diff mbox series

[v2,1/4] pinctrl: sprd: free maps on DT map failure

Message ID 20261003083200.459705-2-yaojiale02@163.com
State New
Headers show
Series pinctrl: free maps on DT mapping failures | expand

Commit Message

Jiale Yao Oct. 3, 2026, 8:31 a.m. UTC
sprd_dt_node_to_map() reserves map storage before adding mux and
configuration entries.  If a later operation fails, the error path only
frees the temporary configurations and leaves the map allocation reachable
through the output pointer.

Free the partially built map on failure.  The caller ignores the output
parameters when the mapping callback returns an error, so they do not need
to be reset after freeing the map.

Fixes: 41d32cfce1ae ("pinctrl: sprd: Add Spreadtrum pin control driver")
Signed-off-by: Jiale Yao <yaojiale02@163.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
 drivers/pinctrl/sprd/pinctrl-sprd.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Linus Walleij Oct. 7, 2026, 10:33 a.m. UTC | #1
On Sat, Oct 3, 2026 at 10:32 AM Jiale Yao <yaojiale02@163.com> wrote:

> sprd_dt_node_to_map() reserves map storage before adding mux and
> configuration entries.  If a later operation fails, the error path only
> frees the temporary configurations and leaves the map allocation reachable
> through the output pointer.
>
> Free the partially built map on failure.  The caller ignores the output
> parameters when the mapping callback returns an error, so they do not need
> to be reset after freeing the map.
>
> Fixes: 41d32cfce1ae ("pinctrl: sprd: Add Spreadtrum pin control driver")
> Signed-off-by: Jiale Yao <yaojiale02@163.com>
> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

Patch applied.

Yours,
Linus Walleij
diff mbox series

Patch

diff --git a/drivers/pinctrl/sprd/pinctrl-sprd.c b/drivers/pinctrl/sprd/pinctrl-sprd.c
index 16cf9d15f247..a565d4fd4233 100644
--- a/drivers/pinctrl/sprd/pinctrl-sprd.c
+++ b/drivers/pinctrl/sprd/pinctrl-sprd.c
@@ -326,6 +326,9 @@  static int sprd_dt_node_to_map(struct pinctrl_dev *pctldev,
 
 out:
 	kfree(configs);
+	if (ret < 0)
+		pinctrl_utils_free_map(pctldev, *map, *num_maps);
+
 	return ret;
 }