Skip to content

Commit ef623a6

Browse files
krismanaxboe
authored andcommitted
io_uring: Move old async data allocation helper to header
There are two remaining uses of the old async data allocator that do not rely on the alloc cache. I don't want to make them use the new allocator helper because that would require a if(cache) check, which will result in dead code for the cached case (for callers passing a cache, gcc can't prove the cache isn't NULL, and will therefore preserve the check. Since this is an inline function and just a few lines long, keep a second helper to deal with cases where we don't have an async data cache. No functional change intended here. This is just moving the helper around and making it inline. Signed-off-by: Gabriel Krisman Bertazi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent d7f1161 commit ef623a6

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

io_uring/io_uring.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,19 +1643,6 @@ io_req_flags_t io_file_get_flags(struct file *file)
16431643
return res;
16441644
}
16451645

1646-
bool io_alloc_async_data(struct io_kiocb *req)
1647-
{
1648-
const struct io_issue_def *def = &io_issue_defs[req->opcode];
1649-
1650-
WARN_ON_ONCE(!def->async_size);
1651-
req->async_data = kmalloc(def->async_size, GFP_KERNEL);
1652-
if (req->async_data) {
1653-
req->flags |= REQ_F_ASYNC_DATA;
1654-
return false;
1655-
}
1656-
return true;
1657-
}
1658-
16591646
static u32 io_get_sequence(struct io_kiocb *req)
16601647
{
16611648
u32 seq = req->ctx->cached_sq_head;

io_uring/io_uring.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "io-wq.h"
1313
#include "slist.h"
1414
#include "filetable.h"
15+
#include "opdef.h"
1516

1617
#ifndef CREATE_TRACE_POINTS
1718
#include <trace/events/io_uring.h>
@@ -233,6 +234,17 @@ static inline void *io_uring_alloc_async_data(struct io_alloc_cache *cache,
233234
return req->async_data;
234235
}
235236

237+
static inline void *io_uring_alloc_async_data_nocache(struct io_kiocb *req)
238+
{
239+
const struct io_issue_def *def = &io_issue_defs[req->opcode];
240+
241+
WARN_ON_ONCE(!def->async_size);
242+
req->async_data = kmalloc(def->async_size, GFP_KERNEL);
243+
if (req->async_data)
244+
req->flags |= REQ_F_ASYNC_DATA;
245+
return req->async_data;
246+
}
247+
236248
static inline bool req_has_async_data(struct io_kiocb *req)
237249
{
238250
return req->flags & REQ_F_ASYNC_DATA;

io_uring/timeout.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,9 @@ static int __io_timeout_prep(struct io_kiocb *req,
525525

526526
if (WARN_ON_ONCE(req_has_async_data(req)))
527527
return -EFAULT;
528-
if (io_alloc_async_data(req))
528+
data = io_uring_alloc_async_data_nocache(req);
529+
if (!data)
529530
return -ENOMEM;
530-
531-
data = req->async_data;
532531
data->req = req;
533532
data->flags = flags;
534533

io_uring/waitid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ int io_waitid(struct io_kiocb *req, unsigned int issue_flags)
303303
struct io_waitid_async *iwa;
304304
int ret;
305305

306-
if (io_alloc_async_data(req))
306+
iwa = io_uring_alloc_async_data_nocache(req);
307+
if (!iwa)
307308
return -ENOMEM;
308309

309-
iwa = req->async_data;
310310
iwa->req = req;
311311

312312
ret = kernel_waitid_prepare(&iwa->wo, iw->which, iw->upid, &iw->info,

0 commit comments

Comments
 (0)