Skip to content

Commit ae57857

Browse files
committed
ACPICA: Use uintptr_t and offsetof() in Linux kernel builds
To avoid "performing pointer subtraction with a null pointer has undefined behavior" compiler warnings, use uintptr_t and offsetof() that are always available during Linux kernel builds to define acpi_uintptr_t and the ACPI_TO_INTEGER() and ACPI_OFFSET() macros. Based on earlier proposal from Arnd Bergmann. Link: https://lore.kernel.org/linux-acpi/20210927121338.938994-1-arnd@kernel.org Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
1 parent e783362 commit ae57857

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

include/acpi/actypes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,12 @@ typedef u64 acpi_integer;
507507
/* Pointer/Integer type conversions */
508508

509509
#define ACPI_TO_POINTER(i) ACPI_CAST_PTR (void, (acpi_size) (i))
510+
#ifndef ACPI_TO_INTEGER
510511
#define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p, (void *) 0)
512+
#endif
513+
#ifndef ACPI_OFFSET
511514
#define ACPI_OFFSET(d, f) ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) 0)
515+
#endif
512516
#define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i)
513517

514518
/* Optimizations for 4-character (32-bit) acpi_name manipulation */

include/acpi/platform/aclinux.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@
114114
#define acpi_raw_spinlock raw_spinlock_t *
115115
#define acpi_cpu_flags unsigned long
116116

117+
#define acpi_uintptr_t uintptr_t
118+
119+
#define ACPI_TO_INTEGER(p) ((uintptr_t)(p))
120+
#define ACPI_OFFSET(d, f) offsetof(d, f)
121+
117122
/* Use native linux version of acpi_os_allocate_zeroed */
118123

119124
#define USE_NATIVE_ALLOCATE_ZEROED

0 commit comments

Comments
 (0)