pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init
Subsystems (4)
Krzysztof Kozlowski
maintainerPATCH 1/4 pinctrl: samsung: Fix device node refcount leaks in Exynos wakeup controller init
In exynos_eint_wkup_init() the for_each_child_of_node() loop is used with a break to find a matching child node. Although each iteration of for_each_child_of_node puts the previous node, but early exit from loop misses it. This leads to leak of device node.
--- drivers/pinctrl/samsung/pinctrl-exynos.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/pinctrl/samsung/pinctrl-exynos.c +8 -2
@@ -504,6 +504,7 @@ int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d) bank->nr_pins, &exynos_eint_irqd_ops, bank);if (!bank->irq_domain) {dev_err (dev,"wkup irq domain add failed\n" ); +of_node_put (wkup_np);return -ENXIO ; }
@@ -518,8 +519,10 @@ int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d) weint_data =devm_kcalloc (dev, bank->nr_pins,sizeof (*weint_data),GFP_KERNEL ); -if (!weint_data) +if (!weint_data) { +of_node_put (wkup_np);return -ENOMEM ; + }for (idx =0 ; idx < bank->nr_pins; ++idx) { irq =irq_of_parse_and_map (bank->of_node, idx);
@@ -536,10 +539,13 @@ int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d) } } -if (!muxed_banks) +if (!muxed_banks) { +of_node_put (wkup_np);return 0 ; + } irq =irq_of_parse_and_map (wkup_np,0 ); +of_node_put (wkup_np);if (!irq) {dev_err (dev,"irq number for muxed EINTs not found\n" );return 0 ;
Signature · 1 line
2.17.1
Krzysztof Kozlowski
maintainerPATCH 2/4 pinctrl: samsung: Fix device node refcount leaks in S3C24xx wakeup controller init
In s3c24xx_eint_init() the for_each_child_of_node() loop is used with a break to find a matching child node. Although each iteration of for_each_child_of_node puts the previous node, but early exit from loop misses it. This leads to leak of device node.
--- drivers/pinctrl/samsung/pinctrl-s3c24xx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pinctrl/samsung/pinctrl-s3c24xx.c +5 -1
@@ -490,8 +490,10 @@ static int s3c24xx_eint_init(struct samsung_pinctrl_drv_data *d)return -ENODEV ; eint_data =devm_kzalloc (dev,sizeof (*eint_data),GFP_KERNEL ); -if (!eint_data) +if (!eint_data) { +of_node_put (eint_np);return -ENOMEM ; + } eint_data->drvdata = d;
@@ -503,12 +505,14 @@ static int s3c24xx_eint_init(struct samsung_pinctrl_drv_data *d) irq =irq_of_parse_and_map (eint_np, i);if (!irq) {dev_err (dev,"failed to get wakeup EINT IRQ %d\n" , i); +of_node_put (eint_np);return -ENXIO ; } eint_data->parents[i] = irq;irq_set_chained_handler_and_data (irq, handlers[i], eint_data); } +of_node_put (eint_np); bank = d->pin_banks;for (i =0 ; i < d->nr_banks; ++i, ++bank) {
Signature · 1 line
2.17.1
Krzysztof Kozlowski
maintainerPATCH 3/4 pinctrl: samsung: Fix device node refcount leaks in S3C64xx wakeup controller init
In reply to Krzysztof KozlowskiIn s3c64xx_eint_eint0_init() the for_each_child_of_node() loop is used with a break to find a matching child node. Although each iteration of for_each_child_of_node puts the previous node, but early exit from loop misses it. This leads to leak of device node.
--- drivers/pinctrl/samsung/pinctrl-s3c64xx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pinctrl/samsung/pinctrl-s3c64xx.c +5 -1
@@ -704,8 +704,10 @@ static int s3c64xx_eint_eint0_init(struct samsung_pinctrl_drv_data *d)return -ENODEV ; data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); -if (!data) +if (!data) { +of_node_put (eint0_np);return -ENOMEM ; + } data->drvdata = d;for (i =0 ; i <NUM_EINT0_IRQ ; ++i) {
@@ -714,6 +716,7 @@ static int s3c64xx_eint_eint0_init(struct samsung_pinctrl_drv_data *d) irq =irq_of_parse_and_map (eint0_np, i);if (!irq) {dev_err (dev,"failed to get wakeup EINT IRQ %d\n" , i); +of_node_put (eint0_np);return -ENXIO ; }
@@ -721,6 +724,7 @@ static int s3c64xx_eint_eint0_init(struct samsung_pinctrl_drv_data *d) s3c64xx_eint0_handlers[i], data); } +of_node_put (eint0_np); bank = d->pin_banks;for (i =0 ; i < d->nr_banks; ++i, ++bank) {
Signature · 1 line
2.17.1
Krzysztof Kozlowski
maintainerPATCH 4/4 pinctrl: samsung: Fix device node refcount leaks in init code
In reply to Krzysztof KozlowskiSeveral functions use for_each_child_of_node() loop with a break to find a matching child node. Although each iteration of for_each_child_of_node puts the previous node, but early exit from loop misses it. This leads to leak of device node.
--- drivers/pinctrl/samsung/pinctrl-samsung.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/pinctrl/samsung/pinctrl-samsung.c +8 -2
@@ -272,6 +272,7 @@ static int samsung_dt_node_to_map(struct pinctrl_dev *pctldev, &reserved_maps, num_maps);if (ret <0 ) {samsung_dt_free_map (pctldev, *map, *num_maps); +of_node_put (np);return ret; } }
@@ -785,8 +786,10 @@ static struct samsung_pmx_func *samsung_pinctrl_create_functions(if (!of_get_child_count (cfg_np)) { ret =samsung_pinctrl_create_function (dev, drvdata, cfg_np, func); -if (ret <0 ) +if (ret <0 ) { +of_node_put (cfg_np);return ERR_PTR (ret); + }if (ret >0 ) { ++func; ++func_cnt;
@@ -797,8 +800,11 @@ static struct samsung_pmx_func *samsung_pinctrl_create_functions(for_each_child_of_node (cfg_np, func_np) { ret =samsung_pinctrl_create_function (dev, drvdata, func_np, func); -if (ret <0 ) +if (ret <0 ) { +of_node_put (func_np); +of_node_put (cfg_np);return ERR_PTR (ret); + }if (ret >0 ) { ++func; ++func_cnt;
Signature · 1 line
2.17.1
Quoted 6 lines · Krzysztof Kozlowski
In
exynos_eint_wkup_init()thefor_each_child_of_node()loop is used with a break to find a matching child node. Although each iteration offor_each_child_of_nodeputs the previous node, but early exit from loop misses it. This leads to leak of device node.Signed-off-by Krzysztof Kozlowski <[email protected]>
I assume you're collecting these for a pull request to me at some later point, all look good to me.
Yours,
Linus Walleij
Krzysztof Kozlowski
maintainerQuoted 8 lines · Linus Walleij
Quoted 5 lines · Krzysztof Kozlowski
In
exynos_eint_wkup_init()thefor_each_child_of_node()loop is used with a break to find a matching child node. Although each iteration offor_each_child_of_nodeputs the previous node, but early exit from loop misses it. This leads to leak of device node.
Quoted 4 lines
Quoted 1 line
Signed-off-by Krzysztof Kozlowski <[email protected]>I assume you're collecting these for a pull request to me at some later point, all look good to me.
Yes, I'll take these and one more patch from lists and send them to you.
Best regards,
Krzysztof