Re: [PATCH] acpica: fix -Wnull-pointer-arithmetic warnings

From: Qian Cai
Date: Wed Jul 24 2019 - 10:40:02 EST


On Wed, 2019-07-24 at 14:17 +0000, Moore, Robert wrote:
>
> -----Original Message-----
> From: Qian Cai [mailto:cai@xxxxxx]Â;
> Sent: Wednesday, July 24, 2019 6:40 AM
> To: Moore, Robert <robert.moore@xxxxxxxxx>; Nick Desaulniers <ndesaulniers@goo
> gle.com>
> Cc: Wysocki, Rafael J <rafael.j.wysocki@xxxxxxxxx>; Schmauss, Erik <erik.schma
> uss@xxxxxxxxx>; jkim@xxxxxxxxxxx; Len Brown <lenb@xxxxxxxxxx>; linux-acpi@vger
> .kernel.org; devel@xxxxxxxxxx; clang-built-linux <clang-built-linux@googlegrou
> ps.com>; LKML <linux-kernel@xxxxxxxxxxxxxxx>
> Subject: Re: [PATCH] acpica: fix -Wnull-pointer-arithmetic warnings
>
> On Tue, 2019-07-23 at 20:49 +0000, Moore, Robert wrote:
> > > > Signed-off-by: Qian Cai <cai@xxxxxx>
> > > > ---
> > > > include/acpi/actypes.h | 4 ++--
> > > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h index
> > > > ad6892a24015..25b4a32da177 100644
> > > > --- a/include/acpi/actypes.h
> > > > +++ b/include/acpi/actypes.h
> > > > @@ -500,13 +500,13 @@ typedef u64 acpi_integer;
> > > >
> > > > #define ACPI_CAST_PTR(t, p)ÂÂÂÂÂÂÂÂÂÂÂÂÂ((t *) (acpi_uintptr_t)Â
> > > > (p)) #define ACPI_CAST_INDIRECT_PTR(t, p)ÂÂÂÂ((t **)Â
> > > > (acpi_uintptr_t) (p)) -#define ACPI_ADD_PTR(t, a, b)ÂÂÂÂÂÂÂÂÂÂÂ
> > > > ACPI_CAST_PTR (t, (ACPI_CAST_PTR (u8, (a)) + (acpi_size)(b)))
> > > > +#define ACPI_ADD_PTR(t, a, b)ÂÂÂÂÂÂÂÂÂÂÂACPI_CAST_PTR (t, (a) +
> > > > (acpi_size)(b))
> >
> > We have some questions concerning this change. If (a) is not cast to aÂ
> > u8, the addition will be in whatever units are appropriate for (a)Â
> > i.e., the type of (a). However, we want ACPI_ADD_PTR (AndÂ
> > ACPI_SUB_PTR) to simply perform a byte addition or subtraction - thusÂ
> > the cast to u8. I believe that is the original thinking behind the macros.
>
> I posted a v2 a while ago, and should clear this concern.
>
> OK then this change only affects ACPI_TO_POINTER?
>
> +#define ACPI_TO_POINTER(i)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂACPI_CAST_PTR (void, i)

Yes.

>
>
> >
> > > > #define ACPI_SUB_PTR(t, a, b)ÂÂÂÂÂÂÂÂÂÂÂACPI_CAST_PTR (t,Â
> > > > (ACPI_CAST_PTR (u8, (a)) - (acpi_size)(b))) #defineÂ
> > > > ACPI_PTR_DIFF(a, b)ÂÂÂÂÂÂÂÂÂÂÂÂÂ((acpi_size) (ACPI_CAST_PTR (u8,
> > > > (a)) - ACPI_CAST_PTR (u8, (b))))
> > > >
> > > > /* Pointer/Integer type conversions */
> > > >
> > > > -#define ACPI_TO_POINTER(i)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂACPI_ADD_PTR (void, (voidÂ
> > > > *) 0,
> > > > (acpi_size) (i))
> > > > +#define ACPI_TO_POINTER(i)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂACPI_ADD_PTR (void, 0,
> > > > (acpi_size) (i))
> > >
> > > IIUC, these are adding `i` to NULL (or (void*)0)? X + 0 == X ?
> > > --
> > > Thanks,
> > > ~Nick Desaulniers
> >
> >