Skip to content

Commit 2b4fc4c

Browse files
committed
io_uring/waitid: setup async data in the prep handler
This is the idiomatic way that opcodes should setup their async data, so that it's always valid inside ->issue() without issue needing to do that. Fixes: f31ecf6 ("io_uring: add IORING_OP_WAITID support") Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 0edf128 commit 2b4fc4c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

io_uring/waitid.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,16 @@ static int io_waitid_wait(struct wait_queue_entry *wait, unsigned mode,
285285
int io_waitid_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
286286
{
287287
struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid);
288+
struct io_waitid_async *iwa;
288289

289290
if (sqe->addr || sqe->buf_index || sqe->addr3 || sqe->waitid_flags)
290291
return -EINVAL;
291292

293+
iwa = io_uring_alloc_async_data(NULL, req);
294+
if (!unlikely(iwa))
295+
return -ENOMEM;
296+
iwa->req = req;
297+
292298
iw->which = READ_ONCE(sqe->len);
293299
iw->upid = READ_ONCE(sqe->fd);
294300
iw->options = READ_ONCE(sqe->file_index);
@@ -299,16 +305,10 @@ int io_waitid_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
299305
int io_waitid(struct io_kiocb *req, unsigned int issue_flags)
300306
{
301307
struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid);
308+
struct io_waitid_async *iwa = req->async_data;
302309
struct io_ring_ctx *ctx = req->ctx;
303-
struct io_waitid_async *iwa;
304310
int ret;
305311

306-
iwa = io_uring_alloc_async_data(NULL, req);
307-
if (!iwa)
308-
return -ENOMEM;
309-
310-
iwa->req = req;
311-
312312
ret = kernel_waitid_prepare(&iwa->wo, iw->which, iw->upid, &iw->info,
313313
iw->options, NULL);
314314
if (ret)

0 commit comments

Comments
 (0)