]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
fs: ext4fs: Perform NULL check before dereference
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Fri, 4 Jul 2025 12:32:44 +0000 (13:32 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 11 Jul 2025 16:44:29 +0000 (10:44 -0600)
In the function put_ext4 there is a NULL check for fs->dev_desc but this
has already been derefenced twice before this happens. Refactor the code
a bit to put the NULL check first.

This issue found by Smatch.

Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
fs/ext4/ext4_common.c

index cc150cf824f9fc1f54d9406c88dc1b3df55fa5e2..8e6531fa3f0c3755bc7535c12fbb3aa40835a86b 100644 (file)
@@ -198,16 +198,18 @@ void put_ext4(uint64_t off, const void *buf, uint32_t size)
        uint64_t remainder;
        unsigned char *temp_ptr = NULL;
        struct ext_filesystem *fs = get_fs();
-       int log2blksz = fs->dev_desc->log2blksz;
+       int log2blksz;
+
+       if (!fs->dev_desc)
+               return;
+
        ALLOC_CACHE_ALIGN_BUFFER(unsigned char, sec_buf, fs->dev_desc->blksz);
 
+       log2blksz = fs->dev_desc->log2blksz;
        startblock = off >> log2blksz;
        startblock += part_offset;
        remainder = off & (uint64_t)(fs->dev_desc->blksz - 1);
 
-       if (fs->dev_desc == NULL)
-               return;
-
        if ((startblock + (size >> log2blksz)) >
            (part_offset + fs->total_sect)) {
                printf("part_offset is " LBAFU "\n", part_offset);