diff mbox series

[1/3] io_uring: propagate req cache creation errors

Message ID 8adc7ffcac05a8f1ae2c309ea1d0806b5b0c48b4.1738339723.git.asml.silence@gmail.com (mailing list archive)
State New
Headers show
Series check errors in early init | expand

Commit Message

Pavel Begunkov Jan. 31, 2025, 4:24 p.m. UTC
It's very unlikely, but in theory cache creation can fail during
initcall, so don't forget to return errors back if something goes wrong.

Fixes: 2b188cc1bb857 ("Add io_uring IO interface")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/io_uring.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Jens Axboe Jan. 31, 2025, 4:26 p.m. UTC | #1
On 1/31/25 9:24 AM, Pavel Begunkov wrote:
> It's very unlikely, but in theory cache creation can fail during
> initcall, so don't forget to return errors back if something goes wrong.

This is why SLAB_PANIC is used, it'll panic if this fails. That's
commonly used for setup/init time kind of setups, where we never
expect any failure to occur. Hence this can never return NULL.
Pavel Begunkov Jan. 31, 2025, 4:30 p.m. UTC | #2
On 1/31/25 16:26, Jens Axboe wrote:
> On 1/31/25 9:24 AM, Pavel Begunkov wrote:
>> It's very unlikely, but in theory cache creation can fail during
>> initcall, so don't forget to return errors back if something goes wrong.
> 
> This is why SLAB_PANIC is used, it'll panic if this fails. That's
> commonly used for setup/init time kind of setups, where we never
> expect any failure to occur. Hence this can never return NULL.

Yeah, missed it, thanks
diff mbox series

Patch

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 263e504be4a8b..9335144495299 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3916,6 +3916,9 @@  static int __init io_uring_init(void)
 	req_cachep = kmem_cache_create("io_kiocb", sizeof(struct io_kiocb), &kmem_args,
 				SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT |
 				SLAB_TYPESAFE_BY_RCU);
+	if (!req_cachep)
+		return -ENOMEM;
+
 	io_buf_cachep = KMEM_CACHE(io_buffer,
 					  SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);