]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
fastboot: Fix has-slot command always returning yes for fb_nand
authorChance Yang <chance.yang@kneron.us>
Tue, 26 Aug 2025 03:36:17 +0000 (11:36 +0800)
committerMattijs Korpershoek <mkorpershoek@kernel.org>
Tue, 30 Sep 2025 09:48:51 +0000 (11:48 +0200)
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.

Signed-off-by: Chance Yang <chance.yang@kneron.us>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
Link: https://lore.kernel.org/r/20250826-master-v2-1-30b787a2f9fd@kneron.us
Signed-off-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
drivers/fastboot/fb_nand.c

index afc64fd5280717ae4041ed70268ccc01cfbb0496..6df3917e129556fef71640ebb1347c5eb86e648a 100644 (file)
@@ -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;
 }
 
 /**