Skip to contentSkip to conversation

cmd: mtd: Prevent use of uninitialised variable

PATCH In review Andrew Goodbody 3 participants 7 messages Jun 26, 2025 – Oct 28, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd: mtd: Prevent use of uninitialised variable

ret maybe used uninitialised in some cases so instead initialise it first to prevent this.

This issue was found by Smatch.

Fixes 9671243e8d10 (cmd: mtd: Use the subcmd infrastructure to declare mtd sub-commands)
---
 cmd/mtd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/mtd.c +1 -1
index c25997cfb24..1651a4a6b3e 100644
@@ -474,7 +474,7 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
 	struct mtd_info *mtd;
 	u32 oob_len;
 	u8 *buf;
-	int ret;
+	int ret = CMD_RET_SUCCESS;
 
 	if (argc < 2)
 		return CMD_RET_USAGE;

---
base-commit: 903eb123236ccbd8ef05d43507a2a910b785bd56
change-id: 20250626-mtd_fix-bb1ae86f33aa

Best regards,

Signature · 1 line
Andrew Goodbody <[email protected]>
#1 lore raw

Hi Andrew,

Quoted 3 lines · Andrew Goodbody

ret maybe used uninitialised in some cases so instead initialise it first to prevent this.

I don't believe that's true, can you tell us which code path(s) could trigger this because I didn't find one the 2min I spent reading the code.

Quoted 2 lines

This issue was found by Smatch.

Seems like a false positive to me?

Cheers,
Quentin

#2 lore raw
Quoted 8 lines · Quentin Schulz

Hi Andrew,

Quoted 3 lines · Andrew Goodbody

ret maybe used uninitialised in some cases so instead initialise it first to prevent this.

I don't believe that's true, can you tell us which code path(s) could trigger this because I didn't find one the 2min I spent reading the code.

No error path taken before line 563, ret is still not assigned to.
remaining == 0 which could come from being passed 0 on the command line, line 518, unless there is a check for that that I missed? Code reaches line 591 without assigning to ret.

Andrew

Quoted 7 lines
Quoted 2 lines

This issue was found by Smatch.

Seems like a false positive to me?

Cheers,
Quentin

Reviewed-by
#3 lore raw

Hi Andrew,

Quoted 8 lines · Andrew Goodbody
Quoted 7 lines · Quentin Schulz

Hi Andrew,

Quoted 3 lines · Andrew Goodbody

ret maybe used uninitialised in some cases so instead initialise it first to prevent this.

Quoted 6 lines
Quoted 1 line

I don't believe that's true, can you tell us which code path(s) could trigger this because I didn't find one the 2min I spent reading the code.

No error path taken before line 563, ret is still not assigned to.
remaining == 0 which could come from being passed 0 on the command line, line 518, unless there is a check for that that I missed? Code reaches line 591 without assigning to ret.

Indeed, clearly missed that!

Thanks!
Quentin

#4 lore raw
Quoted 18 lines · Quentin Schulz

Hi Andrew,

Quoted 8 lines · Andrew Goodbody
Quoted 7 lines · Quentin Schulz

Hi Andrew,

Quoted 3 lines · Andrew Goodbody

ret maybe used uninitialised in some cases so instead initialise it first to prevent this.

Quoted 6 lines
Quoted 1 line

I don't believe that's true, can you tell us which code path(s) could trigger this because I didn't find one the 2min I spent reading the code.

No error path taken before line 563, ret is still not assigned to.
remaining == 0 which could come from being passed 0 on the command line, line 518, unless there is a check for that that I missed? Code reaches line 591 without assigning to ret.

Quoted 6 lines

Indeed, clearly missed that!

Thanks!
Quentin

Is there anything else needed before this can be merged please?

Thanks,
Andrew

#5 lore raw
In reply to Andrew Goodbody

ping?

Quoted 30 lines · Andrew Goodbody

ret maybe used uninitialised in some cases so instead initialise it first to prevent this.

This issue was found by Smatch.

Fixes 9671243e8d10 (cmd: mtd: Use the subcmd infrastructure to declare mtd sub-commands)
---
  cmd/mtd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
cmd/mtd.c +1 -2
index c25997cfb24..1651a4a6b3e 100644
@@ -474,7 +474,7 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
  	struct mtd_info *mtd;
  	u32 oob_len;
  	u8 *buf;
-	int ret;
+	int ret = CMD_RET_SUCCESS;
 
  	if (argc < 2)
  		return CMD_RET_USAGE;
 
---

base-commit: 903eb123236ccbd8ef05d43507a2a910b785bd56
change-id: 20250626-mtd_fix-bb1ae86f33aa

Best regards,

#6 lore raw
In reply to Andrew Goodbody
Quoted 6 lines · Andrew Goodbody

ret maybe used uninitialised in some cases so instead initialise it first to prevent this.

This issue was found by Smatch.

Applied to u-boot/master, thanks!

[1/1] cmd: mtd: Prevent use of uninitialised variable

      commit: ce1bdedd2f4b3c5c8c76fbf2fc1a234fca470573
Signature · 1 line
Tom