All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs: erofs: Do NULL check before dereferencing pointer
@ 2025-07-04 10:53 Andrew Goodbody
  2025-07-04 11:25 ` Gao Xiang
  2025-07-11 20:00 ` Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Goodbody @ 2025-07-04 10:53 UTC (permalink / raw)
  To: Huang Jianan, Tom Rini; +Cc: linux-erofs, u-boot, Andrew Goodbody

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>
---
 fs/erofs/fs.c | 7 +++++--
 1 file 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;

---
base-commit: 7027b445cc0bfb86204ecb1f1fe596f5895048d9
change-id: 20250704-erofs_fix-77cd80979cf6

Best regards,
-- 
Andrew Goodbody <andrew.goodbody@linaro.org>



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs: erofs: Do NULL check before dereferencing pointer
  2025-07-04 10:53 [PATCH] fs: erofs: Do NULL check before dereferencing pointer Andrew Goodbody
@ 2025-07-04 11:25 ` Gao Xiang
  2025-07-11 20:00 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Gao Xiang @ 2025-07-04 11:25 UTC (permalink / raw)
  To: Andrew Goodbody; +Cc: Huang Jianan, Tom Rini, linux-erofs, u-boot

On Fri, Jul 04, 2025 at 11:53:18AM +0100, Andrew Goodbody wrote:
> 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>

Thanks!
Gao Xiang


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs: erofs: Do NULL check before dereferencing pointer
  2025-07-04 10:53 [PATCH] fs: erofs: Do NULL check before dereferencing pointer Andrew Goodbody
  2025-07-04 11:25 ` Gao Xiang
@ 2025-07-11 20:00 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2025-07-11 20:00 UTC (permalink / raw)
  To: Huang Jianan, Andrew Goodbody; +Cc: linux-erofs, u-boot

On Fri, 04 Jul 2025 11:53:18 +0100, Andrew Goodbody wrote:

> 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
> 
> 
> [...]

Applied to u-boot/master, thanks!

[1/1] fs: erofs: Do NULL check before dereferencing pointer
      commit: ff8a41ce4947c6d7f1826990d5d7b96d30928e3f
-- 
Tom




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-07-11 20:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-04 10:53 [PATCH] fs: erofs: Do NULL check before dereferencing pointer Andrew Goodbody
2025-07-04 11:25 ` Gao Xiang
2025-07-11 20:00 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.