From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Tony Lindgren <tony@atomide.com>,
Haojian Zhuang <haojian.zhuang@linaro.org>,
Linus Walleij <linusw@kernel.org>,
linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org,
Alexander Sverdlin <alexander.sverdlin@siemens.com>
Subject: [PATCH v3 09/12] pinctrl: single: Reject invalid register width in pcs_probe()
Date: Fri, 27 Nov 2026 14:04:57 +0000 [thread overview]
Message-ID: <20261127140602.2790001-10-lee@kernel.org> (raw)
In-Reply-To: <20261127140602.2790001-1-lee@kernel.org>
If the "pinctrl-single,register-width" property specifies an unsupported
width (anything other than 8, 16, or 32), pcs_probe() hits the default
branch in the switch statement and continues without initialising
pcs->read or pcs->write, leading to a divide-by-zero in
pcs_allocate_pin_table() or a NULL function pointer dereference when
accessing registers.
Validate pcs->width immediately after reading the property and return
-EINVAL from the default branch in pcs_probe().
Fixes: 8b8b091bf07f ("pinctrl: Add one-register-per-pin type device tree based pinctrl driver")
Closes: https://sashiko.dev/#/bug/linux-a0303b6e-d0c6-4292-aeeb-fa8a21861827
Cc: stable@vger.kernel.org
Reviewed-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Signed-off-by: Lee Jones <lee@kernel.org>
---
v2 => v3:
- Add Reviewed-by tag from Alexander Sverdlin.
- Rebase onto pinctrl/for-next.
drivers/pinctrl/pinctrl-single.c | 34 ++++++++++++++++----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 52734bd7b7f0..6f5113dcdb4b 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -1827,6 +1827,23 @@ static int pcs_probe(struct platform_device *pdev)
return ret;
}
+ 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:
+ return -EINVAL;
+ }
+
ret = of_property_read_u32(np, "pinctrl-single,function-mask",
&pcs->fmask);
if (!ret) {
@@ -1876,23 +1893,6 @@ static int pcs_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, pcs);
- 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;
- }
-
pcs->desc.name = DRIVER_NAME;
pcs->desc.pctlops = &pcs_pinctrl_ops;
pcs->desc.pmxops = &pcs_pinmux_ops;
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-11-27 14:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 14:04 [PATCH v3 00/12] pinctrl: Fix memory leaks, OOB writes, and resource handling bugs Lee Jones
2026-11-27 14:04 ` [PATCH v3 01/12] pinctrl: nuvoton: ma35: Unmap reg_base and release clock on probe error Lee Jones
2026-11-27 14:04 ` [PATCH v3 02/12] pinctrl: nuvoton: ma35: Prevent out-of-bounds write in ma35_pinctrl_get_soc_data() Lee Jones
2026-11-27 14:04 ` [PATCH v3 03/12] pinctrl: nuvoton: ma35: Retain child firmware node reference " Lee Jones
2026-11-27 14:04 ` [PATCH v3 04/12] pinctrl: nuvoton: ma35: Assign fwnode to gpio_chip in ma35_gpiolib_register() Lee Jones
2026-11-27 14:04 ` [PATCH v3 05/12] pinctrl: nuvoton: ma35: Avoid leaking map when parent node is missing Lee Jones
2026-11-27 14:04 ` [PATCH v3 06/12] pinctrl: nuvoton: Unmap GPIO bank registers on error in NPCM7xx and NPCM8xx Lee Jones
2026-11-27 14:04 ` [PATCH v3 07/12] pinctrl: nuvoton: npcm8xx: Propagate npcm8xx_gpio_register() error in probe Lee Jones
2026-11-27 14:04 ` [PATCH v3 08/12] pinctrl: nuvoton: npcm7xx: Fix fwnode_irq_get() error check in npcm7xx_gpio_of() Lee Jones
2026-11-27 14:04 ` Lee Jones [this message]
2026-11-27 14:04 ` [PATCH v3 10/12] pinctrl: single: Free pinconf settings array with pinctrl_utils_free_map() Lee Jones
2026-11-27 14:04 ` [PATCH v3 11/12] pinctrl: sunplus: Validate pin_func index in sppctl_dt_node_to_map() Lee Jones
2026-11-27 14:05 ` [PATCH v3 12/12] pinctrl: realtek: rtd1625: Set dcycle_offset to NA for pins without duty-cycle support Lee Jones
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=20261127140602.2790001-10-lee@kernel.org \
--to=lee@kernel.org \
--cc=alexander.sverdlin@siemens.com \
--cc=haojian.zhuang@linaro.org \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tony@atomide.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
all inboxes | Powered by JetHome®