summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Goodbody <andrew.goodbody@linaro.org>2025-07-04 11:53:18 +0100
committerTom Rini <trini@konsulko.com>2025-07-11 11:33:25 -0600
commitff8a41ce4947c6d7f1826990d5d7b96d30928e3f (patch)
tree5d232785f9e9c91752a45d94bfddf94e4a00ae0b
parenta21ec39944f93fb5bd3dd5de525e78cac988fdb6 (diff)
fs: erofs: Do NULL check before dereferencing pointer
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>
-rw-r--r--fs/erofs/fs.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/fs/erofs/fs.c b/fs/erofs/fs.c
index dcdc883e34c..db86928511e 100644
--- a/fs/erofs/fs.c
+++ b/fs/erofs/fs.c
@@ -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;