summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-05-24 17:38:22 -0600
committerBin Meng <bmeng.cn@gmail.com>2020-05-27 14:40:09 +0800
commit924e346a66ea57f48d6f8467c30d411442229946 (patch)
treeee443db70ff469b7c94b01e2f8464fe340e99c63 /fs
parent0e7b6312e7c6780381612fe09a73c77f77e63c2d (diff)
cbfs: Change file_cbfs_find_uncached() to return an error
This function currently returns a node pointer so there is no way to know the error code. Also it uses data in BSS which seems unnecessary since the caller might prefer to use a local variable. Update the function and split its body out into a separate function so we can use it later. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/cbfs/cbfs.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c
index 73fe3b3624..ba903d16a0 100644
--- a/fs/cbfs/cbfs.c
+++ b/fs/cbfs/cbfs.c
@@ -371,40 +371,46 @@ const struct cbfs_cachenode *file_cbfs_find(const char *name)
return cbfs_find_file(&cbfs_s, name);
}
-const struct cbfs_cachenode *file_cbfs_find_uncached(ulong end_of_rom,
- const char *name)
+static int find_uncached(struct cbfs_priv *priv, const char *name, void *start,
+ struct cbfs_cachenode *node)
{
- struct cbfs_priv *priv = &cbfs_s;
- void *start;
- u32 size;
- u32 align;
- static struct cbfs_cachenode node;
-
- if (file_cbfs_load_header(priv, end_of_rom))
- return NULL;
-
- start = priv->start;
- size = priv->header.rom_size;
- align = priv->header.align;
+ int size = priv->header.rom_size;
+ int align = priv->header.align;
while (size >= align) {
- int ret;
int used;
+ int ret;
- ret = file_cbfs_next_file(priv, start, size, align, &node,
+ ret = file_cbfs_next_file(priv, start, size, align, node,
&used);
if (ret == -ENOENT)
break;
else if (ret)
- return NULL;
- if (!strcmp(name, node.name))
- return &node;
+ return ret;
+ if (!strcmp(name, node->name))
+ return 0;
size -= used;
start += used;
}
- cbfs_s.result = CBFS_FILE_NOT_FOUND;
- return NULL;
+ priv->result = CBFS_FILE_NOT_FOUND;
+
+ return -ENOENT;
+}
+
+int file_cbfs_find_uncached(ulong end_of_rom, const char *name,
+ struct cbfs_cachenode *node)
+{
+ struct cbfs_priv priv;
+ void *start;
+ int ret;
+
+ ret = file_cbfs_load_header(&priv, end_of_rom);
+ if (ret)
+ return ret;
+ start = priv.start;
+
+ return find_uncached(&priv, name, start, node);
}
const char *file_cbfs_name(const struct cbfs_cachenode *file)