]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
fs: exfat: Perform NULL check before dereference
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Tue, 8 Jul 2025 11:16:41 +0000 (12:16 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 15 Jul 2025 15:55:48 +0000 (09:55 -0600)
In the functions exfat_pread and exfat_pwrite there is a NULL check for
ctxt.cur_dev 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/exfat/io.c

index 77cd2dfb6dc945cad72f61a2011cb0cee97c9ae3..d80eece685073340c2d41c64da2a27eebacc6082 100644 (file)
@@ -442,12 +442,15 @@ off_t exfat_get_size(const struct exfat_dev* dev)
 ssize_t exfat_pread(struct exfat_dev* dev, void* buffer, size_t size,
                off_t offset)
 {
-       lbaint_t sect = offset >> ctxt.cur_dev->log2blksz;
-       int off = offset & (ctxt.cur_dev->blksz - 1);
+       lbaint_t sect;
+       int off;
 
        if (!ctxt.cur_dev)
                return -EIO;
 
+       sect = offset >> ctxt.cur_dev->log2blksz;
+       off = offset & (ctxt.cur_dev->blksz - 1);
+
        if (fs_devread(ctxt.cur_dev, &ctxt.cur_part_info, sect,
                       off, size, buffer))
                return 0;
@@ -457,12 +460,15 @@ ssize_t exfat_pread(struct exfat_dev* dev, void* buffer, size_t size,
 ssize_t exfat_pwrite(struct exfat_dev* dev, const void* buffer, size_t size,
                off_t offset)
 {
-       lbaint_t sect = offset >> ctxt.cur_dev->log2blksz;
-       int off = offset & (ctxt.cur_dev->blksz - 1);
+       lbaint_t sect;
+       int off;
 
        if (!ctxt.cur_dev)
                return -EIO;
 
+       sect = offset >> ctxt.cur_dev->log2blksz;
+       off = offset & (ctxt.cur_dev->blksz - 1);
+
        if (fs_devwrite(ctxt.cur_dev, &ctxt.cur_part_info, sect,
                       off, size, buffer))
                return 0;