[PATCH 2/2] pinctrl: ti-iodelay: fix memory leaks on consumer re-probe
From: A. Sverdlin
Date: Thu Oct 01 2026 - 04:52:50 EST
From: Alexander Sverdlin <alexander.sverdlin@xxxxxxxxxxx>
ti_iodelay_dt_node_to_map() allocates a pinctrl_map, a group, a pin array
and a config array per mapping with devres on the controller, and registers
the group via pinctrl_generic_add_group(). The core deduplicates groups by
name and keeps the first for the controller's lifetime, so on a repeated
mapping of the same node (consumer re-probe) the freshly built group, pins
and configs are dropped and leaked. The pinctrl_map leaked too: the driver
never implemented pinctrl_ops::dt_free_map, so nothing released it.
Reuse the deduplicated group and free the redundant copy (repointing the
map at the retained group), and add dt_free_map() to release the map.
Fixes: 003910ebc83b ("pinctrl: Introduce TI IOdelay configuration driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@xxxxxxxxxxx>
---
drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
index 019b302db2b00..9a8865ce0bbab 100644
--- a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
+++ b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
@@ -497,6 +497,7 @@ static int ti_iodelay_dt_node_to_map(struct pinctrl_dev *pctldev,
struct ti_iodelay_device *iod;
struct ti_iodelay_cfg *cfg;
struct ti_iodelay_pingroup *g;
+ struct group_desc *grp;
const char *name = "pinctrl-pin-array";
int rows, *pins, error = -EINVAL, i;
@@ -553,6 +554,19 @@ static int ti_iodelay_dt_node_to_map(struct pinctrl_dev *pctldev,
if (error < 0)
goto free_data;
+ /*
+ * The core deduplicates groups by name and keeps the first for the
+ * controller's lifetime; on a repeated mapping (consumer re-probe)
+ * reuse it and free our now-redundant copy.
+ */
+ grp = pinctrl_generic_get_group(iod->pctl, error);
+ if (grp->data != g) {
+ devm_kfree(iod->dev, cfg);
+ devm_kfree(iod->dev, pins);
+ devm_kfree(iod->dev, g);
+ g = grp->data;
+ }
+
(*map)->type = PIN_MAP_TYPE_CONFIGS_GROUP;
(*map)->data.configs.group_or_pin = np->name;
(*map)->data.configs.configs = &g->config;
@@ -722,6 +736,15 @@ static void ti_iodelay_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
}
#endif
+static void ti_iodelay_dt_free_map(struct pinctrl_dev *pctldev,
+ struct pinctrl_map *map, unsigned int num_maps)
+{
+ struct ti_iodelay_device *iod;
+
+ iod = pinctrl_dev_get_drvdata(pctldev);
+ devm_kfree(iod->dev, map);
+}
+
static const struct pinctrl_ops ti_iodelay_pinctrl_ops = {
.get_groups_count = pinctrl_generic_get_group_count,
.get_group_name = pinctrl_generic_get_group_name,
@@ -730,6 +753,7 @@ static const struct pinctrl_ops ti_iodelay_pinctrl_ops = {
.pin_dbg_show = ti_iodelay_pin_dbg_show,
#endif
.dt_node_to_map = ti_iodelay_dt_node_to_map,
+ .dt_free_map = ti_iodelay_dt_free_map,
};
static const struct pinconf_ops ti_iodelay_pinctrl_pinconf_ops = {
--
2.55.0