From: Qian Cai <cai@lca.pw>
To: rafael.j.wysocki@intel.com
Cc: robert.moore@intel.com, 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
Date: Thu, 18 Jul 2019 15:48:46 -0400 [thread overview]
Message-ID: <20190718194846.1880-1-cai@lca.pw> (raw)
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)
next reply other threads:[~2019-07-18 19:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-18 19:48 Qian Cai [this message]
2019-07-26 19:35 ` [PATCH v2] acpica: fix -Wnull-pointer-arithmetic warnings 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190718194846.1880-1-cai@lca.pw \
--to=cai@lca.pw \
--cc=clang-built-linux@googlegroups.com \
--cc=devel@acpica.org \
--cc=erik.schmauss@intel.com \
--cc=jkim@FreeBSD.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ndesaulniers@google.com \
--cc=rafael.j.wysocki@intel.com \
--cc=robert.moore@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).