From: Jonathan Cameron <jic23@kernel.org>
To: Rob Herring <robh@kernel.org>
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
Frank Rowand <frowand.list@gmail.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Julia Lawall <Julia.Lawall@inria.fr>,
Nicolas Palix <nicolas.palix@imag.fr>,
Sumera Priyadarsini <sylphrenadin@gmail.com>
Subject: Re: [RFC PATCH 1/4] of: Add cleanup.h based autorelease via __free(device_node) markings.
Date: Sun, 14 Jan 2024 16:39:54 +0000 [thread overview]
Message-ID: <20240114163954.32e23985@jic23-huawei> (raw)
In-Reply-To: <20231221105434.5842ff3a@jic23-huawei>
On Thu, 21 Dec 2023 10:54:34 +0000
Jonathan Cameron <jic23@kernel.org> wrote:
> On Wed, 20 Dec 2023 16:11:44 -0600
> Rob Herring <robh@kernel.org> wrote:
>
> > On Sun, Dec 17, 2023 at 06:46:45PM +0000, Jonathan Cameron wrote:
> > > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > >
> > > The recent addition of scope based cleanup support to the kernel
> > > provides a convenient tool to reduce the chances of leaking reference
> > > counts where of_node_put() should have been called in an error path.
> > >
> > > This enables
> > > struct device_node *child __free(device_node) = NULL;
> > >
> > > for_each_child_of_node(np, child) {
> > > if (test)
> > > return test;
> > > }
> > >
> > > with no need for a manual call of of_node_put()
> > >
> > > In this simile example the gains are small but there are some very
> >
> > typo
> >
> > > complex error handling cases burried in these loops that wil be
> > > greatly simplified by enabling early returns with out the need
> > > for this manual of_node_put() call.
> >
> > Neat!
> >
> > I guess that now that the coccinelle check has fixed many, we can update
> > it to the new way and start fixing them all again. We should update the
> > coccinelle script with the new way. See
> > scripts/coccinelle/iterators/for_each_child.cocci.
>
> If the holiday season gets dull enough I'll take a look at updating that
> as well. Been a long time since I last messed with coccinelle.
>
> Given this is just a simplification rather than a fix, there would be no rush
> to convert things over but we definitely don't want the coccinelle script
> to generate lots of false positives. + we should perhaps add a
> script to try and catch the opposite (double free) as a result of
> using this automated cleanup.
Hi Rob,
As things currently stand the script doesn't trigger on a
struct device_node __free(device_node); (which is wrong anyway)
or
struct device_node __free(device_node) = NULL;
So we at least don't cause a flurry of false positives via these
changes.
I'm not keen to add an upstream check to encourage conversion over
to this new approach simply because there is no great rush to do it
and it's easy enough to use grep to find potential targets today.
Also strongly motivated by the fact I don't really have time to
learn coccinelle (however useful that would be in the long run!)
As such I'll tidy these up a bit and send out a non RFC version with
cover letter additions to mention we don't cause false positives and
that a coccinelle script to find candidates might make sense in the
longer term. It may also make sense to add checks that we don't manually
release the node on error paths without making sure to steal the pointer
(which sets it to NULL to avoid problems).
+CC various Coccinelle folk even though I'm proposing to not do any
coccinelle scripting for now.
Jonathan
next prev parent reply other threads:[~2024-01-14 16:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-17 18:46 [RFC PATCH 0/4] of: Automate handling of of_node_put() Jonathan Cameron
2023-12-17 18:46 ` [RFC PATCH 1/4] of: Add cleanup.h based autorelease via __free(device_node) markings Jonathan Cameron
2023-12-20 22:11 ` Rob Herring
2023-12-21 10:54 ` Jonathan Cameron
2024-01-08 12:53 ` Jonathan Cameron
2024-01-14 16:39 ` Jonathan Cameron [this message]
2023-12-17 18:46 ` [RFC PATCH 2/4] of: unittest: Use __free(device_node) Jonathan Cameron
2023-12-17 18:46 ` [RFC PATCH 3/4] iio: adc: fsl-imx25-gcq: " Jonathan Cameron
2023-12-17 18:46 ` [RFC PATCH 4/4] iio: adc: rcar-gyroadc: use __free(device_node) Jonathan Cameron
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=20240114163954.32e23985@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=Julia.Lawall@inria.fr \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=nicolas.palix@imag.fr \
--cc=robh@kernel.org \
--cc=sylphrenadin@gmail.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 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).