All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] fastboot: Fix has-slot command always returning yes for fb_nand
@ 2025-08-26  3:36 Chance Yang
  2025-09-29  7:33 ` Mattijs Korpershoek
  2025-09-30  9:49 ` Mattijs Korpershoek
  0 siblings, 2 replies; 3+ messages in thread
From: Chance Yang @ 2025-08-26  3:36 UTC (permalink / raw)
  To: Mattijs Korpershoek, Tom Rini; +Cc: u-boot, morgan.chang, 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.

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>
---
Changes in v2:
- cover all the failure paths in fb_nand_lookup()
- Link to v1: https://lore.kernel.org/r/20250708-master-v1-1-574f8bec645d@kneron.us
---
 drivers/fastboot/fb_nand.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/fastboot/fb_nand.c b/drivers/fastboot/fb_nand.c
index afc64fd5280717ae4041ed70268ccc01cfbb0496..6df3917e129556fef71640ebb1347c5eb86e648a 100644
--- a/drivers/fastboot/fb_nand.c
+++ b/drivers/fastboot/fb_nand.c
@@ -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,
-- 
Chance Yang <chance.yang@kneron.us>


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

* Re: [PATCH v2] fastboot: Fix has-slot command always returning yes for fb_nand
  2025-08-26  3:36 [PATCH v2] fastboot: Fix has-slot command always returning yes for fb_nand Chance Yang
@ 2025-09-29  7:33 ` Mattijs Korpershoek
  2025-09-30  9:49 ` Mattijs Korpershoek
  1 sibling, 0 replies; 3+ messages in thread
From: Mattijs Korpershoek @ 2025-09-29  7:33 UTC (permalink / raw)
  To: Chance Yang, Mattijs Korpershoek, Tom Rini
  Cc: u-boot, morgan.chang, Chance Yang

Hi Chance,

Thank you for the patch.

On Tue, Aug 26, 2025 at 11:36, Chance Yang <chance.yang@kneron.us> wrote:

> 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>

> ---
> Changes in v2:
> - cover all the failure paths in fb_nand_lookup()
> - Link to v1: https://lore.kernel.org/r/20250708-master-v1-1-574f8bec645d@kneron.us
> ---
>  drivers/fastboot/fb_nand.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/fastboot/fb_nand.c b/drivers/fastboot/fb_nand.c
> index afc64fd5280717ae4041ed70268ccc01cfbb0496..6df3917e129556fef71640ebb1347c5eb86e648a 100644
> --- a/drivers/fastboot/fb_nand.c
> +++ b/drivers/fastboot/fb_nand.c
> @@ -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,
> -- 
> Chance Yang <chance.yang@kneron.us>

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

* Re: [PATCH v2] fastboot: Fix has-slot command always returning yes for fb_nand
  2025-08-26  3:36 [PATCH v2] fastboot: Fix has-slot command always returning yes for fb_nand Chance Yang
  2025-09-29  7:33 ` Mattijs Korpershoek
@ 2025-09-30  9:49 ` Mattijs Korpershoek
  1 sibling, 0 replies; 3+ messages in thread
From: Mattijs Korpershoek @ 2025-09-30  9:49 UTC (permalink / raw)
  To: Tom Rini, Chance Yang; +Cc: u-boot, morgan.chang

Hi,

On Tue, 26 Aug 2025 11:36:17 +0800, Chance Yang wrote:
> 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

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

end of thread, other threads:[~2025-09-30  9:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-26  3:36 [PATCH v2] fastboot: Fix has-slot command always returning yes for fb_nand Chance Yang
2025-09-29  7:33 ` Mattijs Korpershoek
2025-09-30  9:49 ` Mattijs Korpershoek

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.