Skip to contentSkip to conversation

acpica: fix -Wnull-pointer-arithmetic warnings

PATCH In review Qian Cai 4 participants 7 messages Jul 18, 2019 – Aug 1, 2019

Subsystems (2)
lore
Share & tools
lore

Qian Cai

author
#0 lore raw

PATCH v2 1/1 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)

---

v2: Use ACPI_CAST_PTR() in ACPI_TO_POINTER() directly without
arithmetic.

 include/acpi/actypes.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/acpi/actypes.h +1 -1
index ad6892a24015..163181e2d884 100644
@@ -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)
Signature · 1 line
2.20.1 (Apple Git-117)
#1 lore raw

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

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

#2 lore raw

From: Moore, Robert

Quoted 1 line

Sent: 26 July 2019 20:36

...

Quoted 2 lines

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)

author
#3 lore raw
Quoted 9 lines · David Laight

From: Moore, Robert

Quoted 1 line

Sent: 26 July 2019 20:36

...

Quoted 2 lines

This is because pointer arithmetic
on a pointer not pointing to an array is an undefined behavior (C11 6.5.6, constraint 8).

Quoted 8 lines

...

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.

author
#4 lore raw
In reply to Moore, Robert
Quoted 1 line · Robert

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?

Quoted 70 lines

-----Original Message-----
From: Qian Cai [mailto:[email protected]]
Sent: Thursday, July 18, 2019 12:49 PM
To: Wysocki, Rafael J <[email protected]>
Cc: Moore, Robert <[email protected]>; Schmauss, Erik <erik.schmauss@inte l.com>; [email protected]; [email protected]; [email protected]; linux-acpi @vger.kernel.org; [email protected]; [email protected]; linux- [email protected]; Qian Cai <[email protected]>
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)

---

v2: Use ACPI_CAST_PTR() in ACPI_TO_POINTER() directly without arithmetic.

 include/acpi/actypes.h | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
include/acpi/actypes.h index renamed from include/acpi/actypes.h +0 -0

ad6892a24015..163181e2d884 100644

include/acpi/actypes.h +0 -0
@@ -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)

#5 lore raw
Quoted 16 lines

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

Quoted 1 line · Robert

We've taken the change to ACPI_TO_POINTER.

Quoted 7 lines

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

Quoted 81 lines
Quoted 14 lines

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

Quoted 4 lines

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]

Quoted 4 lines

status = acpi_get_handle(ACPI_ROOT_OBJECT,
obj->string.pointer,
                                         ^~~~~~~~~~~~~~~~ ./include/acpi/actypes.h:458:56: note: expanded from macro

'ACPI_ROOT_OBJECT'

Quoted 5 lines

 #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'

Quoted 10 lines

 #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'

Quoted 40 lines

 #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(a)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(-)
include/acpi/actypes.h index renamed from include/acpi/actypes.h +0 -0

ad6892a24015..163181e2d884 100644

include/acpi/actypes.h +1 -1
@@ -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)

#6 lore raw

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

Quoted 16 lines

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

Quoted 1 line · Robert

We've taken the change to ACPI_TO_POINTER.

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

Quoted 7 lines

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.

Quoted 85 lines

Erik

Quoted 13 lines

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

Quoted 5 lines

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]

Quoted 4 lines

status = acpi_get_handle(ACPI_ROOT_OBJECT,
obj->string.pointer,
                                         ^~~~~~~~~~~~~~~~ ./include/acpi/actypes.h:458:56: note: expanded from macro

'ACPI_ROOT_OBJECT'

Quoted 5 lines

 #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'

Quoted 10 lines

 #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'

Quoted 42 lines

 #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(a)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(-)
include/acpi/actypes.h index renamed from include/acpi/actypes.h +0 -0

ad6892a24015..163181e2d884 100644

include/acpi/actypes.h +1 -1
@@ -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)