Commit 24f48416dfe1d827dcf759d6cd0e7a8e5c67e321

Authored by Heinrich Schuchardt
Committed by Tom Rini
1 parent 254eedee7f

fs: avoid possible NULL dereference in fs_devread

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>

Showing 1 changed file with 2 additions and 1 deletions Side-by-side Diff

... ... @@ -15,12 +15,13 @@
15 15 lbaint_t sector, int byte_offset, int byte_len, char *buf)
16 16 {
17 17 unsigned block_len;
18   - int log2blksz = blk->log2blksz;
  18 + int log2blksz;
19 19 ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf, (blk ? blk->blksz : 0));
20 20 if (blk == NULL) {
21 21 printf("** Invalid Block Device Descriptor (NULL)\n");
22 22 return 0;
23 23 }
  24 + log2blksz = blk->log2blksz;
24 25  
25 26 /* Check partition boundaries */
26 27 if ((sector + ((byte_offset + byte_len - 1) >> log2blksz))