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

From: Qian Cai
Date: Thu Aug 01 2019 - 15:16:26 EST


On Fri, 2019-07-26 at 19:35 +0000, Moore, Robert wrote:
> We've taken the change to ACPI_TO_POINTER.

I am a bit confused here. I saw the commit in the acpia repo.

https://github.com/acpica/acpica/commit/02bbca5070e42d298c9b824300aa0eb8a082d797

but how does that change will go into the linux kernel? Suppose Rafael will need
to pick it up manually?

>
>
> -----Original Message-----
> From: Qian Cai [mailto:cai@xxxxxx]Â;
> Sent: Thursday, July 18, 2019 12:49 PM
> To: Wysocki, Rafael J <rafael.j.wysocki@xxxxxxxxx>
> Cc: Moore, Robert <robert.moore@xxxxxxxxx>; Schmauss, Erik <erik.schmauss@inte
> l.com>; jkim@xxxxxxxxxxx; lenb@xxxxxxxxxx; ndesaulniers@xxxxxxxxxx; linux-acpi
> @vger.kernel.org; devel@xxxxxxxxxx; clang-built-linux@xxxxxxxxxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx; Qian Cai <cai@xxxxxx>
> Subject: [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings
>
> Clang generate quite a few of those warnings.
>
> drivers/acpi/scan.c:759:28: warning: arithmetic on a null pointer treated as a
> cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
> status = acpi_get_handle(ACPI_ROOT_OBJECT,
> obj->string.pointer,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ^~~~~~~~~~~~~~~~
> ./include/acpi/actypes.h:458:56: note: expanded from macro 'ACPI_ROOT_OBJECT'
> Â#define ACPI_ROOT_OBJECTÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ((acpi_handle) ACPI_TO_POINTER
> (ACPI_MAX_PTR))
> ^~~~~~~~~~~~~~~
> ./include/acpi/actypes.h:509:41: note: expanded from macro 'ACPI_TO_POINTER'
> Â#define ACPI_TO_POINTER(i)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂACPI_ADD_PTR (void, (void *) 0,
> (acpi_size) (i))
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ./include/acpi/actypes.h:503:84: note: expanded from macro 'ACPI_ADD_PTR'
> Â#define ACPI_ADD_PTR(t, a, b)ÂÂÂÂÂÂÂÂÂÂÂACPI_CAST_PTR (t,
> (ACPI_CAST_PTR (u8, (a)) + (acpi_size)(b)))
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ^~~~~~~~~~~~~~~~~
> ./include/acpi/actypes.h:501:66: note: expanded from macro 'ACPI_CAST_PTR'
> Â#define ACPI_CAST_PTR(t, p)ÂÂÂÂÂÂÂÂÂÂÂÂÂ((t *) (acpi_uintptr_t) (p))
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ^ This is
> because pointer arithmetic on a pointer not pointing to an array is an
> undefined behavior (C11 6.5.6, constraint 8). Fix it by just casting the
> corresponding pointers using ACPI_CAST_PTR() and skip the arithmetic. Also,
> fix a checkpatch warning together.
>
> ERROR: Macros with complex values should be enclosed in parentheses
> Â#45: FILE: include/acpi/actypes.h:509:
> +#define ACPI_TO_POINTER(i)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂACPI_CAST_PTR (void, i)
>
> Signed-off-by: Qian Cai <cai@xxxxxx>
> ---
>
> v2: Use ACPI_CAST_PTR() in ACPI_TO_POINTER() directly without
> ÂÂÂÂarithmetic.
>
> Âinclude/acpi/actypes.h | 2 +-
> Â1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h index
> ad6892a24015..163181e2d884 100644
> --- a/include/acpi/actypes.h
> +++ b/include/acpi/actypes.h
> @@ -506,7 +506,7 @@ typedef u64 acpi_integer;
> Â
> Â/* Pointer/Integer type conversions */
> Â
> -#define ACPI_TO_POINTER(i)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂACPI_ADD_PTR (void, (void *) 0,
> (acpi_size) (i))
> +#define ACPI_TO_POINTER(i)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ(ACPI_CAST_PTR (void, 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_PHYSADDR_TO_PTR(i)ÂÂÂÂÂÂÂÂÂACPI_TO_POINTER(i)
> --
> 2.20.1 (Apple Git-117)
>