Skip to contentSkip to conversation

input: keyboard: mtk-pmic-keys: Add of_node_put() before return

PATCH Applied Nishka Dasgupta 2 participants 2 messages Jul 9, 2019 – Jul 12, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input: keyboard: mtk-pmic-keys: 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.

---
 drivers/input/keyboard/mtk-pmic-keys.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/input/keyboard/mtk-pmic-keys.c +7 -2
index 746ff06eaf8d..62391d6c7da6 100644
@@ -277,8 +277,10 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
 		keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index];
 
 		keys->keys[index].irq = platform_get_irq(pdev, index);
-		if (keys->keys[index].irq < 0)
+		if (keys->keys[index].irq < 0) {
+			of_node_put(child);
 			return keys->keys[index].irq;
+		}
 
 		error = of_property_read_u32(child,
 			"linux,keycodes", &keys->keys[index].keycode);
@@ -286,6 +288,7 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
 			dev_err(keys->dev,
 				"failed to read key:%d linux,keycode property: %d\n",
 				index, error);
+			of_node_put(child);
 			return error;
 		}
 
@@ -293,8 +296,10 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
 			keys->keys[index].wakeup = true;
 
 		error = mtk_pmic_key_setup(keys, &keys->keys[index]);
-		if (error)
+		if (error) {
+			of_node_put(child);
 			return error;
+		}
 
 		index++;
 	}
Signature · 1 line
2.19.1
maintainer Applied
#1 lore raw
Quoted 7 lines · Nishka Dasgupta

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.

Applied, thank you.

Quoted 43 lines
---
 drivers/input/keyboard/mtk-pmic-keys.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/input/keyboard/mtk-pmic-keys.c +7 -2
index 746ff06eaf8d..62391d6c7da6 100644
@@ -277,8 +277,10 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
 		keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index];
 
 		keys->keys[index].irq = platform_get_irq(pdev, index);
-		if (keys->keys[index].irq < 0)
+		if (keys->keys[index].irq < 0) {
+			of_node_put(child);
 			return keys->keys[index].irq;
+		}
 
 		error = of_property_read_u32(child,
 			"linux,keycodes", &keys->keys[index].keycode);
@@ -286,6 +288,7 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
 			dev_err(keys->dev,
 				"failed to read key:%d linux,keycode property: %d\n",
 				index, error);
+			of_node_put(child);
 			return error;
 		}
 
@@ -293,8 +296,10 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
 			keys->keys[index].wakeup = true;
 
 		error = mtk_pmic_key_setup(keys, &keys->keys[index]);
-		if (error)
+		if (error) {
+			of_node_put(child);
 			return error;
+		}
 
 		index++;
 	}
Signature · 1 line
2.19.1
Signature · 1 line
Dmitry