* [PATCH] pinctrl: rockchip: fix memleak in rockchip_dt_node_to_map
@ 2020-05-06 10:09 Dafna Hirschfeld
2020-05-06 10:57 ` Heiko Stübner
2020-05-12 17:46 ` Linus Walleij
0 siblings, 2 replies; 3+ messages in thread
From: Dafna Hirschfeld @ 2020-05-06 10:09 UTC (permalink / raw)
To: linux-gpio, linux-rockchip
Cc: helen.koike, dafna.hirschfeld, ezequiel, dafna3, kernel,
linus.walleij, heiko
In function rockchip_dt_node_to_map, a new_map variable is
allocated by:
new_map = devm_kcalloc(pctldev->dev, map_num, sizeof(*new_map),
GFP_KERNEL);
This uses devres and attaches new_map to the pinctrl driver.
This cause a leak since new_map is not released when the probed
driver is removed. Fix it by using kcalloc to allocate new_map
and free it in `rockchip_dt_free_map`
Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
---
drivers/pinctrl/pinctrl-rockchip.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
index a9299f0bd21e..c07324d1f265 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -508,8 +508,8 @@ static int rockchip_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;
@@ -519,7 +519,7 @@ static int rockchip_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;
@@ -546,6 +546,7 @@ static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev,
static void rockchip_dt_free_map(struct pinctrl_dev *pctldev,
struct pinctrl_map *map, unsigned num_maps)
{
+ kfree(map);
}
static const struct pinctrl_ops rockchip_pctrl_ops = {
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] pinctrl: rockchip: fix memleak in rockchip_dt_node_to_map
2020-05-06 10:09 [PATCH] pinctrl: rockchip: fix memleak in rockchip_dt_node_to_map Dafna Hirschfeld
@ 2020-05-06 10:57 ` Heiko Stübner
2020-05-12 17:46 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Heiko Stübner @ 2020-05-06 10:57 UTC (permalink / raw)
To: Dafna Hirschfeld
Cc: linux-gpio, linux-rockchip, helen.koike, ezequiel, dafna3,
kernel, linus.walleij
Am Mittwoch, 6. Mai 2020, 12:09:03 CEST schrieb Dafna Hirschfeld:
> In function rockchip_dt_node_to_map, a new_map variable is
> allocated by:
>
> new_map = devm_kcalloc(pctldev->dev, map_num, sizeof(*new_map),
> GFP_KERNEL);
>
> This uses devres and attaches new_map to the pinctrl driver.
> This cause a leak since new_map is not released when the probed
> driver is removed. Fix it by using kcalloc to allocate new_map
> and free it in `rockchip_dt_free_map`
>
> Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
Reviewed-by: Heiko Stuebner <heiko@sntech.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pinctrl: rockchip: fix memleak in rockchip_dt_node_to_map
2020-05-06 10:09 [PATCH] pinctrl: rockchip: fix memleak in rockchip_dt_node_to_map Dafna Hirschfeld
2020-05-06 10:57 ` Heiko Stübner
@ 2020-05-12 17:46 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2020-05-12 17:46 UTC (permalink / raw)
To: Dafna Hirschfeld
Cc: open list:GPIO SUBSYSTEM, open list:ARM/Rockchip SoC...,
helen.koike, ezequiel, dafna3, kernel, Heiko Stübner
On Wed, May 6, 2020 at 12:09 PM Dafna Hirschfeld
<dafna.hirschfeld@collabora.com> wrote:
> In function rockchip_dt_node_to_map, a new_map variable is
> allocated by:
>
> new_map = devm_kcalloc(pctldev->dev, map_num, sizeof(*new_map),
> GFP_KERNEL);
>
> This uses devres and attaches new_map to the pinctrl driver.
> This cause a leak since new_map is not released when the probed
> driver is removed. Fix it by using kcalloc to allocate new_map
> and free it in `rockchip_dt_free_map`
>
> Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
Patch applied.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-12 17:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06 10:09 [PATCH] pinctrl: rockchip: fix memleak in rockchip_dt_node_to_map Dafna Hirschfeld
2020-05-06 10:57 ` Heiko Stübner
2020-05-12 17:46 ` Linus Walleij
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.