Skip to contentSkip to conversation

man: Fix syscall wrappers in example code

PATCH Applied Martin K. Petersen 2 participants 2 messages Apr 16, 2025 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 man: Fix syscall wrappers in example code

The example code in io_uring.7 provides two wrappers for the io_uring syscalls. However, the example fails to take into account that glibc's syscall(2) returns -1 and sets errno on failure. This means that any errors returned by the provided wrapper functions will be reported as -EPERM which could lead to incorrect error handling actions being taken.

Adjust the two example wrappers to match arch/generic/syscall.h. This makes them follow the documented io_uring calling convention which reports a call error as a negative return value.

man/io_uring.7 +7 -3
index 49cdc25290e7..b6c092b60201 100644
@@ -651,14 +651,18 @@ off_t offset;
 
 int io_uring_setup(unsigned entries, struct io_uring_params *p)
 {
-    return (int) syscall(__NR_io_uring_setup, entries, p);
+    int ret;
+    ret = syscall(__NR_io_uring_setup, entries, p);
+    return (ret < 0) ? -errno : ret;
 }
 
 int io_uring_enter(int ring_fd, unsigned int to_submit,
                    unsigned int min_complete, unsigned int flags)
 {
-    return (int) syscall(__NR_io_uring_enter, ring_fd, to_submit,
-    			 min_complete, flags, NULL, 0);
+    int ret;
+    ret = syscall(__NR_io_uring_enter, ring_fd, to_submit,
+                  min_complete, flags, NULL, 0);
+    return (ret < 0) ? -errno : ret;
 }
 
 int app_setup_uring(void) {
maintainer Applied
#1 lore raw
Quoted 8 lines · Martin K. Petersen

The example code in io_uring.7 provides two wrappers for the io_uring syscalls. However, the example fails to take into account that glibc's syscall(2) returns -1 and sets errno on failure. This means that any errors returned by the provided wrapper functions will be reported as -EPERM which could lead to incorrect error handling actions being taken.

[...]

Applied, thanks!

[1/1] man: Fix syscall wrappers in example code

      commit: 4c9be7fdbb83b9e2872721fb026befa052f65ded

Best regards,

Signature · 1 line
Jens Axboe