From: Linus Torvalds <torvalds@linux-foundation.org>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>,
Nathan Chancellor <nathan@kernel.org>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, Kees Cook <keescook@chromium.org>
Subject: Re: [GIT PULL] ext4 changes for the 6.4 merge window
Date: Fri, 28 Apr 2023 14:18:48 -0700 [thread overview]
Message-ID: <CAHk-=wjwMaS5=J7UgEPuoP_=01O9Ti62JVF-c=a6v3g2YAwzKQ@mail.gmail.com> (raw)
In-Reply-To: <CAKwvOd=mgAMuMODXTapt8JRqEFLS1j-hfssZE0YjJNjPhH=H5A@mail.gmail.com>
On Fri, Apr 28, 2023 at 2:03 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> >
> > void *bar(void) {
> > #if CONFIG_XYZ
> > if (somecondition) return NULL;
> > #endif
> > return foo(); }
> >
> > and the caller really *should* check for NULL - it's just that the
> > compiler never saw that case.
>
> I think having a return value be conditionally _Nonnull is "garbage
> in; garbage out."
No, no, you misunderstand.
"foo()" is the one that is unconditionally _Nonnull. It never returns NULL.
But *bar()* is not. There's no _Nonnull about 'bar()'. Never was, never will be.
We are *not* looking to statically mark everything that never returns
NULL as _Nonnull. Only some core helper functions.
If "bar()" is a complicated function that can under some circumstances
return NULL, then it's clearly not _Nonnull.
It does not matter one whit that maybe in some simplified config,
bar() might never return NULL. That simply does *not* make it
_Nonnull.
But my point is that for a *compiler*, this is not actually easy at all.
Because a compiler might inline 'bar()' entirely (it's a trivial
function that only calls 'foo()', after all, so it *should* be
inlined.
But now that 'bar()' has been inlined into some other call-site, that
*other* call site will have a test for "is the result NULL?"
And that other call site *should* have that test. Because it didn't
call "foo()", it called "bar()".
But with the inlining, the compiler will likely see just the call to
foo(), and I suspect your patch would make it then complain about how
the result is tested for NULL.
So it would need to have that special logic of "only warn if the test
is at the same level".
> Thinking more about this, I really think _Nonnull should behave like a
> qualifier (const, restrict, volatile). So the above example would be:
>
> void * _Nonnull ptr = foo();
> if (!ptr) // warning: tautology
That would solve the problem, yes. But I suspect it would be very
inconvenient for users.
In particular, it would have made it totally pointless for the issue
at hand: finding *existing* users of __filemap_get_folio() (that used
to return NULL for errors), and finding the cases where the NULL check
still exists now that it's no longer the right thign to do.
So I think it would largely defeat the use-case. It would only warn
for cases that have already been annotated.
So to be useful, I think it would have to be a "does automagically the
right thing" kind of feature.
Linus
next prev parent reply other threads:[~2023-04-28 21:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-25 4:18 Theodore Ts'o
2023-04-26 17:03 ` Linus Torvalds
2023-04-26 17:34 ` Nick Desaulniers
2023-04-26 17:36 ` Nick Desaulniers
2023-04-26 17:43 ` Nick Desaulniers
2023-04-26 18:11 ` Linus Torvalds
2023-04-26 18:22 ` Nick Desaulniers
2023-04-26 18:32 ` Linus Torvalds
2023-04-26 22:07 ` Nick Desaulniers
2023-04-26 22:31 ` Linus Torvalds
2023-04-28 21:02 ` Nick Desaulniers
2023-04-28 21:18 ` Linus Torvalds [this message]
2023-04-26 23:16 ` Theodore Ts'o
2023-04-26 19:10 ` Matthew Wilcox
2023-04-26 19:38 ` Linus Torvalds
2023-04-26 23:12 ` Theodore Ts'o
2023-05-03 8:03 ` Dan Carpenter
2023-04-26 17:06 ` pr-tracker-bot
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-=wjwMaS5=J7UgEPuoP_=01O9Ti62JVF-c=a6v3g2YAwzKQ@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=keescook@chromium.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=tytso@mit.edu \
/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