]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
fs: erofs: Do NULL check before dereferencing pointer
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Fri, 4 Jul 2025 10:53:18 +0000 (11:53 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 11 Jul 2025 17:33:25 +0000 (11:33 -0600)
The assignments to sect and off use the pointer from ctxt.cur_dev but
that has not been NULL checked before this is done. So instead move the
assignments after the NULL check.

This issue found by Smatch

Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
Reviewed-by: Gao Xiang <xiang@kernel.org>
fs/erofs/fs.c

index dcdc883e34c43f6178c46be49b70f9218b34f151..db86928511e82f83d288f3820c57c30b336d897d 100644 (file)
@@ -11,12 +11,15 @@ static struct erofs_ctxt {
 
 int erofs_dev_read(int device_id, void *buf, u64 offset, size_t len)
 {
-       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, len, buf))
                return 0;