Skip to content

Commit

Permalink
ACPICA: Use uintptr_t and offsetof() in Linux kernel builds
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Rafael J. Wysocki committed Jan 25, 2022
1 parent e783362 commit ae57857
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/acpi/actypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,12 @@ typedef u64 acpi_integer;
/* Pointer/Integer type conversions */

#define ACPI_TO_POINTER(i) ACPI_CAST_PTR (void, (acpi_size) (i))
#ifndef ACPI_TO_INTEGER
#define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p, (void *) 0)
#endif
#ifndef ACPI_OFFSET
#define ACPI_OFFSET(d, f) ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) 0)
#endif
#define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i)

/* Optimizations for 4-character (32-bit) acpi_name manipulation */
Expand Down
5 changes: 5 additions & 0 deletions include/acpi/platform/aclinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
#define acpi_raw_spinlock raw_spinlock_t *
#define acpi_cpu_flags unsigned long

#define acpi_uintptr_t uintptr_t

#define ACPI_TO_INTEGER(p) ((uintptr_t)(p))
#define ACPI_OFFSET(d, f) offsetof(d, f)

/* Use native linux version of acpi_os_allocate_zeroed */

#define USE_NATIVE_ALLOCATE_ZEROED
Expand Down

0 comments on commit ae57857

Please sign in to comment.