From: Linus Torvalds <torvalds@osdl.org>
To: Ingo Oeser <ioe-lkml@rameria.de>
Cc: linux-kernel@vger.kernel.org, arjanv@redhat.com,
Dave Jones <davej@redhat.com>, Jeff Garzik <jgarzik@pobox.com>,
viro@parcelfarce.linux.theplanet.co.uk,
bfennema@falcon.csc.calpoly.edu
Subject: Re: Fix UDF-FS potentially dereferencing null
Date: Sat, 17 Apr 2004 10:14:54 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.58.0404171009320.3947@ppc970.osdl.org> (raw)
In-Reply-To: <200404171313.02784.ioe-lkml@rameria.de>
On Sat, 17 Apr 2004, Ingo Oeser wrote:
>
> Or even call the attribute "nonnull", because this is a very obvious
> naming, even to non-native English readers.
I did that at first, but decided that what I really wanted was "safe".
"nonnull" is nice for avoiding the NULL check, but it's useless for
anything else.
"safe" to my mind means that not only is it not NULL, it's also safe to
dereference early (ie "prefetchable"), which has a lot of meaning for the
back-end.
> "safe" can mean anything from "safe to use under spinlock" to
> "you cannot get pregnant from using this variable".
That's pretty much _exactly_ what "safe" means.
Basically, a real C compiler is not allowed to dereference a pointer
speculatively, since that could have undefined side effects in the
machine. And "safe" means that there are no side effects, pregnancy-
or otherwise.
> GCC will not only optimize out the check, but also ensure that the we
> will not pass NULL ptrs, if it can notice it. If this gets pushed high
> enough (up to the register-like functions, where it gets first
> assigned), we will never face this kind of problem anymore and document
> this fact per function. Sounds like C coder heaven ;-)
No. "nonnull" is useless. Even if it isn't NULL, the C standard does not
allow the compiler to just dereference something willy-nilly.
In contrast, "safe" means that the compiler could do something like
int * safe ptr;
if (!a)
a = *ptr;
and know that it is "safe" to transform this into
tmp = *ptr;
a = a ? : tmp;
which it otherwise can't necessarily determine.
Linus
next prev parent reply other threads:[~2004-04-17 17:15 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-16 21:41 Dave Jones
2004-04-16 21:58 ` Linus Torvalds
2004-04-16 22:00 ` viro
2004-04-16 23:13 ` Jeff Garzik
2004-04-16 23:18 ` Dave Jones
2004-04-16 23:34 ` viro
2004-04-17 0:44 ` Linus Torvalds
2004-04-17 9:50 ` Arjan van de Ven
2004-04-17 10:42 ` Arjan van de Ven
2004-04-17 11:12 ` Ingo Oeser
2004-04-17 17:14 ` Linus Torvalds [this message]
2004-04-22 20:29 ` Alexandre Oliva
2004-04-22 20:56 ` Linus Torvalds
2004-04-23 14:00 ` Alexandre Oliva
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=Pine.LNX.4.58.0404171009320.3947@ppc970.osdl.org \
--to=torvalds@osdl.org \
--cc=arjanv@redhat.com \
--cc=bfennema@falcon.csc.calpoly.edu \
--cc=davej@redhat.com \
--cc=ioe-lkml@rameria.de \
--cc=jgarzik@pobox.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
/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
all inboxes | Powered by JetHome®