[PATCH v3 10/12] pinctrl: single: Free pinconf settings array with pinctrl_utils_free_map()
From: Lee Jones
Date: Fri Nov 27 2026 - 09:07:24 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_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@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
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