Commit d7faa8ff authored by Dafna Hirschfeld's avatar Dafna Hirschfeld Committed by Linus Walleij

pinctrl: rockchip: fix memleak in rockchip_dt_node_to_map

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: default avatarDafna Hirschfeld <dafna.hirschfeld@collabora.com>
Reviewed-by: default avatarHeiko Stuebner <heiko@sntech.de>
Link: https://lore.kernel.org/r/20200506100903.15420-1-dafna.hirschfeld@collabora.comSigned-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent c4f333b7
...@@ -508,8 +508,8 @@ static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev, ...@@ -508,8 +508,8 @@ static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev,
} }
map_num += grp->npins; 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) if (!new_map)
return -ENOMEM; return -ENOMEM;
...@@ -519,7 +519,7 @@ static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev, ...@@ -519,7 +519,7 @@ static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev,
/* create mux map */ /* create mux map */
parent = of_get_parent(np); parent = of_get_parent(np);
if (!parent) { if (!parent) {
devm_kfree(pctldev->dev, new_map); kfree(new_map);
return -EINVAL; return -EINVAL;
} }
new_map[0].type = PIN_MAP_TYPE_MUX_GROUP; new_map[0].type = PIN_MAP_TYPE_MUX_GROUP;
...@@ -546,6 +546,7 @@ static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev, ...@@ -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, static void rockchip_dt_free_map(struct pinctrl_dev *pctldev,
struct pinctrl_map *map, unsigned num_maps) struct pinctrl_map *map, unsigned num_maps)
{ {
kfree(map);
} }
static const struct pinctrl_ops rockchip_pctrl_ops = { static const struct pinctrl_ops rockchip_pctrl_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment