Re: [PATCH] cb710: avoid NULL pointer subtraction

From
Michał Mirosław <mirq-linux@rere.qmqm.pl>
Date
2021-09-27 15:32:11
Also in
lkml
Reply to
Arnd Bergmann, 2021-09-27
On Mon, Sep 27, 2021 at 02:13:57PM +0200, Arnd Bergmann wrote:
quoted hunk ↗ jump to hunk
From: Arnd Bergmann <arnd@arndb.de>

clang-14 complains about an unusual way of converting a pointer to
an integer:

drivers/misc/cb710/sgbuf2.c:50:15: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction]
        return ((ptr - NULL) & 3) != 0;

Replace this with a normal cast to uintptr_t.

Fixes: 5f5bac8272be ("mmc: Driver for CB710/720 memory card reader (MMC part)")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/misc/cb710/sgbuf2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/misc/cb710/sgbuf2.c b/drivers/misc/cb710/sgbuf2.c
index e5a4ed3701eb..a798fad5f03c 100644
--- a/drivers/misc/cb710/sgbuf2.c
+++ b/drivers/misc/cb710/sgbuf2.c
@@ -47,7 +47,7 @@ static inline bool needs_unaligned_copy(const void *ptr)
 #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
 	return false;
 #else
-	return ((ptr - NULL) & 3) != 0;
+	return ((uintptr_t)ptr & 3) != 0;
 #endif
 }
 
Acked-by: Michał Mirosław <redacted>
Thread (2 messages) 2 messages, 2 authors, last reply 2021-09-27
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help