diff mbox series

[U-Boot,1/1] fs: avoid possible NULL dereference in fs_devread

Message ID 20171119224921.30613-1-xypron.glpk@gmx.de
State Accepted
Commit 24f48416dfe1d827dcf759d6cd0e7a8e5c67e321
Delegated to: Tom Rini
Headers show
Series [U-Boot,1/1] fs: avoid possible NULL dereference in fs_devread | expand

Commit Message

Heinrich Schuchardt Nov. 19, 2017, 10:49 p.m. UTC
It is unwise to first dereference a variable
and then to check if it was NULL.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 fs/fs_internal.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Marek BehĂșn Nov. 20, 2017, 1:58 a.m. UTC | #1
Reviewed-by: Marek Behun <marek.behun@nic.cz>
Bin Meng Nov. 20, 2017, 9:36 a.m. UTC | #2
On Mon, Nov 20, 2017 at 6:49 AM, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> It is unwise to first dereference a variable
> and then to check if it was NULL.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  fs/fs_internal.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tom Rini Nov. 30, 2017, 3:36 p.m. UTC | #3
On Sun, Nov 19, 2017 at 11:49:21PM +0100, Heinrich Schuchardt wrote:

> It is unwise to first dereference a variable
> and then to check if it was NULL.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Reviewed-by: Marek Behun <marek.behun@nic.cz>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/fs/fs_internal.c b/fs/fs_internal.c
index 58b441030c..5cdd272c9d 100644
--- a/fs/fs_internal.c
+++ b/fs/fs_internal.c
@@ -15,12 +15,13 @@  int fs_devread(struct blk_desc *blk, disk_partition_t *partition,
 	       lbaint_t sector, int byte_offset, int byte_len, char *buf)
 {
 	unsigned block_len;
-	int log2blksz = blk->log2blksz;
+	int log2blksz;
 	ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, (blk ? blk->blksz : 0));
 	if (blk == NULL) {
 		printf("** Invalid Block Device Descriptor (NULL)\n");
 		return 0;
 	}
+	log2blksz = blk->log2blksz;
 
 	/* Check partition boundaries */
 	if ((sector + ((byte_offset + byte_len - 1) >> log2blksz))