Linux on ARM based TI OMAP SoCs
 help / color / mirror / Atom feed
* [PATCH v3 00/12] pinctrl: Fix memory leaks, OOB writes, and resource handling bugs
@ 2026-11-27 14:04 Lee Jones
  2026-11-27 14:04 ` [PATCH v3 09/12] pinctrl: single: Reject invalid register width in pcs_probe() Lee Jones
  2026-11-27 14:04 ` [PATCH v3 10/12] pinctrl: single: Free pinconf settings array with pinctrl_utils_free_map() Lee Jones
  0 siblings, 2 replies; 3+ messages in thread
From: Lee Jones @ 2026-11-27 14:04 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, Andreas Färber, Andrew Gaylard, Andrew Jeffery,
	Andy Shevchenko, Avi Fishman, Benjamin Fair, Dan Carpenter,
	Dvorkin Dmitry, Haojian Zhuang, Harshit Mogalapalli, Jacky Huang,
	James Tai, jordan_hargrave, Linus Walleij, linux-arm-kernel,
	linux-gpio, linux-omap, linux-realtek-soc, Maulik Shah,
	Nancy Yuen, openbmc, Patrick Venture, Shan-Chun Hung, Tali Perry,
	Tomer Maimon, tomer.maimon, Tony Lindgren, Tzuyi Chang, Wells Lu,
	Yang Yingliang, Yu-Chun Lin

These issues were reported by Sashiko.

This v3 series addresses Alexander Sverdlin's review feedback on
pinctrl-single and rebases the twelve patches onto pinctrl/for-next.

v2 => v3:
 - Rebase onto pinctrl/for-next.
 - Add Alexander Sverdlin's Reviewed-by tag on patch 09.
 - Update patch 10 (pinctrl: single) to use kzalloc_objs() with pinctrl_utils_free_map() directly and update its Fixes tag, per Alexander Sverdlin's review.

Cc: "Andreas Färber" <afaerber@suse.com>
Cc: Andrew Gaylard <ag@ffroot.co.za>
Cc: Andrew Jeffery <andrew@codeconstruct.com.au>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Avi Fishman <avifishman70@gmail.com>
Cc: Benjamin Fair <benjaminfair@google.com>
Cc: Dan Carpenter <error27@gmail.com>
Cc: Dvorkin Dmitry <dvorkin@tibbo.com>
Cc: Haojian Zhuang <haojian.zhuang@linaro.org>
Cc: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Cc: Jacky Huang <ychuang3@nuvoton.com>
Cc: James Tai <james.tai@realtek.com>
Cc: jordan_hargrave@dell.com
Cc: Linus Walleij <linusw@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-gpio@vger.kernel.org
Cc: linux-omap@vger.kernel.org
Cc: linux-realtek-soc@lists.infradead.org
Cc: Maulik Shah <maulik.shah@oss.qualcomm.com>
Cc: Nancy Yuen <yuenn@google.com>
Cc: openbmc@lists.ozlabs.org
Cc: Patrick Venture <venture@google.com>
Cc: Shan-Chun Hung <schung@nuvoton.com>
Cc: Tali Perry <tali.perry1@gmail.com>
Cc: Tomer Maimon <tmaimon77@gmail.com>
Cc: tomer.maimon@nuvoton.com
Cc: Tony Lindgren <tony@atomide.com>
Cc: Tzuyi Chang <tychang@realtek.com>
Cc: Wells Lu <wellslutw@gmail.com>
Cc: Yang Yingliang <yangyingliang@huawei.com>
Cc: Yu-Chun Lin <eleanor.lin@realtek.com>

Lee Jones (12):
  pinctrl: nuvoton: ma35: Unmap reg_base and release clock on probe
    error
  pinctrl: nuvoton: ma35: Prevent out-of-bounds write in
    ma35_pinctrl_get_soc_data()
  pinctrl: nuvoton: ma35: Retain child firmware node reference in
    ma35_pinctrl_get_soc_data()
  pinctrl: nuvoton: ma35: Assign fwnode to gpio_chip in
    ma35_gpiolib_register()
  pinctrl: nuvoton: ma35: Avoid leaking map when parent node is missing
  pinctrl: nuvoton: Unmap GPIO bank registers on error in NPCM7xx and
    NPCM8xx
  pinctrl: nuvoton: npcm8xx: Propagate npcm8xx_gpio_register() error in
    probe
  pinctrl: nuvoton: npcm7xx: Fix fwnode_irq_get() error check in
    npcm7xx_gpio_of()
  pinctrl: single: Reject invalid register width in pcs_probe()
  pinctrl: single: Free pinconf settings array with
    pinctrl_utils_free_map()
  pinctrl: sunplus: Validate pin_func index in sppctl_dt_node_to_map()
  pinctrl: realtek: rtd1625: Set dcycle_offset to NA for pins without
    duty-cycle support

 drivers/pinctrl/nuvoton/pinctrl-ma35.c    | 70 +++++++++++++++++++----
 drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c | 20 +++++--
 drivers/pinctrl/nuvoton/pinctrl-npcm8xx.c | 15 ++++-
 drivers/pinctrl/pinctrl-single.c          | 52 +++++++----------
 drivers/pinctrl/realtek/pinctrl-rtd1625.c | 12 ++--
 drivers/pinctrl/sunplus/sppctl.c          |  7 ++-
 6 files changed, 123 insertions(+), 53 deletions(-)

