diff mbox series

Input: sparcspkr: Fix refcount leak in bbc_beep_probe

Message ID 20220516081018.42728-1-linmq006@gmail.com (mailing list archive)
State Accepted
Commit c8994b30d71d64d5dcc9bc0edbfdf367171aa96f
Headers show
Series Input: sparcspkr: Fix refcount leak in bbc_beep_probe | expand

Commit Message

Miaoqian Lin May 16, 2022, 8:10 a.m. UTC
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 <linmq006@gmail.com>
---
 drivers/input/misc/sparcspkr.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Dmitry Torokhov May 16, 2022, 10:08 p.m. UTC | #1
Hi 
On Mon, May 16, 2022 at 12:10:16PM +0400, Miaoqian Lin wrote:
> 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 <linmq006@gmail.com>
> ---

Thank you for the patch.

>  drivers/input/misc/sparcspkr.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
> index fe43e5557ed7..6a86900aa1fb 100644
> --- a/drivers/input/misc/sparcspkr.c
> +++ b/drivers/input/misc/sparcspkr.c
> @@ -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);
> +

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

Thanks.
Miaoqian Lin May 17, 2022, 5:39 a.m. UTC | #2
Hi, Dmitry

On 2022/5/17 6:08, Dmitry Torokhov wrote:
> Hi 
> On Mon, May 16, 2022 at 12:10:16PM +0400, Miaoqian Lin wrote:
>> 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 <linmq006@gmail.com>
>> ---
> Thank you for the patch.
>
>>  drivers/input/misc/sparcspkr.c | 9 ++++++---
>>  1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
>> index fe43e5557ed7..6a86900aa1fb 100644
>> --- a/drivers/input/misc/sparcspkr.c
>> +++ b/drivers/input/misc/sparcspkr.c
>> @@ -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);
>> +
> We do not really need to keep node pointer for that long, how about the
> version of your patch below?
Looks good to me.
> Thanks.
>
diff mbox series

Patch

diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
index fe43e5557ed7..6a86900aa1fb 100644
--- a/drivers/input/misc/sparcspkr.c
+++ b/drivers/input/misc/sparcspkr.c
@@ -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: