From: Julia Lawall <julia.lawall@inria.fr>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: Julia Lawall <julia.lawall@inria.fr>,
Rob Herring <robh@kernel.org>,
Roman Storozhenko <romeusmeister@gmail.com>,
jirislaby@kernel.org, skhan@linuxfoundation.org,
javier.carrasco.cruz@gmail.com, linux-kernel@vger.kernel.org,
linux-serial@vger.kernel.org
Subject: Re: [PATCH] sysrq: Auto release device node using __free attribute
Date: Sat, 13 Apr 2024 21:15:25 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.22.394.2404132106281.3446@hadrien> (raw)
In-Reply-To: <2024041211-statistic-reformist-bf70@gregkh>
On Fri, 12 Apr 2024, Greg KH wrote:
> On Thu, Apr 11, 2024 at 08:17:07PM +0200, Julia Lawall wrote:
> >
> >
> > On Thu, 11 Apr 2024, Greg KH wrote:
> >
> > > On Thu, Apr 11, 2024 at 08:02:56PM +0200, Roman Storozhenko wrote:
> > > > Add a cleanup function attribute '__free(device_node)' to the device node
> > > > pointer initialization statement and remove the pairing cleanup function
> > > > call of 'of_node_put' at the end of the function.
> > > > The '_free()' attrubute is introduced by scope-based resource management
> > > > in-kernel framework implemented in 'cleanup.h'. A pointer marked with
> > > > '__free()' attribute makes a compiler insert a cleanup function call
> > > > to the places where the pointer goes out of the scope. This feature
> > > > allows to get rid of manual cleanup function calls.
> > > >
> > > > Suggested-by: Julia.Lawall <Julia.Lawall@inria.fr>
> > > > Signed-off-by: Roman Storozhenko <romeusmeister@gmail.com>
> > > > ---
> > > > This patch targets the next tree:
> > > > tree: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
> > > > tag: next-20240411
> > > > ---
> > > > drivers/tty/sysrq.c | 7 +++----
> > > > 1 file changed, 3 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
> > > > index 02217e3c916b..1d1261f618c0 100644
> > > > --- a/drivers/tty/sysrq.c
> > > > +++ b/drivers/tty/sysrq.c
> > > > @@ -758,11 +758,12 @@ static void sysrq_detect_reset_sequence(struct sysrq_state *state,
> > > > static void sysrq_of_get_keyreset_config(void)
> > > > {
> > > > u32 key;
> > > > - struct device_node *np;
> > > > struct property *prop;
> > > > const __be32 *p;
> > > >
> > > > - np = of_find_node_by_path("/chosen/linux,sysrq-reset-seq");
> > > > + struct device_node *np __free(device_node) =
> > > > + of_find_node_by_path("/chosen/linux,sysrq-reset-seq");
> > > > +
> > > > if (!np) {
> > > > pr_debug("No sysrq node found");
> > > > return;
> > > > @@ -781,8 +782,6 @@ static void sysrq_of_get_keyreset_config(void)
> > > >
> > > > /* Get reset timeout if any. */
> > > > of_property_read_u32(np, "timeout-ms", &sysrq_reset_downtime_ms);
> > > > -
> > > > - of_node_put(np);
> > > > }
> > > > #else
> > > > static void sysrq_of_get_keyreset_config(void)
> > >
> > > Also, this change really makes no sense at all, the pointer never goes
> > > out of scope except when the function is over, at the bottom. So why
> > > make this complex change at all for no benefit?
> > >
> > > In other words, properly understand the change you are making and only
> > > make it if it actually makes sense. It does not make any sense here,
> > > right?
> >
> > Maybe it would be nice to get rid of of_node_puts in the general case?
>
> That's a call for the of maintainer to make, and then if so, to do it
> across the whole tree, right?
>
> > Even though this one is not very annoying, there are some other functions
> > where there are many of_node_puts, and convoluted error handling code to
> > incorporate them on both the success and failure path. So maybe it would
> > be better to avoid the situation of having them sometimes and not having
> > them other times? But this is an opinion, and if the general consensus is
> > to only get rid of the cases that currently add complexity, then that is
> > possible too.
>
> Let's keep things simple until it has to be complex please.
Jonathan Cameron pointed me to the following series from Rob Herring:
https://lore.kernel.org/linux-devicetree/20240409-dt-cleanup-free-v2-0-5b419a4af38d@kernel.org/
The patch for of_node_put is:
https://lore.kernel.org/linux-devicetree/20240409-dt-cleanup-free-v2-3-5b419a4af38d@kernel.org/
It uses __free directy. The cases in the file drivers/of/property.c have
quite simple structure, with for each get just one put at the end of the
scope in most cases.
julia
>
> thanks,
>
> greg k-h
>
next prev parent reply other threads:[~2024-04-13 19:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-11 18:02 [PATCH] sysrq: Auto release device node using __free attribute Roman Storozhenko
2024-04-11 18:10 ` Greg KH
2024-04-11 18:25 ` Roman Storozhenko
2024-04-12 5:22 ` Greg KH
2024-04-11 18:11 ` Greg KH
2024-04-11 18:17 ` Julia Lawall
2024-04-12 5:22 ` Greg KH
2024-04-12 6:21 ` Julia Lawall
2024-04-13 19:15 ` Julia Lawall [this message]
2024-04-11 18:28 ` Roman Storozhenko
2024-04-12 5:20 ` Greg KH
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=alpine.DEB.2.22.394.2404132106281.3446@hadrien \
--to=julia.lawall@inria.fr \
--cc=gregkh@linuxfoundation.org \
--cc=javier.carrasco.cruz@gmail.com \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=robh@kernel.org \
--cc=romeusmeister@gmail.com \
--cc=skhan@linuxfoundation.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).