From: sashiko-bot@kernel.org
To: "A. Sverdlin" <alexander.sverdlin@siemens.com>,
linux-gpio@vger.kernel.org
Subject: Re: [PATCH 3/3] pinctrl: single: Reject bit-per-mux without a usable function mask
Date: Thu, 19 Nov 2026 23:42:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-224208@kernel.org> (raw)
In-Reply-To: <20261119232806.4093754-4-alexander.sverdlin@siemens.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] pinctrl: single: __ffs(0) undefined behavior in pcs_probe()
on zero fmask
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] pinctrl: single: division by zero in pcs_allocate_pin_table()
[1]
--
commit cc08958bb33456e53a3135b8e53047a689914a44
Author: Alexander Sverdlin <alexander.sverdlin@siemens.com>
pinctrl: single: Reject bit-per-mux without a usable function mask
This commit rejects pinctrl-single,bit-per-mux configurations in
pcs_probe() when pinctrl-single,function-mask is missing, zero, or wider
than the register width.
Link: https://lore.kernel.org/all/20261119205013.2563811-10-lee@kernel.org/
> diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
> index bc6a3a4999156..73425f6c97284 100644
> --- a/drivers/pinctrl/pinctrl-single.c
> +++ b/drivers/pinctrl/pinctrl-single.c
> @@ -1855,6 +1855,14 @@ static int pcs_probe(struct platform_device *pdev)
>
> pcs->bits_per_mux = of_property_read_bool(np,
> "pinctrl-single,bit-per-mux");
> + if (pcs->bits_per_mux &&
> + (!pcs->fmask || fls(pcs->fmask) > pcs->width)) {
> + dev_err(pcs->dev, "invalid function mask 0x%x for bit-per-mux\n",
> + pcs->fmask);
> +
> + return -EINVAL;
> + }
[Severity: Medium]
Can pcs_probe() invoke __ffs(0) before reaching this !pcs->fmask check?
When pinctrl-single,function-mask is present in the Device Tree with a
value of 0, of_property_read_u32() succeeds earlier in pcs_probe() and
runs:
drivers/pinctrl/pinctrl-single.c:pcs_probe() {
...
ret = of_property_read_u32(np, "pinctrl-single,function-mask",
&pcs->fmask);
if (!ret) {
pcs->fshift = __ffs(pcs->fmask);
pcs->fmax = pcs->fmask >> pcs->fshift;
} else {
...
}
__ffs(0) is undefined (__builtin_ctzl(0)), and shifting the 32-bit
pcs->fmask by pcs->fshift can also trigger an out-of-bounds shift before
reaching the new check. Checking if (!ret && pcs->fmask) above would
avoid both.
[Severity: High]
This problem wasn't introduced by this patch, but does pcs_probe() also
fail to reject an invalid pcs->width [1]?
Later in pcs_probe(), the switch on pcs->width ignores anything other
than 8, 16, or 32 in its default case:
drivers/pinctrl/pinctrl-single.c:pcs_probe() {
...
switch (pcs->width) {
case 8:
pcs->read = pcs_readb;
pcs->write = pcs_writeb;
break;
case 16:
pcs->read = pcs_readw;
pcs->write = pcs_writew;
break;
case 32:
pcs->read = pcs_readl;
pcs->write = pcs_writel;
break;
default:
break;
}
...
ret = pcs_allocate_pin_table(pcs);
...
}
When pcs->width is less than 8 and bit-per-mux is not set,
pcs_allocate_pin_table() computes mux_bytes = pcs->width / BITS_PER_BYTE
as 0 and divides by zero in pcs->size / mux_bytes. If pcs->width is
greater than 8 but not 8, 16, or 32, pcs->read and pcs->write remain NULL
and pcs_add_pin() dereferences pcs->read when irq_enable_mask is set.
[1] https://sashiko.dev/#/bug/linux-a0303b6e-d0c6-4292-aeeb-fa8a21861827
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119232806.4093754-1-alexander.sverdlin@siemens.com?part=3
next prev parent reply other threads:[~2026-11-19 23:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 23:28 [PATCH 0/3] pinctrl: single: follow-up fixes from review A. Sverdlin
2026-11-19 23:28 ` [PATCH 1/3] pinctrl: single: Also free the pinconf table of a duplicate function A. Sverdlin
2026-11-19 23:43 ` sashiko-bot
2026-11-20 9:06 ` Sverdlin, Alexander
2026-11-19 23:28 ` [PATCH 2/3] pinctrl: single: Don't remove deduplicated groups and functions on error A. Sverdlin
2026-11-19 23:28 ` [PATCH 3/3] pinctrl: single: Reject bit-per-mux without a usable function mask A. Sverdlin
2026-11-19 23:42 ` sashiko-bot [this message]
2026-11-20 9:48 ` Sverdlin, Alexander
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=sashiko-outbox-224208@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexander.sverdlin@siemens.com \
--cc=linux-gpio@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 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.