Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
Reviewed-by: Heiko Stuebner <heiko@sntech.de>
Link: https://lore.kernel.org/r/20200506100903.15420-1-dafna.hirschfeld@collabora.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Dafna Hirschfeld and committed by
Linus Walleij
d7faa8ff c4f333b7

+4 -3
+4 -3
drivers/pinctrl/pinctrl-rockchip.c
··· 508 508 } 509 509 510 510 map_num += grp->npins; 511 - new_map = devm_kcalloc(pctldev->dev, map_num, sizeof(*new_map), 512 - GFP_KERNEL); 511 + 512 + new_map = kcalloc(map_num, sizeof(*new_map), GFP_KERNEL); 513 513 if (!new_map) 514 514 return -ENOMEM; 515 515 ··· 519 519 /* create mux map */ 520 520 parent = of_get_parent(np); 521 521 if (!parent) { 522 - devm_kfree(pctldev->dev, new_map); 522 + kfree(new_map); 523 523 return -EINVAL; 524 524 } 525 525 new_map[0].type = PIN_MAP_TYPE_MUX_GROUP; ··· 546 546 static void rockchip_dt_free_map(struct pinctrl_dev *pctldev, 547 547 struct pinctrl_map *map, unsigned num_maps) 548 548 { 549 + kfree(map); 549 550 } 550 551 551 552 static const struct pinctrl_ops rockchip_pctrl_ops = {