From: David Laight <David.Laight@ACULAB.COM>
To: 'Christian Brauner' <brauner@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: Kees Cook <keescook@chromium.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [GIT PULL] pid: use flex array
Date: Fri, 30 Jun 2023 11:21:44 +0000 [thread overview]
Message-ID: <8b73a39a359b4523a053efd614cd7dd7@AcuMS.aculab.com> (raw)
In-Reply-To: <20230630-stiefel-rotor-7f2d13fc084f@brauner>
From: Christian Brauner
> Sent: 30 June 2023 09:04
...
> > And some of them are even ok. I don't think it's always wrong,
> > particularly if you then abstract it out.
> >
> > So doing something like that
> >
> > #define PCI_IOBASE ((void __iomem *)0)
> >
> > makes perfect sense. It's literally abstracting out something real (in
> > this case yes, it looks like a NULL pointer, but it's actually a
> > pointer with a strict type that just happens to have the value zero.
You can't do that, it doesn't work.
A NULL pointer is any constant integer expression that evaluates
to zero implicitly or explicitly converted to a pointer type.
The bit pattern used for a NULL pointer is implementation defined.
It is almost always 0, but the C language allows any invalid
value to be used - eg the 'all ones' pattern.
clang warns for 'PCI_IOBASE + 4'.
Probably because it only has the expected value if NULL is the
zero bit pattern - so it isn't portable.
If has to be said that I doubt gcc or clang support NULL being
other than the zero bit pattern.
Any C code that uses memset() to set a pointer to NULL is making
that assumption.
I have used a system where the native 'invalid pointer' was ~0
but the C port used zero.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2023-06-30 11:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-28 10:37 Christian Brauner
2023-06-29 23:52 ` Linus Torvalds
2023-06-30 6:51 ` Christian Brauner
2023-06-30 7:12 ` Linus Torvalds
2023-06-30 8:04 ` Christian Brauner
2023-06-30 11:21 ` David Laight [this message]
2023-06-30 16:01 ` Linus Torvalds
2023-06-30 16:59 ` Kees Cook
2023-07-01 6:27 ` Christian Brauner
2023-07-01 6:44 ` [PATCH] pid: use struct_size_t() helper Christian Brauner
2023-07-01 15:28 ` Linus Torvalds
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=8b73a39a359b4523a053efd614cd7dd7@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=brauner@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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
Powered by JetHome