linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Len Brown <lenb@kernel.org>,
	Robert Moore <robert.moore@intel.com>,
	Arnd Bergmann <arnd@arndb.de>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Erik Kaneda <erik.kaneda@intel.com>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	"open list:ACPI COMPONENT ARCHITECTURE (ACPICA)"
	<devel@acpica.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	llvm@lists.linux.dev
Subject: Re: [PATCH] ACPI: avoid NULL pointer arithmetic
Date: Thu, 30 Sep 2021 22:36:58 +0200	[thread overview]
Message-ID: <CAK8P3a1Xmj0O8zORM9O+GLS9maqKV-awuSNQdC_zxN1z7mnjnA@mail.gmail.com> (raw)
In-Reply-To: <CAJZ5v0jDKK6ecsubVDv_=EUF3goiiDW28tvbKF9cesMphgKaug@mail.gmail.com>

On Thu, Sep 30, 2021 at 8:52 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Wed, Sep 29, 2021 at 8:47 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> >
> > On Mon, Sep 27, 2021 at 2:13 PM Arnd Bergmann <arnd@kernel.org> wrote:
> > >
> > >  #define ACPI_TO_POINTER(i)              ACPI_CAST_PTR (void, (acpi_size) (i))
> > > -#define ACPI_TO_INTEGER(p)              ACPI_PTR_DIFF (p, (void *) 0)
> > > -#define ACPI_OFFSET(d, f)               ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) 0)
> > > +#define ACPI_TO_INTEGER(p)              ((uintptr_t)(p))
> > > +#define ACPI_OFFSET(d, f)               offsetof(d, f)
> > >  #define ACPI_PHYSADDR_TO_PTR(i)         ACPI_TO_POINTER(i)
> > >  #define ACPI_PTR_TO_PHYSADDR(i)         ACPI_TO_INTEGER(i)
> > >
> > > --
> >
> > Queued up as 5.16 material, converted into an upstream ACPICA pull
> > request and submitted, thanks!
>
> And reverted from there, because it introduced build issues.
>
> Can we use alternative definitions that don't depend on uintptr_t and
> offsetof()?

It's a bit tricky, as both were introduced to avoid portability issues.

For uintptr_t, we could use 'unsigned long', which works on everything
that Linux can run on, but wouldn't work if this code can be compiled
for 64-bit Windows. 'size_t' probably works, but likely has the same problem
as 'uintptr_t' because they require and additional #include. I see
that some code uses acpi_uintptr_t, which looks like it is meant to
replace uintptr_t, this is defined as 'void *' in include/acpi/actypes.h,
so that probably wouldn't avoid the warning.

For offsetof(), we could use __builtin_offsetof(), which would work with
any gcc-compatible compiler, if the goal is to avoid including <stddef.h>.
If it has to work on other compilers, there is no portable way that doesn't
rely on standard headers. The best idea I'd have would be to use
"#ifdef offsetof" to choose between the trivial implementation I had
and the old one that works for non-standard C but may invoke
undefined behavior.

       Arnd

      reply	other threads:[~2021-09-30 20:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27 12:13 [PATCH] ACPI: avoid NULL pointer arithmetic Arnd Bergmann
2021-09-28 17:43 ` Rafael J. Wysocki
2021-09-28 20:39   ` Moore, Robert
2021-09-29 12:01     ` Rafael J. Wysocki
2021-09-29 18:47 ` Rafael J. Wysocki
2021-09-30 18:52   ` Rafael J. Wysocki
2021-09-30 20:36     ` Arnd Bergmann [this message]

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=CAK8P3a1Xmj0O8zORM9O+GLS9maqKV-awuSNQdC_zxN1z7mnjnA@mail.gmail.com \
    --to=arnd@kernel.org \
    --cc=arnd@arndb.de \
    --cc=devel@acpica.org \
    --cc=erik.kaneda@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=robert.moore@intel.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;
as well as URLs for NNTP newsgroup(s).