Skip to contentSkip to conversation

hexagon: fix using plain integer as NULL pointer warning in cmpxchg

PATCH In review Willem de Bruijn 4 participants 4 messages Dec 3, 2024 – Jan 27, 2025 Qualcomm hexagon architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hexagon: fix using plain integer as NULL pointer warning in cmpxchg

From: Willem de Bruijn <[email protected]>

Sparse reports

net/ipv4/inet_diag.c:1511:17: sparse: sparse: Using plain integer as NULL pointer

Due to this code calling cmpxchg on a non-integer type struct inet_diag_handler *

return !cmpxchg((const struct inet_diag_handler**)&inet_diag_table[type],
NULL, h) ? 0 : -EEXIST;

While hexagon's cmpxchg assigns an integer value to a variable of this type.

    __typeof__(*(ptr)) __oldval = 0;

Update this assignment to cast 0 to the correct type.

The original issue is easily reproduced at head with the below block, and is absent after this change.

make LLVM=1 ARCH=hexagon defconfig
make C=1 LLVM=1 ARCH=hexagon net/ipv4/inet_diag.o

Fixes 99a70aa051d2 ("Hexagon: Add processor and system headers")
---
 arch/hexagon/include/asm/cmpxchg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/hexagon/include/asm/cmpxchg.h +1 -1
index bf6cf5579cf4..9c58fb81f7fd 100644
@@ -56,7 +56,7 @@ __arch_xchg(unsigned long x, volatile void *ptr, int size)
 	__typeof__(ptr) __ptr = (ptr);				\
 	__typeof__(*(ptr)) __old = (old);			\
 	__typeof__(*(ptr)) __new = (new);			\
