[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAK8P3a1Xmj0O8zORM9O+GLS9maqKV-awuSNQdC_zxN1z7mnjnA@mail.gmail.com>
Date: Thu, 30 Sep 2021 22:36:58 +0200
From: Arnd Bergmann <arnd@...nel.org>
To: "Rafael J. Wysocki" <rafael@...nel.org>
Cc: Len Brown <lenb@...nel.org>, Robert Moore <robert.moore@...el.com>,
Arnd Bergmann <arnd@...db.de>,
"Rafael J. Wysocki" <rafael.j.wysocki@...el.com>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Erik Kaneda <erik.kaneda@...el.com>,
ACPI Devel Maling List <linux-acpi@...r.kernel.org>,
"open list:ACPI COMPONENT ARCHITECTURE (ACPICA)" <devel@...ica.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
llvm@...ts.linux.dev
Subject: Re: [PATCH] ACPI: avoid NULL pointer arithmetic
On Thu, Sep 30, 2021 at 8:52 PM Rafael J. Wysocki <rafael@...nel.org> wrote:
>
> On Wed, Sep 29, 2021 at 8:47 PM Rafael J. Wysocki <rafael@...nel.org> wrote:
> >
> > On Mon, Sep 27, 2021 at 2:13 PM Arnd Bergmann <arnd@...nel.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
Powered by blists - more mailing lists