-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v3 09/12] pinctrl: single: Reject invalid register width in pcs_probe()
  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 ` Lee Jones
  2026-11-27 14:04 ` [PATCH v3 10/12] pinctrl: single: Free pinconf settings array with pinctrl_utils_free_map() Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2026-11-27 14:04 UTC (permalink / raw)
  To: lee, Tony Lindgren, Haojian Zhuang, Linus Walleij,
	linux-arm-kernel, linux-omap, linux-gpio, linux-kernel
  Cc: stable, Alexander Sverdlin

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v3 10/12] pinctrl: single: Free pinconf settings array with pinctrl_utils_free_map()
  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 09/12] pinctrl: single: Reject invalid register width in pcs_probe() Lee Jones
@ 2026-11-27 14:04 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2026-11-27 14:04 UTC (permalink / raw)
  To: lee, Tony Lindgren, Haojian Zhuang, Linus Walleij, Dan Carpenter,
	Yang Yingliang, linux-arm-kernel, linux-omap, linux-gpio,
	linux-kernel
  Cc: stable

pcs_parse_pinconf() allocates a per-map settings array and attaches it
to map[i].data.configs.configs, while pcs_dt_node_to_map() allocates
*map itself, both via devm_kzalloc_objs() on pcs->dev.

When a consumer device unbinds and re-probes, pcs_dt_free_map() only
frees map and leaks the settings array on pcs->dev.  Moreover, because
pcs_probe() registers the pinctrl device with devres before pinctrl
hogs or consumers call pcs_dt_node_to_map(), devres teardown on
pcs->dev unbind frees *map and settings before
devm_pinctrl_dev_release() invokes .dt_free_map().

Allocate *map and settings with unmanaged kzalloc_objs() and wire
.dt_free_map directly to pinctrl_utils_free_map(), dropping the custom
pcs_dt_free_map() callback.

Fixes: 8f773bfbdd42 ("pinctrl: single: fix possible memory leak when pinctrl_enable() fails")
Fixes: 9dddb4df90d1 ("pinctrl: single: support generic pinconf")
Closes: https://sashiko.dev/#/bug/linux-fcedec46-4487-4392-a882-3d3bef07e56f
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
v2 => v3:
 - Allocate the pinconf settings array with kzalloc_objs() and wire .dt_free_map directly to pinctrl_utils_free_map(), dropping pcs_dt_free_map(), per Alexander Sverdlin's review.
 - Update the first Fixes tag to commit 8f773bfbdd42 ("pinctrl: single: fix possible memory leak when pinctrl_enable() fails").

 drivers/pinctrl/pinctrl-single.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 6f5113dcdb4b..3f756796c792 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -32,6 +32,7 @@
 #include "core.h"
 #include "devicetree.h"
 #include "pinconf.h"
+#include "pinctrl-utils.h"
 #include "pinmux.h"
 
 #define DRIVER_NAME			"pinctrl-single"
@@ -308,15 +309,6 @@ static void pcs_pin_dbg_show(struct pinctrl_dev *pctldev,
 	seq_printf(s, "%zx %08x %s ", pa, val, DRIVER_NAME);
 }
 
-static void pcs_dt_free_map(struct pinctrl_dev *pctldev,
-				struct pinctrl_map *map, unsigned num_maps)
-{
-	struct pcs_device *pcs;
-
-	pcs = pinctrl_dev_get_drvdata(pctldev);
-	devm_kfree(pcs->dev, map);
-}
-
 static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev,
 				struct device_node *np_config,
 				struct pinctrl_map **map, unsigned *num_maps);
@@ -327,7 +319,7 @@ static const struct pinctrl_ops pcs_pinctrl_ops = {
 	.get_group_pins = pinctrl_generic_get_group_pins,
 	.pin_dbg_show = pcs_pin_dbg_show,
 	.dt_node_to_map = pcs_dt_node_to_map,
-	.dt_free_map = pcs_dt_free_map,
+	.dt_free_map = pinctrl_utils_free_map,
 };
 
 static int pcs_get_function(struct pinctrl_dev *pctldev, unsigned pin,
@@ -960,7 +952,7 @@ static int pcs_parse_pinconf(struct pcs_device *pcs, struct device_node *np,
 	func->nconfs = nconfs;
 	conf = &(func->conf[0]);
 	m++;
-	settings = devm_kzalloc_objs(pcs->dev, unsigned long, nconfs);
+	settings = kzalloc_objs(unsigned long, nconfs);
 	if (!settings)
 		return -ENOMEM;
 	s = &settings[0];
@@ -1284,7 +1276,7 @@ static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev,
 	pcs = pinctrl_dev_get_drvdata(pctldev);
 
 	/* create 2 maps. One is for pinmux, and the other is for pinconf. */
-	*map = devm_kzalloc_objs(pcs->dev, **map, 2);
+	*map = kzalloc_objs(**map, 2);
 	if (!*map)
 		return -ENOMEM;
 
@@ -1319,7 +1311,7 @@ static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev,
 free_pgnames:
 	devm_kfree(pcs->dev, pgnames);
 free_map:
-	devm_kfree(pcs->dev, *map);
+	kfree(*map);
 
 	return ret;
 }
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-27 14:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 09/12] pinctrl: single: Reject invalid register width in pcs_probe() Lee Jones
2026-11-27 14:04 ` [PATCH v3 10/12] pinctrl: single: Free pinconf settings array with pinctrl_utils_free_map() Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox