fastboot: Fix has-slot command always returning yes for fb_nand
PATCH 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 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.
--- drivers/fastboot/fb_nand.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/fastboot/fb_nand.c +6 -1
@@ -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 >0 ) +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]>
Hi Chance,
Thank you for the patch.
Quoted 22 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 (fromfind_dev_and_part)When partition didn't exist,
fb_nand_lookupreturned 1, butfastboot_nand_get_part_infopassed it directly togetvar_get_part_info, which treated 1 >= 0 as success, causing has-slot to always return yes.Fix by converting positive return values to
-ENOENTinfastboot_nand_get_part_infoto match the expected error convention.Signed-off-by Chance Yang <[email protected]>--- drivers/fastboot/fb_nand.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/fastboot/fb_nand.c +0
-0
drivers/fastboot/fb_nand.c int fastboot_nand_get_part_info(const char *part_name, · line 163
Quoted 7 lines
drivers/fastboot/fb_nand.c +4
-0@@ -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 >0 )
ret > 0 does not cover all the failure paths in fb_nand_lookup():
Inspecting fb_nand_loopup(), it can fail in 3 different ways. In case of failure:
1. mtdparts_init(): returns 1
2. find_dev_and_part(): returns 1
3. dev->id->type != MTD_DEV_TYPE_NAND: returns -EINVAL
Right now, we only cover failure path 1. and 2.
Could we change this to:
if (ret)
Thanks,
Mattijs
Quoted 15 lines
drivers/fastboot/fb_nand.c +2
-2+return -ENOENT ; -return fb_nand_lookup (part_name, &mtd, part_info, response); +return ret; }/** --- base-commit:
d1d53c252a4a746db5ebcdf0d6de3aa0feec504e
change-id: 20250708-master-b6a53395df05Best regards,
Signature · 1 line
Chance Yang <[email protected]>