diff options
author | Simon Glass <sjg@chromium.org> | 2021-03-15 18:00:14 +1300 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2021-03-27 13:59:37 +1300 |
commit | 70a394a6b6437e18e67edfd7054302b830e1fe6a (patch) | |
tree | 341e1d1ac8ec9a1a37dd09ef1688ec23012db68d /fs | |
parent | c4f5b5dcc31b5aee37dabbadc998fcf695885157 (diff) | |
download | u-boot-70a394a6b6437e18e67edfd7054302b830e1fe6a.tar.gz u-boot-70a394a6b6437e18e67edfd7054302b830e1fe6a.tar.bz2 u-boot-70a394a6b6437e18e67edfd7054302b830e1fe6a.zip |
cbfs: Factor out filling a cache node into a new function
The file_cbfs_next_file() function is already fairly long. Before
expanding it further, move the core part into a separate function.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/cbfs/cbfs.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index aed4026d65..a93dc3d0c1 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -79,6 +79,35 @@ static void swap_file_header(struct cbfs_fileheader *dest, dest->offset = be32_to_cpu(src->offset); } +/** + * fill_node() - Fill a node struct with information from the CBFS + * + * @node: Node to fill + * @start: Pointer to the start of the CBFS file in memory + * @header: Pointer to the header information (in our enddianess) + * @return 0 if OK, -EBADF if the header is too small + */ +static int fill_node(struct cbfs_cachenode *node, void *start, + struct cbfs_fileheader *header) +{ + uint name_len; + + /* Check the header is large enough */ + if (header->offset < sizeof(struct cbfs_fileheader)) + return -EBADF; + + node->next = NULL; + node->type = header->type; + node->data = start + header->offset; + node->data_length = header->len; + name_len = header->offset - sizeof(struct cbfs_fileheader); + node->name = start + sizeof(struct cbfs_fileheader); + node->name_length = name_len; + node->attr_offset = header->attributes_offset; + + return 0; +} + /* * Given a starting position in memory, scan forward, bounded by a size, and * find the next valid CBFS file. No memory is allocated by this function. The @@ -104,8 +133,8 @@ static int file_cbfs_next_file(struct cbfs_priv *priv, void *start, int size, while (size >= align) { const struct cbfs_fileheader *file_header = start; - u32 name_len; u32 step; + int ret; /* Check if there's a file here. */ if (memcmp(good_file_magic, &file_header->magic, @@ -117,19 +146,11 @@ static int file_cbfs_next_file(struct cbfs_priv *priv, void *start, int size, } swap_file_header(&header, file_header); - if (header.offset < sizeof(struct cbfs_fileheader)) { + ret = fill_node(node, start, &header); + if (ret) { priv->result = CBFS_BAD_FILE; - return -EBADF; + return log_msg_ret("fill", ret); } - node->next = NULL; - node->type = header.type; - node->data = start + header.offset; - node->data_length = header.len; - name_len = header.offset - sizeof(struct cbfs_fileheader); - node->name = (char *)file_header + - sizeof(struct cbfs_fileheader); - node->name_length = name_len; - node->attr_offset = header.attributes_offset; step = header.len; if (step % align) |