Skip to contentSkip to conversation

Input: sparcspkr: Fix refcount leak in bbc_beep_probe

PATCH In review Miaoqian Lin 2 participants 3 messages May 16, 2022 – May 17, 2022

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

PATCH 1/1 Input: sparcspkr: Fix refcount leak in bbc_beep_probe

of_find_node_by_path() calls of_find_node_opts_by_path(), which returns a node pointer with refcount incremented, we should use of_node_put() on it when done. Add missing of_node_put() to avoid refcount leak.

Fixes 9c1a5077fdca ("input: Rewrite sparcspkr device probing.")
---
 drivers/input/misc/sparcspkr.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/input/misc/sparcspkr.c +6 -3
index fe43e5557ed7..6a86900aa1fb 100644
@@ -206,11 +206,11 @@ static int bbc_beep_probe(struct platform_device *op)
 	info = &state->u.bbc;
 	info->clock_freq = of_getintprop_default(dp, "clock-frequency", 0);
 	if (!info->clock_freq)
-		goto out_free;
+		goto out_put;
 
 	info->regs = of_ioremap(&op->resource[0], 0, 6, "bbc beep");
 	if (!info->regs)
-		goto out_free;
+		goto out_put;
 
 	platform_set_drvdata(op, state);
 
@@ -218,11 +218,14 @@ static int bbc_beep_probe(struct platform_device *op)
 	if (err)
 		goto out_clear_drvdata;
 
+	of_node_put(dp);
+
 	return 0;
 
 out_clear_drvdata:
 	of_iounmap(&op->resource[0], info->regs, 6);
-
+out_put:
+	of_node_put(dp);
 out_free:
 	kfree(state);
 out_err:
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Hi

Quoted 8 lines · Miaoqian Lin

of_find_node_by_path() calls of_find_node_opts_by_path(), which returns a node pointer with refcount incremented, we should use of_node_put() on it when done. Add missing of_node_put() to avoid refcount leak.

Fixes 9c1a5077fdca ("input: Rewrite sparcspkr device probing.")

---

Thank you for the patch.

Quoted 22 lines
 drivers/input/misc/sparcspkr.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/input/misc/sparcspkr.c +2 -2
index fe43e5557ed7..6a86900aa1fb 100644
@@ -206,11 +206,11 @@ static int bbc_beep_probe(struct platform_device *op)
 	info = &state->u.bbc;
 	info->clock_freq = of_getintprop_default(dp, "clock-frequency", 0);
 	if (!info->clock_freq)
-		goto out_free;
+		goto out_put;
 
 	info->regs = of_ioremap(&op->resource[0], 0, 6, "bbc beep");
 	if (!info->regs)
-		goto out_free;
+		goto out_put;
 
 	platform_set_drvdata(op, state);
 

drivers/input/misc/sparcspkr.c static int bbc_beep_probe(struct platform_device *op) · line 222

Quoted 5 lines
drivers/input/misc/sparcspkr.c +2 -0
@@ -218,11 +218,14 @@ static int bbc_beep_probe(struct platform_device *op)
 	if (err)
 		goto out_clear_drvdata;
 
+	of_node_put(dp);
+

We do not really need to keep node pointer for that long, how about the version of your patch below?

Thanks.

Signature · 20 lines
Dmitry


Input: sparcspkr - fix refcount leak in bbc_beep_probe

From: Miaoqian Lin <[email protected]>

of_find_node_by_path() calls of_find_node_opts_by_path(),
which returns a node pointer with refcount
incremented, we should use of_node_put() on it when done.
Add missing of_node_put() to avoid refcount leak.

Fixes: 9c1a5077fdca ("input: Rewrite sparcspkr device probing.")
Signed-off-by: Miaoqian Lin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Patchwork-Id: 12850379
Signed-off-by: Dmitry Torokhov <[email protected]>
---
 drivers/input/misc/sparcspkr.c |    1 +
 1 file changed, 1 insertion(+)
drivers/input/misc/sparcspkr.c +1 -0
index fe43e5557ed7..cdcb7737c46a 100644
@@ -205,6 +205,7 @@ static int bbc_beep_probe(struct platform_device *op)
 
 	info = &state->u.bbc;
 	info->clock_freq = of_getintprop_default(dp, "clock-frequency", 0);
+	of_node_put(dp);
 	if (!info->clock_freq)
 		goto out_free;
 
#2 lore raw

Hi, Dmitry

Quoted 33 lines · Dmitry Torokhov

Hi

Quoted 8 lines · Miaoqian Lin

of_find_node_by_path() calls of_find_node_opts_by_path(), which returns a node pointer with refcount incremented, we should use of_node_put() on it when done. Add missing of_node_put() to avoid refcount leak.

Fixes 9c1a5077fdca ("input: Rewrite sparcspkr device probing.")

---

Thank you for the patch.

Quoted 21 lines
 drivers/input/misc/sparcspkr.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/input/misc/sparcspkr.c +2 -2
index fe43e5557ed7..6a86900aa1fb 100644
@@ -206,11 +206,11 @@ static int bbc_beep_probe(struct platform_device *op)
 	info = &state->u.bbc;
 	info->clock_freq = of_getintprop_default(dp, "clock-frequency", 0);
 	if (!info->clock_freq)
-		goto out_free;
+		goto out_put;
 
 	info->regs = of_ioremap(&op->resource[0], 0, 6, "bbc beep");
 	if (!info->regs)
-		goto out_free;
+		goto out_put;
 
 	platform_set_drvdata(op, state);
 
Quoted 8 lines

drivers/input/misc/sparcspkr.c static int bbc_beep_probe(struct platform_device *op) · line 222

Quoted 6 lines
drivers/input/misc/sparcspkr.c +2 -0
@@ -218,11 +218,14 @@ static int bbc_beep_probe(struct platform_device *op)
 	if (err)
 		goto out_clear_drvdata;
 
+	of_node_put(dp);
+

We do not really need to keep node pointer for that long, how about the version of your patch below?

Looks good to me.

Quoted 2 lines

Thanks.