2022-11-28 14:13:59

by Qiheng Lin

[permalink] [raw]
Subject: [PATCH] power: supply: Fix refcount leak in rk817_charger_probe

of_get_child_by_name() returns a node pointer with refcount
incremented, we should use of_node_put() on it when not need anymore.
Add missing of_node_put() to avoid refcount leak.

Fixes: 11cb8da0189b ("power: supply: Add charger driver for Rockchip RK817")
Signed-off-by: Qiheng Lin <[email protected]>
---
drivers/power/supply/rk817_charger.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/rk817_charger.c b/drivers/power/supply/rk817_charger.c
index 635f051b0821..d25a81d79fac 100644
--- a/drivers/power/supply/rk817_charger.c
+++ b/drivers/power/supply/rk817_charger.c
@@ -1060,8 +1060,10 @@ static int rk817_charger_probe(struct platform_device *pdev)
return -ENODEV;

charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
- if (!charger)
+ if (!charger) {
+ of_node_put(node);
return -ENOMEM;
+ }

charger->rk808 = rk808;

--
2.32.0


2022-11-29 18:05:15

by Chris Morgan

[permalink] [raw]
Subject: Re: [PATCH] power: supply: Fix refcount leak in rk817_charger_probe

On Mon, Nov 28, 2022 at 10:27:40PM +0800, Qiheng Lin wrote:
> of_get_child_by_name() returns a node pointer with refcount
> incremented, we should use of_node_put() on it when not need anymore.
> Add missing of_node_put() to avoid refcount leak.
>
> Fixes: 11cb8da0189b ("power: supply: Add charger driver for Rockchip RK817")
> Signed-off-by: Qiheng Lin <[email protected]>

Good catch, thank you!

Reviewed-by: Chris Morgan <[email protected]>

> ---
> drivers/power/supply/rk817_charger.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/power/supply/rk817_charger.c b/drivers/power/supply/rk817_charger.c
> index 635f051b0821..d25a81d79fac 100644
> --- a/drivers/power/supply/rk817_charger.c
> +++ b/drivers/power/supply/rk817_charger.c
> @@ -1060,8 +1060,10 @@ static int rk817_charger_probe(struct platform_device *pdev)
> return -ENODEV;
>
> charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
> - if (!charger)
> + if (!charger) {
> + of_node_put(node);
> return -ENOMEM;
> + }
>
> charger->rk808 = rk808;
>
> --
> 2.32.0
>

2022-12-03 02:19:10

by Sebastian Reichel

[permalink] [raw]
Subject: Re: [PATCH] power: supply: Fix refcount leak in rk817_charger_probe

Hi,

On Tue, Nov 29, 2022 at 11:35:45AM -0600, Chris Morgan wrote:
> On Mon, Nov 28, 2022 at 10:27:40PM +0800, Qiheng Lin wrote:
> > of_get_child_by_name() returns a node pointer with refcount
> > incremented, we should use of_node_put() on it when not need anymore.
> > Add missing of_node_put() to avoid refcount leak.
> >
> > Fixes: 11cb8da0189b ("power: supply: Add charger driver for Rockchip RK817")
> > Signed-off-by: Qiheng Lin <[email protected]>
>
> Good catch, thank you!
>
> Reviewed-by: Chris Morgan <[email protected]>

Thanks, merged.

-- Sebastian

> > ---
> > drivers/power/supply/rk817_charger.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/power/supply/rk817_charger.c b/drivers/power/supply/rk817_charger.c
> > index 635f051b0821..d25a81d79fac 100644
> > --- a/drivers/power/supply/rk817_charger.c
> > +++ b/drivers/power/supply/rk817_charger.c
> > @@ -1060,8 +1060,10 @@ static int rk817_charger_probe(struct platform_device *pdev)
> > return -ENODEV;
> >
> > charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
> > - if (!charger)
> > + if (!charger) {
> > + of_node_put(node);
> > return -ENOMEM;
> > + }
> >
> > charger->rk808 = rk808;
> >
> > --
> > 2.32.0
> >


Attachments:
(No filename) (1.29 kB)
signature.asc (849.00 B)
Download all attachments