From: Jonas Jelonek <jelonek.jonas@gmail.com>
To: shao.mingyin@zte.com.cn, linusw@kernel.org, brgl@kernel.org,
linux-gpio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] gpio: line-mux: fix unsigned truncation of property count error
Date: Tue, 10 Nov 2026 17:07:04 +0100 [thread overview]
Message-ID: <8f5f5582-523f-4632-be69-b176f7ac52db@gmail.com> (raw)
In-Reply-To: <20261110225742308FW7iPw8mc9gwd2DU0W-_w@zte.com.cn>
Hi Shao,
On 10.11.26 15:57, shao.mingyin@zte.com.cn wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
>
> device_property_count_u32() returns an int and reports errors with a
> negative errno (e.g. -EINVAL when the "gpio-line-mux-states" property is
> missing). Storing that into an unsigned int turns -EINVAL into a huge
> value, so the "if (!ngpio)" guard never triggers and struct_size() then
> computes a huge size. The allocation fails with -ENOMEM, hiding the
> real error; struct_size() saturates on overflow, so this is not an
> undersized allocation on 32-bit builds either.
>
> Use a signed int for the count, propagate the property-array error, and
> reject a zero count.
>
> Fixes: 2b03d9a40cd1 ("gpio: add gpio-line-mux driver")
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
> Reviewed-by: Jonas Jelonek <jelonek.jonas@gmail.com>
> ---
> This patch supersedes 5/5 of the v1 series; 1/5 has been withdrawn and
> 2/5-4/5 are unchanged.
>
> v2:
> - keep the declarations in reverse christmas tree order; merge
> "int ngpio, ret" (Jonas Jelonek)
> - propagate the property-array errno when ngpio < 0, and map only a
> zero count to -EINVAL (Jonas Jelonek)
> v1: https://lore.kernel.org/all/20261107161258203oCy-Pa4_0rNe65TqrzFWD@zte.com.cn/
>
> drivers/gpio/gpio-line-mux.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpio-line-mux.c b/drivers/gpio/gpio-line-mux.c
> index b4452d956bf0271d25598de2117c0db73805aba6..00b69632c4401300d11bbc296306df114d18c08f 100644
> --- a/drivers/gpio/gpio-line-mux.c
> +++ b/drivers/gpio/gpio-line-mux.c
> @@ -48,11 +48,12 @@ static int gpio_lmux_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> struct gpio_lmux *glm;
> - unsigned int ngpio;
> size_t size;
> - int ret;
> + int ngpio, ret;
>
I think you still need to move it up where 'unsigned int ngpio' was before
for RCT.
> ngpio = device_property_count_u32(dev, "gpio-line-mux-states");
> + if (ngpio < 0)
> + return ngpio;
> if (!ngpio)
> return -EINVAL;
>
Best,
Jonas
prev parent reply other threads:[~2026-11-10 16:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 14:57 shao.mingyin
2026-11-10 15:17 ` Bartosz Golaszewski
2026-11-10 15:28 ` shao.mingyin
2026-11-10 16:07 ` Jonas Jelonek [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=8f5f5582-523f-4632-be69-b176f7ac52db@gmail.com \
--to=jelonek.jonas@gmail.com \
--cc=brgl@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shao.mingyin@zte.com.cn \
/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
all inboxes | Powered by JetHome®