diff mbox series

[1/1] pinctrl/ar91: fix a memleak in at91_dt_node_to_map

Message ID 20220602073033.8385-1-ruc_gongyuanjun@163.com
State New
Headers show
Series [1/1] pinctrl/ar91: fix a memleak in at91_dt_node_to_map | expand

Commit Message

Yuanjun Gong June 2, 2022, 7:30 a.m. UTC
A new_map is allocated in at91_dt_node_to_map but it is not
freed in at91_dt_free_map, causing a memory leak.

Fix it by using kcalloc to allocate new_map and free it in
at91_dt_free_map

Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com>
---
 drivers/pinctrl/pinctrl-at91.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Linus Walleij June 15, 2022, 1:37 p.m. UTC | #1
On Thu, Jun 2, 2022 at 9:31 AM Yuanjun Gong <ruc_gongyuanjun@163.com> wrote:

> A new_map is allocated in at91_dt_node_to_map but it is not
> freed in at91_dt_free_map, causing a memory leak.
>
> Fix it by using kcalloc to allocate new_map and free it in
> at91_dt_free_map
>
> Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com>

So why isn't devres refcounting working in this case?

Yours,
Linus Walleij
diff mbox series

Patch

diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index d91a010e65f5..32ab983a77fe 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -291,8 +291,7 @@  static int at91_dt_node_to_map(struct pinctrl_dev *pctldev,
 	}
 
 	map_num += grp->npins;
-	new_map = devm_kcalloc(pctldev->dev, map_num, sizeof(*new_map),
-			       GFP_KERNEL);
+	new_map = kcalloc(map_num, sizeof(*new_map), GFP_KERNEL);
 	if (!new_map)
 		return -ENOMEM;
 
@@ -302,7 +301,7 @@  static int at91_dt_node_to_map(struct pinctrl_dev *pctldev,
 	/* create mux map */
 	parent = of_get_parent(np);
 	if (!parent) {
-		devm_kfree(pctldev->dev, new_map);
+		kfree(new_map);
 		return -EINVAL;
 	}
 	new_map[0].type = PIN_MAP_TYPE_MUX_GROUP;
@@ -329,6 +328,7 @@  static int at91_dt_node_to_map(struct pinctrl_dev *pctldev,
 static void at91_dt_free_map(struct pinctrl_dev *pctldev,
 				struct pinctrl_map *map, unsigned num_maps)
 {
+	kfree(map);
 }
 
 static const struct pinctrl_ops at91_pctrl_ops = {