From: Kyle Moffett <mrmacman_g4@mac.com>
To: Jan Engelhardt <jengelh@computergmbh.de>
Cc: Rene Herman <rene.herman@gmail.com>,
Jason Uhlenkott <jasonuhl@jasonuhl.org>,
Arjan van de Ven <arjan@infradead.org>,
Tim Bird <tim.bird@am.sony.com>,
linux kernel <linux-kernel@vger.kernel.org>
Subject: Re: kfree(0) - ok?
Date: Wed, 15 Aug 2007 10:34:10 -0400 [thread overview]
Message-ID: <912C3FD2-3B6D-4328-8485-657F63CC6552@mac.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0708151604360.15707@fbirervta.pbzchgretzou.qr>
On Aug 15, 2007, at 10:06:49, Jan Engelhardt wrote:
> On Aug 15 2007 09:58, Kyle Moffett wrote:
>> Irrespective of whatever the standard says, EVERY platform and
>> compiler anybody makes nowadays has a NULL pointer value with all
>> bits clear. Theoretically the standard allows otherwise, but such
>> a decision would break so much code. Linux especially, we rely on
>> the uninitialized data to have all bits clear and we depend on
>> that producing NULL pointers; if a NULL pointer was not bitwise
>> exactly 0 then the test "if (some_ptr != NULL)" would fail and we
>> would start dereferencing garbage.
>
> But if kmalloc returns NULL on failure, then testing for NULL
> (irrespective of being 0 or 0xDEADBEEF) is ok. What would actually
> concern me then is what "if (!some_ptr)" would do. Probably not the
> right thing.
Well, what I was referring to is:
static struct foo *some_ptr;
/* Assumes that $SOME_LOCK is held */
int initialize_foo_module()
{
if (!some_ptr) {
some_ptr = kmalloc(sizeof(*some_ptr));
if (!some_ptr)
return -ENOMEM;
/* ... */
}
/* ... */
}
We initialize all of the static data to all-bits-clear zeros during
kernel init. Any platform on which the binary representations of
"(unsigned long)0" and "(void *)0" are different (even in length, due
to other issues) will not run the Linux kernel as it stands today.
And as to the sizeof(unsigned long) == sizeof(void *) issue, please
remember that every Linux compiler is either ILP32 (int, long, and
pointer are 32-bit) or LP64 (int is 32-bit and long/pointer are 64-
bit). We sort of fundamentally rely on these properties in code all
over the place.
So yes the Linux kernel "breaks the standard" in a bunch of places,
but on the other hand we're not your average software and we don't
have to worry about building on an LLP64 compiler (Windows 64-bit and
some UNIXes) or other strangeness.
Cheers,
Kyle Moffett
next prev parent reply other threads:[~2007-08-15 14:34 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-14 22:59 Tim Bird
2007-08-14 22:55 ` Arjan van de Ven
2007-08-14 23:21 ` Jason Uhlenkott
2007-08-15 7:28 ` Jan Engelhardt
2007-08-15 8:37 ` Rene Herman
2007-08-15 9:20 ` Jan Engelhardt
2007-08-15 9:43 ` Jason Uhlenkott
2007-08-15 9:58 ` Rene Herman
2007-08-15 10:20 ` Jan Engelhardt
2007-08-15 10:27 ` Rene Herman
2007-08-15 13:58 ` Kyle Moffett
2007-08-15 14:06 ` Jan Engelhardt
2007-08-15 14:34 ` Kyle Moffett [this message]
2007-08-15 16:01 ` H. Peter Anvin
2007-08-15 8:52 ` Jason Uhlenkott
2007-08-15 9:18 ` Andreas Schwab
2007-08-15 9:32 ` Giacomo A. Catenazzi
2007-08-14 23:42 ` Satyam Sharma
2007-08-15 0:19 ` Christoph Lameter
2007-08-17 18:22 ` Andrew Morton
2007-08-17 18:31 ` Arjan van de Ven
2007-08-17 18:50 ` Satyam Sharma
2007-08-17 18:37 ` Jan Engelhardt
2007-08-17 20:43 ` Christoph Lameter
2007-08-17 21:17 ` Satyam Sharma
2007-08-17 21:32 ` Satyam Sharma
2007-08-17 21:13 ` Satyam Sharma
2007-08-17 21:14 ` Christoph Lameter
2007-08-17 21:42 ` Pekka Enberg
2007-08-17 23:22 ` Christoph Lameter
2007-08-17 23:40 ` Thomas Gleixner
2007-08-18 0:02 ` Satyam Sharma
2007-08-18 1:03 ` Christoph Lameter
2007-08-18 8:10 ` Pekka Enberg
2007-08-18 8:21 ` Jan Engelhardt
2007-08-17 21:46 ` Satyam Sharma
2007-08-14 23:13 ` Satyam Sharma
[not found] <fa.oMJ6o9vN0dnAoFR83/o4hg1EptE@ifi.uio.no>
2007-08-14 23:05 ` Robert Hancock
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=912C3FD2-3B6D-4328-8485-657F63CC6552@mac.com \
--to=mrmacman_g4@mac.com \
--cc=arjan@infradead.org \
--cc=jasonuhl@jasonuhl.org \
--cc=jengelh@computergmbh.de \
--cc=linux-kernel@vger.kernel.org \
--cc=rene.herman@gmail.com \
--cc=tim.bird@am.sony.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
Powered by JetHome