Skip to contentSkip to conversation

fastboot: Fix has-slot command always returning yes for fb_nand

PATCH In review Chance Yang 2 participants 3 messages Aug 26, 2025 – Sep 30, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fastboot: Fix has-slot command always returning yes for fb_nand

The issue was a mismatch in return value conventions between functions:
- getvar_get_part_info() expects >= 0 for success
- fb_nand_lookup() returns 0 on success, 1 on failure (from mtdparts_init and find_dev_and_part)

When partition didn't exist, fb_nand_lookup returned 1, but fastboot_nand_get_part_info passed it directly to getvar_get_part_info, which treated 1 >= 0 as success, causing has-slot to always return yes.

Fix by converting positive return values to -ENOENT in fastboot_nand_get_part_info to match the expected error convention.

---
Changes in v2:
- cover all the failure paths in fb_nand_lookup()
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/fastboot/fb_nand.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/fastboot/fb_nand.c +6 -1
index afc64fd5280717ae4041ed70268ccc01cfbb0496..6df3917e129556fef71640ebb1347c5eb86e648a 100644
@@ -157,8 +157,13 @@ int fastboot_nand_get_part_info(const char *part_name,
 				struct part_info **part_info, char *response)
 {
 	struct mtd_info *mtd = NULL;
+	int ret;
+
+	ret = fb_nand_lookup(part_name, &mtd, part_info, response);
+	if (ret)
+		return -ENOENT;
 
-	return fb_nand_lookup(part_name, &mtd, part_info, response);
+	return ret;
 }
 
 /**

---
base-commit: d1d53c252a4a746db5ebcdf0d6de3aa0feec504e
change-id: 20250708-master-b6a53395df05

Best regards,

Signature · 1 line
Chance Yang <[email protected]>
Reviewed-by on v2 1/1
#1 lore raw

Hi Chance,

Thank you for the patch.

Quoted 5 lines · Chance Yang

The issue was a mismatch in return value conventions between functions:
- getvar_get_part_info() expects >= 0 for success
- fb_nand_lookup() returns 0 on success, 1 on failure (from mtdparts_init and find_dev_and_part)

Quoted 8 lines

When partition didn't exist, fb_nand_lookup returned 1, but fastboot_nand_get_part_info passed it directly to getvar_get_part_info, which treated 1 >= 0 as success, causing has-slot to always return yes.

Fix by converting positive return values to -ENOENT in fastboot_nand_get_part_info to match the expected error convention.

Quoted 35 lines

---
Changes in v2:
- cover all the failure paths in fb_nand_lookup()
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/fastboot/fb_nand.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/fastboot/fb_nand.c +6 -2
index afc64fd5280717ae4041ed70268ccc01cfbb0496..6df3917e129556fef71640ebb1347c5eb86e648a 100644
@@ -157,8 +157,13 @@ int fastboot_nand_get_part_info(const char *part_name,
 				struct part_info **part_info, char *response)
 {
 	struct mtd_info *mtd = NULL;
+	int ret;
+
+	ret = fb_nand_lookup(part_name, &mtd, part_info, response);
+	if (ret)
+		return -ENOENT;
 
-	return fb_nand_lookup(part_name, &mtd, part_info, response);
+	return ret;
 }
 
 /**
 
---

base-commit: d1d53c252a4a746db5ebcdf0d6de3aa0feec504e
change-id: 20250708-master-b6a53395df05

Best regards,

Signature · 1 line
Chance Yang <[email protected]>
#2 lore raw
In reply to Chance Yang

Hi,

Quoted 10 lines · Chance Yang

The issue was a mismatch in return value conventions between functions:
- getvar_get_part_info() expects >= 0 for success
- fb_nand_lookup() returns 0 on success, 1 on failure (from mtdparts_init and find_dev_and_part)

When partition didn't exist, fb_nand_lookup returned 1, but fastboot_nand_get_part_info passed it directly to getvar_get_part_info, which treated 1 >= 0 as success, causing has-slot to always return yes.

[...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu-next)

[1/1] fastboot: Fix has-slot command always returning yes for fb_nand

      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/3ce8a0e9115eaa0cdfc142459814b2283cf01785

--
Mattijs