From 2f64dc70baba18dc0b2d91d92f13bda7f2f28112 Mon Sep 17 00:00:00 2001 From: Nishka Dasgupta Date: Sun, 4 Aug 2019 21:10:29 +0530 Subject: [PATCH 1/3] pinctrl: rzn1: Add of_node_put() before return Each iteration of for_each_child_of_node puts the previous node, but in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the return in three places. Issue found with Coccinelle. Signed-off-by: Nishka Dasgupta Signed-off-by: Geert Uytterhoeven --- drivers/pinctrl/pinctrl-rzn1.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/pinctrl-rzn1.c b/drivers/pinctrl/pinctrl-rzn1.c index cc0e5aa9128a..0f6f8a10a53a 100644 --- a/drivers/pinctrl/pinctrl-rzn1.c +++ b/drivers/pinctrl/pinctrl-rzn1.c @@ -412,8 +412,10 @@ static int rzn1_dt_node_to_map(struct pinctrl_dev *pctldev, for_each_child_of_node(np, child) { ret = rzn1_dt_node_to_map_one(pctldev, child, map, num_maps); - if (ret < 0) + if (ret < 0) { + of_node_put(child); return ret; + } } return 0; @@ -792,8 +794,10 @@ static int rzn1_pinctrl_parse_functions(struct device_node *np, grp = &ipctl->groups[ipctl->ngroups]; grp->func = func->name; ret = rzn1_pinctrl_parse_groups(child, grp, ipctl); - if (ret < 0) + if (ret < 0) { + of_node_put(child); return ret; + } i++; ipctl->ngroups++; } @@ -838,8 +842,10 @@ static int rzn1_pinctrl_probe_dt(struct platform_device *pdev, for_each_child_of_node(np, child) { ret = rzn1_pinctrl_parse_functions(child, ipctl, i++); - if (ret < 0) + if (ret < 0) { + of_node_put(child); return ret; + } } return 0; From 6da53cfa0f8300c85c7b63c9a6951400474a142c Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Wed, 31 Jul 2019 11:41:16 +0200 Subject: [PATCH 2/3] pinctrl: sh-pfc: Use dev_notice_once() instead of open-coding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At the time of commit 9a643c9a11259955 ("sh-pfc: Convert message printing from pr_* to dev_*"), the dev_*_once() variants didn't exist yet, so the once behavior was open-coded. Since commit e135303bd5bebcd2 ("device: Add dev__once variants") they do, so "revert" to the good practice of using a helper. Signed-off-by: Geert Uytterhoeven Reviewed-by: Ulrich Hecht Reviewed-by: Niklas Söderlund --- drivers/pinctrl/sh-pfc/gpio.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/pinctrl/sh-pfc/gpio.c b/drivers/pinctrl/sh-pfc/gpio.c index 97c1332c1045..64c09aa374ae 100644 --- a/drivers/pinctrl/sh-pfc/gpio.c +++ b/drivers/pinctrl/sh-pfc/gpio.c @@ -255,18 +255,13 @@ static int gpio_pin_setup(struct sh_pfc_chip *chip) #ifdef CONFIG_PINCTRL_SH_FUNC_GPIO static int gpio_function_request(struct gpio_chip *gc, unsigned offset) { - static bool __print_once; struct sh_pfc *pfc = gpio_to_pfc(gc); unsigned int mark = pfc->info->func_gpios[offset].enum_id; unsigned long flags; int ret; - if (!__print_once) { - dev_notice(pfc->dev, - "Use of GPIO API for function requests is deprecated." - " Convert to pinctrl\n"); - __print_once = true; - } + dev_notice_once(pfc->dev, + "Use of GPIO API for function requests is deprecated, convert to pinctrl\n"); if (mark == 0) return -EINVAL; From 625efea83a7c37d281c6a90526813a1366929d24 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Wed, 7 Aug 2019 09:15:02 +0200 Subject: [PATCH 3/3] pinctrl: rza1: Use devm_platform_ioremap_resource() helper Use the devm_platform_ioremap_resource() helper instead of open-coding the same operation. Signed-off-by: Geert Uytterhoeven --- drivers/pinctrl/pinctrl-rza1.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/pinctrl/pinctrl-rza1.c b/drivers/pinctrl/pinctrl-rza1.c index 021e37b7689e..68aeefe29144 100644 --- a/drivers/pinctrl/pinctrl-rza1.c +++ b/drivers/pinctrl/pinctrl-rza1.c @@ -1359,7 +1359,6 @@ static int rza1_pinctrl_register(struct rza1_pinctrl *rza1_pctl) static int rza1_pinctrl_probe(struct platform_device *pdev) { struct rza1_pinctrl *rza1_pctl; - struct resource *res; int ret; rza1_pctl = devm_kzalloc(&pdev->dev, sizeof(*rza1_pctl), GFP_KERNEL); @@ -1368,8 +1367,7 @@ static int rza1_pinctrl_probe(struct platform_device *pdev) rza1_pctl->dev = &pdev->dev; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - rza1_pctl->base = devm_ioremap_resource(&pdev->dev, res); + rza1_pctl->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(rza1_pctl->base)) return PTR_ERR(rza1_pctl->base);