* [PATCH V2] power: supply: Fix additional refcount leak in rk817_charger_probe
@ 2023-09-20 14:56 Chris Morgan
2023-09-20 19:37 ` Sebastian Reichel
2023-09-20 20:31 ` Sebastian Reichel
0 siblings, 2 replies; 4+ messages in thread
From: Chris Morgan @ 2023-09-20 14:56 UTC (permalink / raw)
To: linux-pm; +Cc: linqiheng, sre, Chris Morgan, Dan Carpenter
From: Chris Morgan <macromorgan@hotmail.com>
Dan Carpenter reports that the Smatch static checker warning has found
that there is another refcount leak in the probe function. While
of_node_put() was added in one of the return paths, it should in
fact be added for ALL return paths that return an error.
Changes Since V1:
- Use devm_add_action_or_reset() to call of_node_put() instead of
calling it in every single error path from the probe() function.
Fixes: 54c03bfd094f ("power: supply: Fix refcount leak in rk817_charger_probe")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Closes: https://lore.kernel.org/linux-pm/dc0bb0f8-212d-4be7-be69-becd2a3f9a80@kili.mountain/
Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
---
drivers/power/supply/rk817_charger.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/drivers/power/supply/rk817_charger.c b/drivers/power/supply/rk817_charger.c
index 8328bcea1a29..708689d34959 100644
--- a/drivers/power/supply/rk817_charger.c
+++ b/drivers/power/supply/rk817_charger.c
@@ -1045,6 +1045,13 @@ static void rk817_charging_monitor(struct work_struct *work)
queue_delayed_work(system_wq, &charger->work, msecs_to_jiffies(8000));
}
+static void rk817_cleanup_node(void *data)
+{
+ struct device_node *node = data;
+
+ of_node_put(node);
+}
+
static int rk817_charger_probe(struct platform_device *pdev)
{
struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
@@ -1061,12 +1068,16 @@ static int rk817_charger_probe(struct platform_device *pdev)
if (!node)
return -ENODEV;
- charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
- if (!charger) {
+ ret = devm_add_action_or_reset(&pdev->dev, rk817_cleanup_node, node);
+ if (ret) {
of_node_put(node);
- return -ENOMEM;
+ return ret;
}
+ charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
+ if (!charger)
+ return -ENOMEM;
+
charger->rk808 = rk808;
charger->dev = &pdev->dev;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH V2] power: supply: Fix additional refcount leak in rk817_charger_probe
2023-09-20 14:56 [PATCH V2] power: supply: Fix additional refcount leak in rk817_charger_probe Chris Morgan
@ 2023-09-20 19:37 ` Sebastian Reichel
2023-09-20 20:31 ` Sebastian Reichel
1 sibling, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2023-09-20 19:37 UTC (permalink / raw)
To: linux-pm, Chris Morgan; +Cc: linqiheng, sre, Chris Morgan, Dan Carpenter
On Wed, 20 Sep 2023 09:56:44 -0500, Chris Morgan wrote:
> Dan Carpenter reports that the Smatch static checker warning has found
> that there is another refcount leak in the probe function. While
> of_node_put() was added in one of the return paths, it should in
> fact be added for ALL return paths that return an error.
>
> Changes Since V1:
> - Use devm_add_action_or_reset() to call of_node_put() instead of
> calling it in every single error path from the probe() function.
>
> [...]
Applied, thanks!
[1/1] power: supply: Fix additional refcount leak in rk817_charger_probe
commit: 488ef44c068e79752dba8eda0b75f524f111a695
Best regards,
--
Sebastian Reichel <sebastian.reichel@collabora.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH V2] power: supply: Fix additional refcount leak in rk817_charger_probe
2023-09-20 14:56 [PATCH V2] power: supply: Fix additional refcount leak in rk817_charger_probe Chris Morgan
2023-09-20 19:37 ` Sebastian Reichel
@ 2023-09-20 20:31 ` Sebastian Reichel
2023-09-21 13:18 ` Chris Morgan
1 sibling, 1 reply; 4+ messages in thread
From: Sebastian Reichel @ 2023-09-20 20:31 UTC (permalink / raw)
To: Chris Morgan; +Cc: linux-pm, linqiheng, Chris Morgan, Dan Carpenter
[-- Attachment #1: Type: text/plain, Size: 2490 bytes --]
Hi,
As you saw I applied this, but I did some modifications:
On Wed, Sep 20, 2023 at 09:56:44AM -0500, Chris Morgan wrote:
> From: Chris Morgan <macromorgan@hotmail.com>
>
> Dan Carpenter reports that the Smatch static checker warning has found
> that there is another refcount leak in the probe function. While
> of_node_put() was added in one of the return paths, it should in
> fact be added for ALL return paths that return an error.
>
> Changes Since V1:
> - Use devm_add_action_or_reset() to call of_node_put() instead of
> calling it in every single error path from the probe() function.
^ this should be below the ---
>
> Fixes: 54c03bfd094f ("power: supply: Fix refcount leak in rk817_charger_probe")
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Closes: https://lore.kernel.org/linux-pm/dc0bb0f8-212d-4be7-be69-becd2a3f9a80@kili.mountain/
> Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
> ---
> drivers/power/supply/rk817_charger.c | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/power/supply/rk817_charger.c b/drivers/power/supply/rk817_charger.c
> index 8328bcea1a29..708689d34959 100644
> --- a/drivers/power/supply/rk817_charger.c
> +++ b/drivers/power/supply/rk817_charger.c
> @@ -1045,6 +1045,13 @@ static void rk817_charging_monitor(struct work_struct *work)
> queue_delayed_work(system_wq, &charger->work, msecs_to_jiffies(8000));
> }
>
> +static void rk817_cleanup_node(void *data)
> +{
> + struct device_node *node = data;
> +
> + of_node_put(node);
> +}
> +
> static int rk817_charger_probe(struct platform_device *pdev)
> {
> struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
> @@ -1061,12 +1068,16 @@ static int rk817_charger_probe(struct platform_device *pdev)
> if (!node)
> return -ENODEV;
>
> - charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
> - if (!charger) {
> + ret = devm_add_action_or_reset(&pdev->dev, rk817_cleanup_node, node);
> + if (ret) {
> of_node_put(node);
devm_add_action_or_reset() calls the action on failure (that's the
'_or_reset' part). So this of_node_put() is wrong.
Thanks,
-- Sebastian
> - return -ENOMEM;
> + return ret;
> }
>
> + charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
> + if (!charger)
> + return -ENOMEM;
> +
> charger->rk808 = rk808;
>
> charger->dev = &pdev->dev;
> --
> 2.34.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH V2] power: supply: Fix additional refcount leak in rk817_charger_probe
2023-09-20 20:31 ` Sebastian Reichel
@ 2023-09-21 13:18 ` Chris Morgan
0 siblings, 0 replies; 4+ messages in thread
From: Chris Morgan @ 2023-09-21 13:18 UTC (permalink / raw)
To: Sebastian Reichel; +Cc: Chris Morgan, linux-pm, linqiheng, Dan Carpenter
On Wed, Sep 20, 2023 at 10:31:06PM +0200, Sebastian Reichel wrote:
> Hi,
>
> As you saw I applied this, but I did some modifications:
Thank you. Still learning so I appreciate all the help.
Chris
>
> On Wed, Sep 20, 2023 at 09:56:44AM -0500, Chris Morgan wrote:
> > From: Chris Morgan <macromorgan@hotmail.com>
> >
> > Dan Carpenter reports that the Smatch static checker warning has found
> > that there is another refcount leak in the probe function. While
> > of_node_put() was added in one of the return paths, it should in
> > fact be added for ALL return paths that return an error.
> >
> > Changes Since V1:
> > - Use devm_add_action_or_reset() to call of_node_put() instead of
> > calling it in every single error path from the probe() function.
>
> ^ this should be below the ---
>
> >
> > Fixes: 54c03bfd094f ("power: supply: Fix refcount leak in rk817_charger_probe")
> > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Closes: https://lore.kernel.org/linux-pm/dc0bb0f8-212d-4be7-be69-becd2a3f9a80@kili.mountain/
> > Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
> > ---
> > drivers/power/supply/rk817_charger.c | 17 ++++++++++++++---
> > 1 file changed, 14 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/power/supply/rk817_charger.c b/drivers/power/supply/rk817_charger.c
> > index 8328bcea1a29..708689d34959 100644
> > --- a/drivers/power/supply/rk817_charger.c
> > +++ b/drivers/power/supply/rk817_charger.c
> > @@ -1045,6 +1045,13 @@ static void rk817_charging_monitor(struct work_struct *work)
> > queue_delayed_work(system_wq, &charger->work, msecs_to_jiffies(8000));
> > }
> >
> > +static void rk817_cleanup_node(void *data)
> > +{
> > + struct device_node *node = data;
> > +
> > + of_node_put(node);
> > +}
> > +
> > static int rk817_charger_probe(struct platform_device *pdev)
> > {
> > struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
> > @@ -1061,12 +1068,16 @@ static int rk817_charger_probe(struct platform_device *pdev)
> > if (!node)
> > return -ENODEV;
> >
> > - charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
> > - if (!charger) {
> > + ret = devm_add_action_or_reset(&pdev->dev, rk817_cleanup_node, node);
> > + if (ret) {
> > of_node_put(node);
>
> devm_add_action_or_reset() calls the action on failure (that's the
> '_or_reset' part). So this of_node_put() is wrong.
>
> Thanks,
>
> -- Sebastian
>
> > - return -ENOMEM;
> > + return ret;
> > }
> >
> > + charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
> > + if (!charger)
> > + return -ENOMEM;
> > +
> > charger->rk808 = rk808;
> >
> > charger->dev = &pdev->dev;
> > --
> > 2.34.1
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-21 17:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-20 14:56 [PATCH V2] power: supply: Fix additional refcount leak in rk817_charger_probe Chris Morgan
2023-09-20 19:37 ` Sebastian Reichel
2023-09-20 20:31 ` Sebastian Reichel
2023-09-21 13:18 ` Chris Morgan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).