From: Stephen Boyd <sboyd@kernel.org>
To: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>, mchehab+huawei@kernel.org
Cc: linux-kernel@vger.kernel.org, krzk@kernel.org,
Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Subject: Re: [PATCH v2] spmi: hisi-spmi-controller: manage the OF node reference in device initialization and cleanup
Date: Wed, 18 Dec 2024 11:49:32 -0800 [thread overview]
Message-ID: <beb398abfe3082c128b0393f168dcc86.sboyd@kernel.org> (raw)
In-Reply-To: <20241218033954.940888-1-joe@pf.is.s.u-tokyo.ac.jp>
Quoting Joe Hattori (2024-12-17 19:39:54)
> spmi_controller_probe() increments the refcount of an OF node, but does
> not release it. Instead, call of_node_get() in spmi_controller_alloc()
> and release it in spmi_ctrl_release() to avoid the reference leak. Also
> remove the lines in spmi_pmic_arb_bus_init() and spmi_controller_probe()
> where a pdev's of_node is stored after spmi_controller_alloc() is
> called.
That last sentence says what is done but doesn't explain why. Please
explain why stashing the of_node in the two drivers are removed.
>
> This bug was found by an experimental static analysis tool that I am
> developing.
>
> Fixes: e562cf3aea3e ("spmi: hisi-spmi-controller: move driver from staging")
> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
[...]
> diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c
> index fb0101da1485..e662a7a78df2 100644
> --- a/drivers/spmi/spmi.c
> +++ b/drivers/spmi/spmi.c
> @@ -36,6 +36,7 @@ static void spmi_ctrl_release(struct device *dev)
> struct spmi_controller *ctrl = to_spmi_controller(dev);
>
> ida_free(&ctrl_ida, ctrl->nr);
> + of_node_put(dev->of_node);
> kfree(ctrl);
> }
>
> @@ -458,7 +459,7 @@ struct spmi_controller *spmi_controller_alloc(struct device *parent,
> ctrl->dev.type = &spmi_ctrl_type;
> ctrl->dev.bus = &spmi_bus_type;
> ctrl->dev.parent = parent;
> - ctrl->dev.of_node = parent->of_node;
> + ctrl->dev.of_node = of_node_get(parent->of_node);
Do we need to use device_set_node() here?
> spmi_controller_set_drvdata(ctrl, &ctrl[1]);
>
next prev parent reply other threads:[~2024-12-18 19:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-18 3:39 [PATCH v2] spmi: hisi-spmi-controller: manage the OF node reference in device initialization and cleanup Joe Hattori
2024-12-18 19:49 ` Stephen Boyd [this message]
2024-12-19 1:37 ` Joe Hattori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=beb398abfe3082c128b0393f168dcc86.sboyd@kernel.org \
--to=sboyd@kernel.org \
--cc=joe@pf.is.s.u-tokyo.ac.jp \
--cc=krzk@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab+huawei@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox