Linux-ACPI Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings
@ 2019-07-18 19:48 Qian Cai
  2019-07-26 19:35 ` Moore, Robert
  0 siblings, 1 reply; 7+ messages in thread
From: Qian Cai @ 2019-07-18 19:48 UTC (permalink / raw)
  To: rafael.j.wysocki
  Cc: robert.moore, erik.schmauss, jkim, lenb, ndesaulniers,
	linux-acpi, devel, clang-built-linux, linux-kernel, Qian Cai

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@lca.pw>
---

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)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings
  2019-07-18 19:48 [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings Qian Cai
@ 2019-07-26 19:35 ` Moore, Robert
  2019-07-29 10:24   ` David Laight
  2019-08-01 19:16   ` Qian Cai
  0 siblings, 2 replies; 7+ messages in thread
From: Moore, Robert @ 2019-07-26 19:35 UTC (permalink / raw)
  To: Qian Cai, Wysocki, Rafael J
  Cc: Schmauss, Erik, jkim, lenb, ndesaulniers, linux-acpi, devel,
	clang-built-linux, linux-kernel

We've taken the change to ACPI_TO_POINTER.
Thanks,
Bob


-----Original Message-----
From: Qian Cai [mailto:cai@lca.pw] 
Sent: Thursday, July 18, 2019 12:49 PM
To: Wysocki, Rafael J <rafael.j.wysocki@intel.com>
Cc: Moore, Robert <robert.moore@intel.com>; Schmauss, Erik <erik.schmauss@intel.com>; jkim@FreeBSD.org; lenb@kernel.org; ndesaulniers@google.com; linux-acpi@vger.kernel.org; devel@acpica.org; clang-built-linux@googlegroups.com; linux-kernel@vger.kernel.org; Qian Cai <cai@lca.pw>
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@lca.pw>
---

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)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings
  2019-07-26 19:35 ` Moore, Robert
@ 2019-07-29 10:24   ` David Laight
  2019-07-29 12:23     ` Qian Cai
  2019-08-01 19:16   ` Qian Cai
  1 sibling, 1 reply; 7+ messages in thread
From: David Laight @ 2019-07-29 10:24 UTC (permalink / raw)
  To: Moore, Robert, Qian Cai, Wysocki, Rafael J
  Cc: Schmauss, Erik, jkim, lenb, ndesaulniers, linux-acpi, devel,
	clang-built-linux, linux-kernel

From: Moore, Robert
> Sent: 26 July 2019 20:36
...
> This is because pointer arithmetic
> on a pointer not pointing to an array is an undefined behavior (C11 6.5.6, constraint 8).
...

The standards committee as smoking dope again :-)
If that is enforced as a compiler warning/error a lot of code 'breaks'.
Anything that does:
	struct foo *foo = ...;
      struct bar *bar = (void *)(foo + 1);
suddenly becomes 'invalid'.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings
  2019-07-29 10:24   ` David Laight
@ 2019-07-29 12:23     ` Qian Cai
  0 siblings, 0 replies; 7+ messages in thread
From: Qian Cai @ 2019-07-29 12:23 UTC (permalink / raw)
  To: David Laight
  Cc: Moore, Robert, Wysocki, Rafael J, Schmauss, Erik, jkim, lenb,
	ndesaulniers, linux-acpi, devel, clang-built-linux, linux-kernel



> On Jul 29, 2019, at 6:24 AM, David Laight <David.Laight@ACULAB.COM> wrote:
> 
> From: Moore, Robert
>> Sent: 26 July 2019 20:36
> ...
>> This is because pointer arithmetic
>> on a pointer not pointing to an array is an undefined behavior (C11 6.5.6, constraint 8).
> ...
> 
> The standards committee as smoking dope again :-)
> If that is enforced as a compiler warning/error a lot of code 'breaks'.
> Anything that does:
> 	struct foo *foo = ...;
>      struct bar *bar = (void *)(foo + 1);
> suddenly becomes 'invalid’.

The clang will generate a warning only if “foo" is NULL.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings
  2019-07-26 19:35 ` Moore, Robert
  2019-07-29 10:24   ` David Laight
@ 2019-08-01 19:16   ` Qian Cai
  2019-08-01 20:17     ` Schmauss, Erik
  1 sibling, 1 reply; 7+ messages in thread
