Skip to contentSkip to conversation

cb710: avoid NULL pointer subtraction

PATCH In review Arnd Bergmann 2 participants 2 messages Sep 27, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cb710: avoid NULL pointer subtraction

From: Arnd Bergmann <[email protected]>

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)")
---
 drivers/misc/cb710/sgbuf2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/cb710/sgbuf2.c +1 -1
index e5a4ed3701eb..a798fad5f03c 100644
@@ -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
 }
 
Signature · 1 line
2.29.2
maintainer Acked-by Michał Mirosław on v1 1/1
#1 lore raw
Quoted 21 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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)")
---
 drivers/misc/cb710/sgbuf2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/cb710/sgbuf2.c +0 -0
index e5a4ed3701eb..a798fad5f03c 100644

drivers/misc/cb710/sgbuf2.c static inline bool needs_unaligned_copy(const void *ptr) · line 53

Quoted 8 lines
drivers/misc/cb710/sgbuf2.c +1 -1
@@ -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
 }