-	__typeof__(*(ptr)) __oldval = 0;			\
+	__typeof__(*(ptr)) __oldval = (__typeof__(*(ptr))) 0;	\
 								\
 	asm volatile(						\
 		"1:	%0 = memw_locked(%1);\n"		\
Signature · 1 line
2.47.0.338.g60cca15819-goog
Tested-by on v1 1/1
#1 lore raw

Hi Willem,

Quoted 23 lines

From: Willem de Bruijn <[email protected]>

Sparse reports

net/ipv4/inet_diag.c:1511:17: sparse: sparse: Using plain integer as NULL pointer

Due to this code calling cmpxchg on a non-integer type struct inet_diag_handler *

return !cmpxchg((const struct inet_diag_handler**)&inet_diag_table[type],
NULL, h) ? 0 : -EEXIST;

While hexagon's cmpxchg assigns an integer value to a variable of this type.

    __typeof__(*(ptr)) __oldval = 0;

Update this assignment to cast 0 to the correct type.

The original issue is easily reproduced at head with the below block, and is absent after this change.

Quoted 7 lines

make LLVM=1 ARCH=hexagon defconfig
make C=1 LLVM=1 ARCH=hexagon net/ipv4/inet_diag.o

Fixes 99a70aa051d2 ("Hexagon: Add processor and system headers")
Quoted 21 lines
---
 arch/hexagon/include/asm/cmpxchg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/hexagon/include/asm/cmpxchg.h +1 -2
index bf6cf5579cf4..9c58fb81f7fd 100644
@@ -56,7 +56,7 @@ __arch_xchg(unsigned long x, volatile void *ptr, int size)
        __typeof__(ptr) __ptr = (ptr);                          \
        __typeof__(*(ptr)) __old = (old);                       \
        __typeof__(*(ptr)) __new = (new);                       \
-       __typeof__(*(ptr)) __oldval = 0;                        \
+       __typeof__(*(ptr)) __oldval = (__typeof__(*(ptr))) 0;   \
                                                                \
        asm volatile(                                           \
                "1:     %0 = memw_locked(%1);\n"                \
--

2.47.0.338.g60cca15819-goog

Signature · 5 lines
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info/privacypolicy
#2 lore raw

Hi Brian,

Do you have an estimate for when this patch will be picked? We are getting build reports from Hexagon in the V3D GPU driver [1].

[1] https://lore.kernel.org/oe-kbuild-all/[email protected]/

Best Regards,
- Maíra

Quoted 59 lines · Christian Gmeiner

Hi Willem,

Quoted 23 lines

From: Willem de Bruijn <[email protected]>

Sparse reports

net/ipv4/inet_diag.c:1511:17: sparse: sparse: Using plain integer as NULL pointer

Due to this code calling cmpxchg on a non-integer type struct inet_diag_handler *

return !cmpxchg((const struct inet_diag_handler**)&inet_diag_table[type],
NULL, h) ? 0 : -EEXIST;

While hexagon's cmpxchg assigns an integer value to a variable of this type.

     __typeof__(*(ptr)) __oldval = 0;

Update this assignment to cast 0 to the correct type.

The original issue is easily reproduced at head with the below block, and is absent after this change.

Quoted 7 lines

make LLVM=1 ARCH=hexagon defconfig
make C=1 LLVM=1 ARCH=hexagon net/ipv4/inet_diag.o

Fixes 99a70aa051d2 ("Hexagon: Add processor and system headers")
Quoted 21 lines
---
  arch/hexagon/include/asm/cmpxchg.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/hexagon/include/asm/cmpxchg.h +1 -2
index bf6cf5579cf4..9c58fb81f7fd 100644
@@ -56,7 +56,7 @@ __arch_xchg(unsigned long x, volatile void *ptr, int size)
         __typeof__(ptr) __ptr = (ptr);                          \
         __typeof__(*(ptr)) __old = (old);                       \
         __typeof__(*(ptr)) __new = (new);                       \
-       __typeof__(*(ptr)) __oldval = 0;                        \
+       __typeof__(*(ptr)) __oldval = (__typeof__(*(ptr))) 0;   \
                                                                 \
         asm volatile(                                           \
                 "1:     %0 = memw_locked(%1);\n"                \
--

2.47.0.338.g60cca15819-goog

#3 lore raw
Quoted 14 lines

-----Original Message-----
From: Maíra Canal <[email protected]>
Sent: Sunday, January 26, 2025 4:59 PM
To: Christian Gmeiner <[email protected]>; Willem de Bruijn <[email protected]>
Cc: [email protected]; Brian Cain <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Willem de Bruijn <[email protected]>; kernel test robot <[email protected]>; [email protected]
Subject: Re: [PATCH] hexagon: fix using plain integer as NULL pointer warning in cmpxchg

Quoted 7 lines

WARNING: This email originated from outside of Qualcomm. Please be wary of any links or attachments, and do not enable macros.

Hi Brian,

Do you have an estimate for when this patch will be picked? We are getting build reports from Hexagon in the V3D GPU driver [1].

Sorry for the delay. I will work on it this week, Maíra.

Quoted 72 lines

[1]
https://lore.kernel.org/oe-kbuild-all/[email protected]/

Best Regards,
- Maíra

Quoted 8 lines · Christian Gmeiner

Hi Willem,

Quoted 6 lines

From: Willem de Bruijn <[email protected]>

Sparse reports

net/ipv4/inet_diag.c:1511:17: sparse: sparse: Using plain integer as NULL

pointer

Quoted 5 lines
Quoted 5 lines

Due to this code calling cmpxchg on a non-integer type struct inet_diag_handler *

return !cmpxchg((const struct

inet_diag_handler**)&inet_diag_table[type],

Quoted 12 lines
Quoted 12 lines
                     NULL, h) ? 0 : -EEXIST;

While hexagon's cmpxchg assigns an integer value to a variable of this type.

     __typeof__(*(ptr)) __oldval = 0;

Update this assignment to cast 0 to the correct type.

The original issue is easily reproduced at head with the below block, and is absent after this change.

Quoted 6 lines
Quoted 6 lines

make LLVM=1 ARCH=hexagon defconfig
make C=1 LLVM=1 ARCH=hexagon net/ipv4/inet_diag.o

Fixes 99a70aa051d2 ("Hexagon: Add processor and system headers")

[email protected]/

Quoted 3 lines
Quoted 1 line

[email protected]/

Quoted 7 lines

Review

Quoted 5 lines
---
  arch/hexagon/include/asm/cmpxchg.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

b/arch/hexagon/include/asm/cmpxchg.h

Quoted 4 lines

arch/hexagon/include/asm/cmpxchg.h __arch_xchg(unsigned long x, volatile void *ptr, int

Quoted 4 lines

index bf6cf5579cf4..9c58fb81f7fd 100644

arch/hexagon/include/asm/cmpxchg.h +0 -0
@@ -56,7 +56,7 @@ __arch_xchg(unsigned long x, volatile void *ptr, int

size)

Quoted 14 lines
Quoted 12 lines
arch/hexagon/include/asm/cmpxchg.h +1 -2
         __typeof__(ptr) __ptr = (ptr);                          \
         __typeof__(*(ptr)) __old = (old);                       \
         __typeof__(*(ptr)) __new = (new);                       \
-       __typeof__(*(ptr)) __oldval = 0;                        \
+       __typeof__(*(ptr)) __oldval = (__typeof__(*(ptr))) 0;   \
                                                                 \
         asm volatile(                                           \
                 "1:     %0 = memw_locked(%1);\n"                \
--

2.47.0.338.g60cca15819-goog