git: 461cfd4192d2 - stable/12 - Fix acpica macros that subtract null pointers
Dimitry Andric
dim at FreeBSD.org
Thu Sep 2 23:58:59 UTC 2021
The branch stable/12 has been updated by dim:
URL: https://cgit.FreeBSD.org/src/commit/?id=461cfd4192d2b7735b6cee0f42e6a7818f8f50b4
commit 461cfd4192d2b7735b6cee0f42e6a7818f8f50b4
Author: Dimitry Andric <dim at FreeBSD.org>
AuthorDate: 2021-08-29 11:15:23 +0000
Commit: Dimitry Andric <dim at FreeBSD.org>
CommitDate: 2021-09-02 23:30:22 +0000
Fix acpica macros that subtract null pointers
Clang 13.0.0 produces a new -Werror warning about the ACPI_TO_INTEGER(p)
and ACPI_OFFSET(d, f) macros in acpica's actypes.h:
sys/contrib/dev/acpica/components/dispatcher/dsopcode.c:708:31: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction]
ObjDesc->Region.Address = ACPI_PTR_TO_PHYSADDR (Table);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sys/contrib/dev/acpica/include/actypes.h:664:41: note: expanded from macro 'ACPI_PTR_TO_PHYSADDR'
#define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i)
^~~~~~~~~~~~~~~~~~
sys/contrib/dev/acpica/include/actypes.h:661:41: note: expanded from macro 'ACPI_TO_INTEGER'
#define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p, (void *) 0)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sys/contrib/dev/acpica/include/actypes.h:656:82: note: expanded from macro 'ACPI_PTR_DIFF'
#define ACPI_PTR_DIFF(a, b) ((ACPI_SIZE) (ACPI_CAST_PTR (UINT8, (a)) - ACPI_CAST_PTR (UINT8, (b))))
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
This problem of undefined behavior was also reported to acpica by @cem
in 2018: https://github.com/acpica/acpica/issues/407, but it seems there
was never any fix committed for it upstream.
Instead fix these locally, for ACPI_TO_INTEGER by simply casting the
incoming pointer to ACPI_SIZE (which corresponds roughly to uintptr_t
and size_t), and for ACPI_OFFSET by reusing our __offsetof definition
from sys/cdefs.h.
Reviewed by: emaste, kib, imp
Differential Revision: https://reviews.freebsd.org/D31710
(cherry picked from commit 130a690ae16e1b845629e586203b508eff699f38)
---
sys/contrib/dev/acpica/include/actypes.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/sys/contrib/dev/acpica/include/actypes.h b/sys/contrib/dev/acpica/include/actypes.h
index c7d2c9aa69e4..f7bb0d4d0170 100644
--- a/sys/contrib/dev/acpica/include/actypes.h
+++ b/sys/contrib/dev/acpica/include/actypes.h
@@ -658,8 +658,13 @@ typedef UINT64 ACPI_INTEGER;
/* Pointer/Integer type conversions */
#define ACPI_TO_POINTER(i) ACPI_CAST_PTR (void, (ACPI_SIZE) (i))
+#ifdef __FreeBSD__
+#define ACPI_TO_INTEGER(p) ((ACPI_SIZE) (p))
+#define ACPI_OFFSET(d, f) ((ACPI_SIZE) __offsetof(d, f))
+#else
#define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p, (void *) 0)
#define ACPI_OFFSET(d, f) ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) 0)
+#endif
#define ACPI_PHYSADDR_TO_PTR(i) ACPI_TO_POINTER(i)
#define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i)
More information about the dev-commits-src-all
mailing list