[PATCH v2 10/12] pinctrl: single: Free pinconf settings array in pcs_dt_free_map()
From: Lee Jones
Date: Thu Nov 19 2026 - 15:51:51 EST
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_kcalloc() 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 pcs_dt_free_map().
Allocate *map and settings with unmanaged kcalloc() and free both with
kfree() in pcs_dt_free_map().
Fixes: 8b8b091bf07f ("pinctrl: Add one-register-per-pin type device tree based pinctrl driver")
Fixes: 9dddb4df90d1 ("pinctrl: single: support generic pinconf")
Closes: https://sashiko.dev/#/bug/linux-fcedec46-4487-4392-a882-3d3bef07e56f
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
v1 => v2:
- Switch *map and settings to unmanaged kcalloc()/kfree() so devres
cannot free *map before pcs_dt_free_map() runs
drivers/pinctrl/pinctrl-single.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 1779ffbc1181..1ba692a7ecac 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -311,10 +311,12 @@ static void pcs_pin_dbg_show(struct pinctrl_dev *pctldev,
static void pcs_dt_free_map(struct pinctrl_dev *pctldev,
struct pinctrl_map *map, unsigned num_maps)
{
- struct pcs_device *pcs;
+ for (unsigned int i = 0; i < num_maps; i++) {
+ if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP)
+ kfree(map[i].data.configs.configs);
+ }
- pcs = pinctrl_dev_get_drvdata(pctldev);
- devm_kfree(pcs->dev, map);
+ kfree(map);
}
static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev,
@@ -964,8 +966,7 @@ static int pcs_parse_pinconf(struct pcs_device *pcs, struct device_node *np,
func->nconfs = nconfs;
conf = &(func->conf[0]);
m++;
- settings = devm_kcalloc(pcs->dev, nconfs, sizeof(unsigned long),
- GFP_KERNEL);
+ settings = kcalloc(nconfs, sizeof(unsigned long), GFP_KERNEL);
if (!settings)
return -ENOMEM;
s = &settings[0];
@@ -1289,7 +1290,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_kcalloc(pcs->dev, 2, sizeof(**map), GFP_KERNEL);
+ *map = kcalloc(2, sizeof(**map), GFP_KERNEL);
if (!*map)
return -ENOMEM;
@@ -1324,7 +1325,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.750.gf70dc682cf-goog