From: Qian Cai @ 2019-08-01 19:16 UTC (permalink / raw)
  To: Moore, Robert, Wysocki, Rafael J
  Cc: Schmauss, Erik, jkim, lenb, ndesaulniers, linux-acpi, devel,
	clang-built-linux, linux-kernel

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@lca.pw] 
> Sent: Thursday, July 18, 2019 12:49 PM
> To: Wysocki, Rafael J <rafael.j.wysocki@intel.com>
> Cc: Moore, Robert <robert.moore@intel.com>; Schmauss, Erik <erik.schmauss@inte
> l.com>; jkim@FreeBSD.org; lenb@kernel.org; ndesaulniers@google.com; linux-acpi
> @vger.kernel.org; devel@acpica.org; clang-built-linux@googlegroups.com; linux-
> kernel@vger.kernel.org; Qian Cai <cai@lca.pw>
> 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@lca.pw>
> ---
> 
> 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)
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings
  2019-08-01 19:16   ` Qian Cai
@ 2019-08-01 20:17     ` Schmauss, Erik
  2019-08-01 20:28       ` Moore, Robert
  0 siblings, 1 reply; 7+ messages in thread
From: Schmauss, Erik @ 2019-08-01 20:17 UTC (permalink / raw)
  To: Qian Cai, Moore, Robert, Wysocki, Rafael J
  Cc: jkim, lenb, ndesaulniers, linux-acpi, devel, clang-built-linux,
	linux-kernel



> -----Original Message-----
> From: Qian Cai [mailto:cai@lca.pw]
> Sent: Thursday, August 1, 2019 12:16 PM
> To: Moore, Robert <robert.moore@intel.com>; Wysocki, Rafael J
> <rafael.j.wysocki@intel.com>
> Cc: Schmauss, Erik <erik.schmauss@intel.com>; jkim@FreeBSD.org;
> lenb@kernel.org; ndesaulniers@google.com; linux-acpi@vger.kernel.org;
> devel@acpica.org; clang-built-linux@googlegroups.com; linux-
> kernel@vger.kernel.org
> Subject: Re: [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings
> 
> 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/02bbca5070e42d298c9b824300aa0
> eb8a082d797
> 
> but how does that change will go into the linux kernel? Suppose Rafael will
> need to pick it up manually?

I do that after every ACPICA release

Erik
> 
> >
> >
> > -----Original Message-----
> > From: Qian Cai [mailto:cai@lca.pw]
> > Sent: Thursday, July 18, 2019 12:49 PM
> > To: Wysocki, Rafael J <rafael.j.wysocki@intel.com>
> > Cc: Moore, Robert <robert.moore@intel.com>; Schmauss, Erik
> > <erik.schmauss@inte l.com>; jkim@FreeBSD.org; lenb@kernel.org;
> > ndesaulniers@google.com; linux-acpi @vger.kernel.org;
> > devel@acpica.org; clang-built-linux@googlegroups.com; linux-
> > kernel@vger.kernel.org; Qian Cai <cai@lca.pw>
> > 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@lca.pw>
> > ---
> >
> > 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)
> >

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings
  2019-08-01 20:17     ` Schmauss, Erik
@ 2019-08-01 20:28       ` Moore, Robert
  0 siblings, 0 replies; 7+ messages in thread
From: Moore, Robert @ 2019-08-01 20:28 UTC (permalink / raw)
  To: Schmauss, Erik, Qian Cai, Wysocki, Rafael J
  Cc: jkim, lenb, ndesaulniers, linux-acpi, devel, clang-built-linux,
	linux-kernel



-----Original Message-----
From: Schmauss, Erik 
Sent: Thursday, August 01, 2019 1:18 PM
To: Qian Cai <cai@lca.pw>; Moore, Robert <robert.moore@intel.com>; Wysocki, Rafael J <rafael.j.wysocki@intel.com>
Cc: jkim@FreeBSD.org; lenb@kernel.org; ndesaulniers@google.com; linux-acpi@vger.kernel.org; devel@acpica.org; clang-built-linux@googlegroups.com; linux-kernel@vger.kernel.org
Subject: RE: [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings



> -----Original Message-----
> From: Qian Cai [mailto:cai@lca.pw]
> Sent: Thursday, August 1, 2019 12:16 PM
> To: Moore, Robert <robert.moore@intel.com>; Wysocki, Rafael J 
> <rafael.j.wysocki@intel.com>
> Cc: Schmauss, Erik <erik.schmauss@intel.com>; jkim@FreeBSD.org; 
> lenb@kernel.org; ndesaulniers@google.com; linux-acpi@vger.kernel.org; 
> devel@acpica.org; clang-built-linux@googlegroups.com; linux- 
> kernel@vger.kernel.org
> Subject: Re: [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings
> 
> 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/02bbca5070e42d298c9b824300aa0
> eb8a082d797
> 
> but how does that change will go into the linux kernel? Suppose Rafael 
> will need to pick it up manually?

>I do that after every ACPICA release

Which happens about once per month.

>Erik
> 
> >
> >
> > -----Original Message-----
> > From: Qian Cai [mailto:cai@lca.pw]
> > Sent: Thursday, July 18, 2019 12:49 PM
> > To: Wysocki, Rafael J <rafael.j.wysocki@intel.com>
> > Cc: Moore, Robert <robert.moore@intel.com>; Schmauss, Erik 
> > <erik.schmauss@inte l.com>; jkim@FreeBSD.org; lenb@kernel.org; 
> > ndesaulniers@google.com; linux-acpi @vger.kernel.org; 
> > devel@acpica.org; clang-built-linux@googlegroups.com; linux- 
> > kernel@vger.kernel.org; Qian Cai <cai@lca.pw>
> > 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@lca.pw>
> > ---
> >
> > 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)
> >

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-18 19:48 [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings Qian Cai
2019-07-26 19:35 ` Moore, Robert
2019-07-29 10:24   ` David Laight
2019-07-29 12:23     ` Qian Cai
2019-08-01 19:16   ` Qian Cai
2019-08-01 20:17     ` Schmauss, Erik
2019-08-01 20:28       ` Moore, Robert

Linux-ACPI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-acpi/0 linux-acpi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-acpi linux-acpi/ https://lore.kernel.org/linux-acpi \
		linux-acpi@vger.kernel.org linux-acpi@archiver.kernel.org
	public-inbox-index linux-acpi


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-acpi


AGPL code for this site: git clone https://public-inbox.org/ public-inbox