* [PATCH] man: Fix syscall wrappers in example code
@ 2025-04-16 20:08 Martin K. Petersen
2025-04-16 20:11 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Martin K. Petersen @ 2025-04-16 20:08 UTC (permalink / raw)
To: io-uring
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.
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
diff --git a/man/io_uring.7 b/man/io_uring.7
index 49cdc25290e7..b6c092b60201 100644
--- a/man/io_uring.7
+++ b/man/io_uring.7
@@ -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) {
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] man: Fix syscall wrappers in example code
2025-04-16 20:08 [PATCH] man: Fix syscall wrappers in example code Martin K. Petersen
@ 2025-04-16 20:11 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2025-04-16 20:11 UTC (permalink / raw)
To: io-uring, Martin K. Petersen
On Wed, 16 Apr 2025 16:08:53 -0400, Martin K. Petersen wrote:
> 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,
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-16 20:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16 20:08 [PATCH] man: Fix syscall wrappers in example code Martin K. Petersen
2025-04-16 20:11 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox