From: Mattijs Korpershoek <mkorpershoek@kernel.org>
To: Chance Yang <chance.yang@kneron.us>,
Mattijs Korpershoek <mkorpershoek@kernel.org>,
Tom Rini <trini@konsulko.com>
Cc: u-boot@lists.denx.de, morgan.chang@kneron.us,
Chance Yang <chance.yang@kneron.us>
Subject: Re: [PATCH] fastboot: Fix has-slot command always returning yes for fb_nand
Date: Fri, 11 Jul 2025 09:23:35 +0200 [thread overview]
Message-ID: <87a55bjimg.fsf@kernel.org> (raw)
In-Reply-To: <20250708-master-v1-1-574f8bec645d@kneron.us>
Hi Chance,
Thank you for the patch.
On Tue, Jul 08, 2025 at 09:16, 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
> 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>
> ---
> 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..b819541eb8fa6f537ca40fb3ea81bc7aab6118bf 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 > 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
> + 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>
prev parent reply other threads:[~2025-07-11 7:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-08 1:16 [PATCH] fastboot: Fix has-slot command always returning yes for fb_nand Chance Yang
2025-07-11 7:23 ` Mattijs Korpershoek [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a55bjimg.fsf@kernel.org \
--to=mkorpershoek@kernel.org \
--cc=chance.yang@kneron.us \
--cc=morgan.chang@kneron.us \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox