drm/modes: Fix drm_mode_vrefres() docs
[drm/drm-misc.git] / io_uring / nop.c
blob5e5196df650a19e032e53594db6f1d1bea71c5f2
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/errno.h>
4 #include <linux/fs.h>
5 #include <linux/file.h>
6 #include <linux/io_uring.h>
8 #include <uapi/linux/io_uring.h>
10 #include "io_uring.h"
11 #include "rsrc.h"
12 #include "nop.h"
14 struct io_nop {
15 /* NOTE: kiocb has the file as the first member, so don't do it here */
16 struct file *file;
17 int result;
18 int fd;
19 int buffer;
20 unsigned int flags;
23 #define NOP_FLAGS (IORING_NOP_INJECT_RESULT | IORING_NOP_FIXED_FILE | \
24 IORING_NOP_FIXED_BUFFER | IORING_NOP_FILE)
26 int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
28 struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
30 nop->flags = READ_ONCE(sqe->nop_flags);
31 if (nop->flags & ~NOP_FLAGS)
32 return -EINVAL;
34 if (nop->flags & IORING_NOP_INJECT_RESULT)
35 nop->result = READ_ONCE(sqe->len);
36 else
37 nop->result = 0;
38 if (nop->flags & IORING_NOP_FILE)
39 nop->fd = READ_ONCE(sqe->fd);
40 else
41 nop->fd = -1;
42 if (nop->flags & IORING_NOP_FIXED_BUFFER)
43 nop->buffer = READ_ONCE(sqe->buf_index);
44 else
45 nop->buffer = -1;
46 return 0;
49 int io_nop(struct io_kiocb *req, unsigned int issue_flags)
51 struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
52 int ret = nop->result;
54 if (nop->flags & IORING_NOP_FILE) {
55 if (nop->flags & IORING_NOP_FIXED_FILE) {
56 req->file = io_file_get_fixed(req, nop->fd, issue_flags);
57 req->flags |= REQ_F_FIXED_FILE;
58 } else {
59 req->file = io_file_get_normal(req, nop->fd);
61 if (!req->file) {
62 ret = -EBADF;
63 goto done;
66 if (nop->flags & IORING_NOP_FIXED_BUFFER) {
67 struct io_ring_ctx *ctx = req->ctx;
68 struct io_rsrc_node *node;
70 ret = -EFAULT;
71 io_ring_submit_lock(ctx, issue_flags);
72 node = io_rsrc_node_lookup(&ctx->buf_table, nop->buffer);
73 if (node) {
74 io_req_assign_buf_node(req, node);
75 ret = 0;
77 io_ring_submit_unlock(ctx, issue_flags);
79 done:
80 if (ret < 0)
81 req_set_fail(req);
82 io_req_set_res(req, nop->result, 0);
83 return IOU_OK;