From: Nathan Lynch <nathanl@linux.ibm.com>
To: Brian King <brking@linux.vnet.ibm.com>, linuxppc-dev@lists.ozlabs.org
Cc: Tyrel Datwyler <tyreld@linux.ibm.com>,
Scott Cheloha <cheloha@linux.ibm.com>,
mmc@linux.vnet.ibm.com, nnac123@linux.ibm.com, brking@pobox.com
Subject: Re: [PATCH] powerpc: Fix device node refcounting
Date: Tue, 07 Feb 2023 09:14:08 -0600 [thread overview]
Message-ID: <87zg9po6db.fsf@linux.ibm.com> (raw)
In-Reply-To: <20230201195856.303385-1-brking@linux.vnet.ibm.com>
(cc'ing a few possibly interested people)
Brian King <brking@linux.vnet.ibm.com> writes:
> While testing fixes to the hvcs hotplug code, kmemleak was reporting
> potential memory leaks. This was tracked down to the struct device_node
> object associated with the hvcs device. Looking at the leaked
> object in crash showed that the kref in the kobject in the device_node
> had a reference count of 1 still, and the release function was never
> getting called as a result of this. This adds an of_node_put in
> pSeries_reconfig_remove_node in order to balance the refcounting
> so that we actually free the device_node in the case of it being
> allocated in pSeries_reconfig_add_node.
My concern here would be whether the additional put is the right thing
to do in all cases. The questions it raises for me are:
- Is it safe for nodes that were present at boot, instead of added
dynamically?
- Is it correct for all types of nodes, or is there something specific
to hvcs that leaves a dangling refcount?
Just hoping we're not stepping into a situation where we're preventing
leaks in some situations but doing use-after-free in others. :-)
>
> Signed-off-by: Brian King <brking@linux.vnet.ibm.com>
> ---
> arch/powerpc/platforms/pseries/reconfig.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c
> index 599bd2c78514..8cb7309b19a4 100644
> --- a/arch/powerpc/platforms/pseries/reconfig.c
> +++ b/arch/powerpc/platforms/pseries/reconfig.c
> @@ -77,6 +77,7 @@ static int pSeries_reconfig_remove_node(struct device_node *np)
> }
>
> of_detach_node(np);
> + of_node_put(np);
> of_node_put(parent);
> return 0;
In a situation like this where the of_node_put() call isn't obviously
connected to one of the of_ iterator APIs or similar, I would prefer a
comment indicating which "get" it balances. I suppose it corresponds to
the node initialization itself, i.e. the of_node_init() call sites in
pSeries_reconfig_add_node() and drivers/of/fdt.c::populate_node().
next prev parent reply other threads:[~2023-02-07 15:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-01 19:58 [PATCH] powerpc: Fix device node refcounting Brian King
2023-02-07 15:14 ` Nathan Lynch [this message]
2023-02-09 15:16 ` Brian King
2023-02-09 17:11 ` Nathan Lynch
2023-02-09 22:36 ` Brian King
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=87zg9po6db.fsf@linux.ibm.com \
--to=nathanl@linux.ibm.com \
--cc=brking@linux.vnet.ibm.com \
--cc=brking@pobox.com \
--cc=cheloha@linux.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mmc@linux.vnet.ibm.com \
--cc=nnac123@linux.ibm.com \
--cc=tyreld@linux.ibm.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.