Skip to contentSkip to conversation

gpio: gpiolib-of.c: Add of_node_put() before break

PATCH In review Nishka Dasgupta 2 participants 2 messages Jul 6, 2019 – Jul 8, 2019 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: gpiolib-of.c: Add of_node_put() before break

Each iteration of for_each_child_of_node puts the previous node, but in the case of a break from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the break. Issue found with Coccinelle.

---
 drivers/gpio/gpiolib-of.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpio/gpiolib-of.c +1 -0
index aec7bd86ae7e..c9325efc1783 100644
@@ -154,6 +154,7 @@ static void of_gpio_flags_quirks(struct device_node *np,
 							of_node_full_name(child));
 					*flags |= OF_GPIO_ACTIVE_LOW;
 				}
+				of_node_put(child);
 				break;
 			}
 		}
Signature · 1 line
2.19.1
#1 lore raw

sob., 6 lip 2019 o 15:34 Nishka Dasgupta <[email protected]> napisał(a):

Quoted 24 lines

Each iteration of for_each_child_of_node puts the previous node, but in the case of a break from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the break. Issue found with Coccinelle.

---
 drivers/gpio/gpiolib-of.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpio/gpiolib-of.c +1 -1
index aec7bd86ae7e..c9325efc1783 100644
@@ -154,6 +154,7 @@ static void of_gpio_flags_quirks(struct device_node *np,
                                                        of_node_full_name(child));
                                        *flags |= OF_GPIO_ACTIVE_LOW;
                                }
+                               of_node_put(child);
                                break;
                        }
                }
--
Quoted 2 lines

2.19.1

Applied for fixes with a slightly changed commit message. Thanks!

Bartosz