Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tapio Reijonen" <tapio.reijonen@vaisala.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 2/2] mux: gpio: Add optional enable gpio
Date: Fri, 04 Sep 2026 06:28:27 +0000	[thread overview]
Message-ID: <20260904062828.4B9CF1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260904-add-external-mux-enable-gpio-v3-2-1b868e669e43@vaisala.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Out-of-bounds stack read in `mux_gpio_set` when the number of GPIOs specified in the device tree exceeds the bit width of `unsigned long`.
--

commit e5d22f785ccbb077940b83f814cc7d4237449e05
Author: Tapio Reijonen <tapio.reijonen@vaisala.com>

mux: gpio: Add optional enable gpio

Some analog multiplexers have an enable input that disconnects all
channels when deasserted, independent of the address inputs. This patch
adds support for an optional enable gpio to handle this. It also updates
the mux idle state logic to require this enable gpio when disconnecting.

> diff --git a/drivers/mux/gpio.c b/drivers/mux/gpio.c
> index f9c7863e51b82..2fd8c83dc22e1 100644
> --- a/drivers/mux/gpio.c
> +++ b/drivers/mux/gpio.c

[ ... ]

> @@ -25,12 +26,26 @@ static int mux_gpio_set(struct mux_control *mux, int state)
>  	struct mux_gpio *mux_gpio = mux_chip_priv(mux->chip);
>  	DECLARE_BITMAP(values, BITS_PER_TYPE(state));
>  	u32 value = state;
> +	int ret;
> +
> +	/*
> +	 * The gpios might not be updated atomically, disable the mux
> +	 * meanwhile.
> +	 */
> +	ret = gpiod_set_value_cansleep(mux_gpio->enable, 0);
> +	if (ret)
> +		return ret;
> +
> +	if (state == MUX_IDLE_DISCONNECT)
> +		return 0;
>  
>  	bitmap_from_arr32(values, &value, BITS_PER_TYPE(value));
>  
> -	gpiod_multi_set_value_cansleep(mux_gpio->gpios, values);
> +	ret = gpiod_multi_set_value_cansleep(mux_gpio->gpios, values);

[Severity: High]
This is a pre-existing issue, but is it possible for an out-of-bounds stack
read to occur here?

In mux_gpio_probe(), the number of pins is parsed from the device tree
using gpiod_count() which sets ndescs. There doesn't appear to be an upper
limit check on this value.

The values bitmap allocated earlier in mux_gpio_set():

    DECLARE_BITMAP(values, BITS_PER_TYPE(state));

limits the capacity to a single unsigned long. If the number of GPIOs
specified in the device tree exceeds the bit width of state, it looks like
gpiod_multi_set_value_cansleep() will iterate past the bounds of the
allocated stack array when reading from values.

Could this lead to leaking adjacent kernel stack memory or triggering a
KASAN panic if an oversized number of pins is provided?

> +	if (ret)
> +		return ret;
>  
> -	return 0;
> +	return gpiod_set_value_cansleep(mux_gpio->enable, 1);
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260904-add-external-mux-enable-gpio-v3-0-1b868e669e43@vaisala.com?part=2

      reply	other threads:[~2026-09-04  6:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04  6:17 [PATCH v3 0/2] mux: gpio: Add optional enable gpio Tapio Reijonen
2026-09-04  6:17 ` [PATCH v3 1/2] dt-bindings: mux: gpio-mux: Add enable-gpios Tapio Reijonen
2026-09-04  6:17 ` [PATCH v3 2/2] mux: gpio: Add optional enable gpio Tapio Reijonen
2026-09-04  6:28   ` sashiko-bot [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=20260904062828.4B9CF1F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tapio.reijonen@vaisala.com \
    /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