Skip to contentSkip to conversation

io_uring: convert cmd_to_io_kiocb() macro to function

PATCH Applied Caleb Sander Mateos 2 participants 2 messages Feb 28, 2025 – Mar 1, 2025 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring: convert cmd_to_io_kiocb() macro to function

The cmd_to_io_kiocb() macro applies a pointer cast to its input without parenthesizing it. Currently all inputs are variable names, so this has the intended effect. But since casts have relatively high precedence, the macro would apply the cast to the wrong value if the input was a pointer addition, for example.

Turn the macro into a static inline function to ensure the pointer cast is applied to the full input value.

---
 include/linux/io_uring_types.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/io_uring_types.h +5 -1
index 432c98ff52ee..72aac84dca93 100644
@@ -605,11 +605,15 @@ static inline void io_kiocb_cmd_sz_check(size_t cmd_sz)
 }
 #define io_kiocb_to_cmd(req, cmd_type) ( \
 	io_kiocb_cmd_sz_check(sizeof(cmd_type)) , \
 	((cmd_type *)&(req)->cmd) \
 )
-#define cmd_to_io_kiocb(ptr)	((struct io_kiocb *) ptr)
+
+static inline struct io_kiocb *cmd_to_io_kiocb(void *ptr)
+{
+	return ptr;
+}
 
 struct io_kiocb {
 	union {
 		/*
 		 * NOTE! Each of the io_kiocb union members has the file pointer
Signature · 1 line
2.45.2
maintainer Applied
#1 lore raw
Quoted 10 lines · Caleb Sander Mateos

The cmd_to_io_kiocb() macro applies a pointer cast to its input without parenthesizing it. Currently all inputs are variable names, so this has the intended effect. But since casts have relatively high precedence, the macro would apply the cast to the wrong value if the input was a pointer addition, for example.

Turn the macro into a static inline function to ensure the pointer cast is applied to the full input value.

[...]

Applied, thanks!

[1/1] io_uring: convert cmd_to_io_kiocb() macro to function

      commit: 09fdd35162c289f354326a55d552a8858f6e8072

Best regards,

Signature · 1 line
Jens Axboe