mirror of
https://github.com/smaeul/u-boot.git
synced 2025-10-14 21:06:01 +01:00
fs/squashfs: sqfs_frag_lookup: simplify error handling
For consistency with other functions. Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
This commit is contained in:
parent
555459e793
commit
c9b8e86f8b
@ -106,6 +106,10 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
|
|||||||
int block, offset, ret;
|
int block, offset, ret;
|
||||||
u16 header;
|
u16 header;
|
||||||
|
|
||||||
|
metadata_buffer = NULL;
|
||||||
|
entries = NULL;
|
||||||
|
table = NULL;
|
||||||
|
|
||||||
if (inode_fragment_index >= get_unaligned_le32(&sblk->fragments))
|
if (inode_fragment_index >= get_unaligned_le32(&sblk->fragments))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
@ -117,12 +121,14 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
|
|||||||
|
|
||||||
/* Allocate a proper sized buffer to store the fragment index table */
|
/* Allocate a proper sized buffer to store the fragment index table */
|
||||||
table = malloc_cache_aligned(n_blks * ctxt.cur_dev->blksz);
|
table = malloc_cache_aligned(n_blks * ctxt.cur_dev->blksz);
|
||||||
if (!table)
|
if (!table) {
|
||||||
return -ENOMEM;
|
ret = -ENOMEM;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (sqfs_disk_read(start, n_blks, table) < 0) {
|
if (sqfs_disk_read(start, n_blks, table) < 0) {
|
||||||
free(table);
|
ret = -EINVAL;
|
||||||
return -EINVAL;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
block = SQFS_FRAGMENT_INDEX(inode_fragment_index);
|
block = SQFS_FRAGMENT_INDEX(inode_fragment_index);
|
||||||
@ -142,12 +148,12 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
|
|||||||
metadata_buffer = malloc_cache_aligned(n_blks * ctxt.cur_dev->blksz);
|
metadata_buffer = malloc_cache_aligned(n_blks * ctxt.cur_dev->blksz);
|
||||||
if (!metadata_buffer) {
|
if (!metadata_buffer) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto free_table;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sqfs_disk_read(start, n_blks, metadata_buffer) < 0) {
|
if (sqfs_disk_read(start, n_blks, metadata_buffer) < 0) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto free_buffer;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Every metadata block starts with a 16-bit header */
|
/* Every metadata block starts with a 16-bit header */
|
||||||
@ -156,13 +162,13 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
|
|||||||
|
|
||||||
if (!metadata || !header) {
|
if (!metadata || !header) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto free_buffer;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
entries = malloc(SQFS_METADATA_BLOCK_SIZE);
|
entries = malloc(SQFS_METADATA_BLOCK_SIZE);
|
||||||
if (!entries) {
|
if (!entries) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto free_buffer;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SQFS_COMPRESSED_METADATA(header)) {
|
if (SQFS_COMPRESSED_METADATA(header)) {
|
||||||
@ -172,7 +178,7 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
|
|||||||
src_len);
|
src_len);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto free_entries;
|
goto out;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
memcpy(entries, metadata, SQFS_METADATA_SIZE(header));
|
memcpy(entries, metadata, SQFS_METADATA_SIZE(header));
|
||||||
@ -181,11 +187,9 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
|
|||||||
*e = entries[offset];
|
*e = entries[offset];
|
||||||
ret = SQFS_COMPRESSED_BLOCK(e->size);
|
ret = SQFS_COMPRESSED_BLOCK(e->size);
|
||||||
|
|
||||||
free_entries:
|
out:
|
||||||
free(entries);
|
free(entries);
|
||||||
free_buffer:
|
|
||||||
free(metadata_buffer);
|
free(metadata_buffer);
|
||||||
free_table:
|
|
||||||
free(table);
|
free(table);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user