From: Linus Torvalds <torvalds@linux-foundation.org>
To: James Bottomley <James.Bottomley@hansenpartnership.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Bart Van Assche <bvanassche@acm.org>,
ksummit@lists.linux.dev, Dan Williams <dan.j.williams@intel.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: Clarifying confusion of our variable placement rules caused by cleanup.h
Date: Tue, 18 Nov 2025 12:30:07 -0800 [thread overview]
Message-ID: <CAHk-=wjD1r5dr_b7gpuPdTXGdXAtaM6wHBSJyzi-Zfw3-cqR6w@mail.gmail.com> (raw)
In-Reply-To: <bff6d9974e50f7cb27cc2b150ecd6e5e2252ae54.camel@HansenPartnership.com>
On Tue, 18 Nov 2025 at 12:21, James Bottomley
<James.Bottomley@hansenpartnership.com> wrote:
>
> On Tue, 2025-11-18 at 14:17 -0500, Steven Rostedt wrote:
> > I think the code could also be better optimized? I haven't run an
> > objcopy to confirm but now early exits do not require calling the
> > __free() function on NULL pointers.
>
> Yes, I can confirm that (at least from reading the docs not actually
> from disassembling the code).
Actually, I _have_ been disassembling some of that code, and most of
the time the compiler is actually good at eliding those things and not
calling kfree() with a NULL pointer.
Now, the reason for that is actually that we spent some effort on this
in <linux/cleanup.h> (and by "we" I mean mostly PeterZ & co with me
being involved in the discussions).
So you'll see those destructor functions being inline functions with
things like that
DEFINE_FREE(kfree, void *, if (_T) kfree(_T))
where that "if (_T)" being integral to having the compiler able to see
inline that "oh, it's statically NULL at this stage, I don't need to
call any external function".
But yes, sometimes having the declaration later can simplify this all
for the compiler too. But the *primary* thing should be about making
the code itself legible and maintainable to humans.
Linus
next prev parent reply other threads:[~2025-11-18 20:30 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-18 16:39 James Bottomley
2025-11-18 17:18 ` Bart Van Assche
2025-11-18 18:38 ` Linus Torvalds
2025-11-18 19:04 ` Bart Van Assche
2025-11-18 19:14 ` Linus Torvalds
2025-11-18 20:43 ` Al Viro
2025-11-18 19:15 ` H. Peter Anvin
2025-11-18 19:11 ` H. Peter Anvin
2025-11-18 19:16 ` Linus Torvalds
2025-11-18 19:19 ` H. Peter Anvin
2025-11-18 19:17 ` Steven Rostedt
2025-11-18 19:22 ` Linus Torvalds
2025-11-18 19:56 ` Steven Rostedt
2025-11-18 20:23 ` Linus Torvalds
2025-11-18 21:05 ` Linus Torvalds
2025-11-18 20:21 ` James Bottomley
2025-11-18 20:30 ` Linus Torvalds [this message]
2025-11-18 20:51 ` Steven Rostedt
2025-11-18 21:10 ` James Bottomley
2025-11-18 22:34 ` Steven Rostedt
2025-11-18 23:32 ` James Bottomley
2025-11-18 19:23 ` H. Peter Anvin
2025-11-18 20:28 ` James Bottomley
2025-11-25 13:09 ` Jani Nikula
2025-11-25 14:25 ` Alexey Dobriyan
2025-11-25 15:32 ` Stephen Hemminger
2025-11-25 16:04 ` Steven Rostedt
2025-11-25 17:57 ` H. Peter Anvin
2025-12-31 12:17 ` Andy Shevchenko
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='CAHk-=wjD1r5dr_b7gpuPdTXGdXAtaM6wHBSJyzi-Zfw3-cqR6w@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=James.Bottomley@hansenpartnership.com \
--cc=bvanassche@acm.org \
--cc=dan.carpenter@linaro.org \
--cc=dan.j.williams@intel.com \
--cc=ksummit@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.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