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, geert+renesas@glider.be,
andrew@codeconstruct.com.au, wbg@kernel.org, opendmb@gmail.com,
florian.fainelli@broadcom.com,
bcm-kernel-feedback-list@broadcom.com
Subject: Re: [PATCH 5/5] gpio: line-mux: fix unsigned truncation of property count error
Date: Mon, 9 Nov 2026 09:29:15 +0100 [thread overview]
Message-ID: <c9e116f6-ce3c-4cda-83dc-4e96c7d58aa8@gmail.com> (raw)
In-Reply-To: <20261107161258203oCy-Pa4_0rNe65TqrzFWD@zte.com.cn>
Hi Shao,
On 07.11.26 09:12, 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 and reject non-positive values.
>
> Fixes: 2b03d9a40cd1 ("gpio: add gpio-line-mux driver")
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
> ---
> drivers/gpio/gpio-line-mux.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpio-line-mux.c b/drivers/gpio/gpio-line-mux.c
> index b4452d956b..19e4212de2 100644
> --- a/drivers/gpio/gpio-line-mux.c
> +++ b/drivers/gpio/gpio-line-mux.c
> @@ -48,12 +48,12 @@
> {
> struct device *dev = &pdev->dev;
> struct gpio_lmux *glm;
> - unsigned int ngpio;
> + int ngpio;
> size_t size;
> int ret;
>
Nit: Please adjust to keep reverse christmas tree. I think 'int ret' and
'int ngpio' can be merged too.
> ngpio = device_property_count_u32(dev, "gpio-line-mux-states");
> - if (!ngpio)
> + if (ngpio <= 0)
> return -EINVAL;
>
> size = struct_size(glm, gpio_mux_states, ngpio);
Maybe return the error if < 0, instead of -EINVAL for all?
With those addressed, you can add:
Reviewed-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Best,
Jonas
prev parent reply other threads:[~2026-11-09 8:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 8:12 [PATCH 0/5] gpio: fix IRQ handling and probe error paths in five drivers shao.mingyin
2026-11-07 8:12 ` [PATCH 1/5] gpio: rcar: don't clobber INTMSK when disabling a single line shao.mingyin
2026-11-07 8:12 ` [PATCH 2/5] gpio: aspeed-sgpio: propagate IRQ setup error in probe shao.mingyin
2026-11-09 3:55 ` Andrew Jeffery
2026-11-07 8:12 ` [PATCH 3/5] gpio: 104-idi-48: fix max_register blocking the IRQ register shao.mingyin
2026-11-07 20:19 ` William Breathitt Gray
2026-11-07 8:12 ` [PATCH 4/5] gpio: brcmstb: don't turn platform_get_irq errors into -ENOENT shao.mingyin
2026-11-07 8:12 ` [PATCH 5/5] gpio: line-mux: fix unsigned truncation of property count error shao.mingyin
2026-11-09 8:29 ` 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=c9e116f6-ce3c-4cda-83dc-4e96c7d58aa8@gmail.com \
--to=jelonek.jonas@gmail.com \
--cc=andrew@codeconstruct.com.au \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=brgl@kernel.org \
--cc=florian.fainelli@broadcom.com \
--cc=geert+renesas@glider.be \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=opendmb@gmail.com \
--cc=shao.mingyin@zte.com.cn \
--cc=wbg@kernel.org \
/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®