Skip to contentSkip to conversation

selftests/io_uring: cast optval through uintptr_t in mini_liburing.h

PATCH Superseded Sasha Levin 2 participants 2 messages Nov 3 – Nov 4

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/io_uring: cast optval through uintptr_t in mini_liburing.h

io_uring_prep_cmd() puts the optval pointer into the 64-bit optval field of the SQE with a plain cast, which warns on 32-bit architectures:

mini_liburing.h:272:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]

Cast through uintptr_t.

---
Found with 32-bit builds of the selftests (gcc 16 and clang 21 with -m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without them now, and the x86_64 builds don't change.

 tools/include/io_uring/mini_liburing.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/include/io_uring/mini_liburing.h +1 -1
index 44be4446feda5..1f5b0cfc1e5b6 100644
@@ -269,7 +269,7 @@ static inline void io_uring_prep_cmd(struct io_uring_sqe *sqe, int op,
 
 	sqe->level = level;
 	sqe->optname = optname;
-	sqe->optval = (unsigned long long)optval;
+	sqe->optval = (unsigned long long)(uintptr_t)optval;
 	sqe->optlen = optlen;
 }
 
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Sasha Levin

io_uring_prep_cmd() puts the optval pointer into the 64-bit optval field of the SQE with a plain cast, which warns on 32-bit architectures:

mini_liburing.h:272:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]

Cast through uintptr_t.

Thanks for the fix.
I see the same warning with gcc -m32, and it is gone with this patch.

Quoted 1 line
Quoted 14 lines

---
Found with 32-bit builds of the selftests (gcc 16 and clang 21 with -m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without them now, and the x86_64 builds don't change.

 tools/include/io_uring/mini_liburing.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/include/io_uring/mini_liburing.h +0 -0
index 44be4446feda5..1f5b0cfc1e5b6 100644

tools/include/io_uring/mini_liburing.h static inline void io_uring_prep_cmd(struct io_uring_sqe *sqe, int op, · line 272

Quoted 5 lines
tools/include/io_uring/mini_liburing.h +1 -1
@@ -269,7 +269,7 @@ static inline void io_uring_prep_cmd(struct io_uring_sqe *sqe, int op,
 
 	sqe->level = level;
 	sqe->optname = optname;
-	sqe->optval = (unsigned long long)optval;
+	sqe->optval = (unsigned long long)(uintptr_t)optval;

mini_liburing.h doesn't include <stdint.h>, so uintptr_t only resolves because both users include it first: io_uring_zerocopy_tx.c directly, and prog_tests/sockopt.c through bpf/bpf.h and bpf/libbpf.h from test_progs.h.

Since this adds the first uintptr_t in the file, should it also add #include <stdint.h> next to the other includes?