mirror of
https://xff.cz/git/u-boot/
synced 2025-09-01 08:42:12 +02:00
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>
This commit is contained in:
@@ -371,40 +371,46 @@ const struct cbfs_cachenode *file_cbfs_find(const char *name)
|
|||||||
return cbfs_find_file(&cbfs_s, name);
|
return cbfs_find_file(&cbfs_s, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct cbfs_cachenode *file_cbfs_find_uncached(ulong end_of_rom,
|
static int find_uncached(struct cbfs_priv *priv, const char *name, void *start,
|
||||||
const char *name)
|
struct cbfs_cachenode *node)
|
||||||
{
|
{
|
||||||
struct cbfs_priv *priv = &cbfs_s;
|
int size = priv->header.rom_size;
|
||||||
void *start;
|
int align = priv->header.align;
|
||||||
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;
|
|
||||||
|
|
||||||
while (size >= align) {
|
while (size >= align) {
|
||||||
int ret;
|
|
||||||
int used;
|
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);
|
&used);
|
||||||
if (ret == -ENOENT)
|
if (ret == -ENOENT)
|
||||||
break;
|
break;
|
||||||
else if (ret)
|
else if (ret)
|
||||||
return NULL;
|
return ret;
|
||||||
if (!strcmp(name, node.name))
|
if (!strcmp(name, node->name))
|
||||||
return &node;
|
return 0;
|
||||||
|
|
||||||
size -= used;
|
size -= used;
|
||||||
start += used;
|
start += used;
|
||||||
}
|
}
|
||||||
cbfs_s.result = CBFS_FILE_NOT_FOUND;
|
priv->result = CBFS_FILE_NOT_FOUND;
|
||||||
return NULL;
|
|
||||||
|
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)
|
const char *file_cbfs_name(const struct cbfs_cachenode *file)
|
||||||
|
@@ -161,17 +161,18 @@ int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp);
|
|||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* file_cbfs_find_uncached() - Find a file with a particular name in CBFS
|
* file_cbfs_find_uncached() - Find a file in CBFS given the end of the ROM
|
||||||
* without using the heap.
|
|
||||||
*
|
*
|
||||||
* @end_of_rom: Points to the end of the ROM the CBFS should be read
|
* Note that @node should be declared by the caller. This design is to avoid
|
||||||
* from.
|
* the need for allocation here.
|
||||||
* @name: The name to search for.
|
|
||||||
*
|
*
|
||||||
* @return A handle to the file, or NULL on error.
|
* @end_of_rom: Points to the end of the ROM the CBFS should be read from
|
||||||
|
* @name: The name to search for
|
||||||
|
* @node: Returns the contents of the node if found (i.e. copied into *node)
|
||||||
|
* @return 0 on success, -ENOENT if not found, -EFAULT on bad header
|
||||||
*/
|
*/
|
||||||
const struct cbfs_cachenode *file_cbfs_find_uncached(ulong end_of_rom,
|
int file_cbfs_find_uncached(ulong end_of_rom, const char *name,
|
||||||
const char *name);
|
struct cbfs_cachenode *node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* file_cbfs_name() - Get the name of a file in CBFS.
|
* file_cbfs_name() - Get the name of a file in CBFS.
|
||||||
|
Reference in New Issue
Block a user