static void io_wq_submit_work(struct io_wq_work **workptr);
static void io_cqring_fill_event(struct io_kiocb *req, long res);
static void __io_free_req(struct io_kiocb *req);
-static void io_put_req(struct io_kiocb *req, struct io_kiocb **nxtptr);
+static void io_put_req(struct io_kiocb *req);
static void io_double_put_req(struct io_kiocb *req);
static struct kmem_cache *req_cachep;
atomic_inc(&req->ctx->cq_timeouts);
list_del_init(&req->list);
io_cqring_fill_event(req, 0);
- io_put_req(req, NULL);
+ io_put_req(req);
}
}
while (!list_empty(&list)) {
req = list_first_entry(&list, struct io_kiocb, list);
list_del(&req->list);
- io_put_req(req, NULL);
+ io_put_req(req);
}
}
io_cqring_fill_event(req, -ECANCELED);
io_commit_cqring(ctx);
req->flags &= ~REQ_F_LINK;
- io_put_req(req, NULL);
+ io_put_req(req);
return true;
}
* Drop reference to request, return next in chain (if there is one) if this
* was the last reference to this request.
*/
-static struct io_kiocb *io_put_req_find_next(struct io_kiocb *req)
+static void io_put_req_find_next(struct io_kiocb *req, struct io_kiocb **nxtptr)
{
struct io_kiocb *nxt = NULL;
if (refcount_dec_and_test(&req->refs))
io_free_req(req, &nxt);
- return nxt;
-}
-
-static void io_put_req(struct io_kiocb *req, struct io_kiocb **nxtptr)
-{
- struct io_kiocb *nxt;
-
- nxt = io_put_req_find_next(req);
if (nxt) {
if (nxtptr)
*nxtptr = nxt;
}
}
+static void io_put_req(struct io_kiocb *req)
+{
+ if (refcount_dec_and_test(&req->refs))
+ io_free_req(req, NULL);
+}
+
static void io_double_put_req(struct io_kiocb *req)
{
/* drop both submit and complete references */
struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw);
io_complete_rw_common(kiocb, res);
- io_put_req(req, NULL);
+ io_put_req(req);
}
static struct io_kiocb *__io_complete_rw(struct kiocb *kiocb, long res)
{
struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw);
+ struct io_kiocb *nxt = NULL;
io_complete_rw_common(kiocb, res);
- return io_put_req_find_next(req);
+ io_put_req_find_next(req, &nxt);
+
+ return nxt;
}
static void io_complete_rw_iopoll(struct kiocb *kiocb, long res, long res2)
return -EINVAL;
io_cqring_add_event(req, 0);
- io_put_req(req, NULL);
+ io_put_req(req);
return 0;
}
if (ret < 0 && (req->flags & REQ_F_LINK))
req->flags |= REQ_F_FAIL_LINK;
io_cqring_add_event(req, ret);
- io_put_req(req, nxt);
+ io_put_req_find_next(req, nxt);
return 0;
}
if (ret < 0 && (req->flags & REQ_F_LINK))
req->flags |= REQ_F_FAIL_LINK;
io_cqring_add_event(req, ret);
- io_put_req(req, nxt);
+ io_put_req_find_next(req, nxt);
return 0;
}
io_cqring_add_event(req, ret);
if (ret < 0 && (req->flags & REQ_F_LINK))
req->flags |= REQ_F_FAIL_LINK;
- io_put_req(req, nxt);
+ io_put_req_find_next(req, nxt);
return 0;
}
#endif
if (ret < 0 && (req->flags & REQ_F_LINK))
req->flags |= REQ_F_FAIL_LINK;
io_cqring_add_event(req, ret);
- io_put_req(req, nxt);
+ io_put_req_find_next(req, nxt);
return 0;
#else
return -EOPNOTSUPP;
io_cqring_add_event(req, ret);
if (ret < 0 && (req->flags & REQ_F_LINK))
req->flags |= REQ_F_FAIL_LINK;
- io_put_req(req, NULL);
+ io_put_req(req);
return 0;
}
io_cqring_ev_posted(ctx);
- io_put_req(req, &nxt);
+ io_put_req_find_next(req, &nxt);
if (nxt)
*workptr = &nxt->work;
}
spin_unlock_irqrestore(&ctx->completion_lock, flags);
io_cqring_ev_posted(ctx);
- io_put_req(req, NULL);
+ io_put_req(req);
} else {
io_queue_async_work(req);
}
if (mask) {
io_cqring_ev_posted(ctx);
- io_put_req(req, nxt);
+ io_put_req_find_next(req, nxt);
}
return ipt.error;
}
io_cqring_ev_posted(ctx);
if (req->flags & REQ_F_LINK)
req->flags |= REQ_F_FAIL_LINK;
- io_put_req(req, NULL);
+ io_put_req(req);
return HRTIMER_NORESTART;
}
io_cqring_ev_posted(ctx);
if (req->flags & REQ_F_LINK)
req->flags |= REQ_F_FAIL_LINK;
- io_put_req(req, NULL);
+ io_put_req(req);
return 0;
}
spin_unlock_irq(&ctx->completion_lock);
io_cqring_ev_posted(ctx);
- io_put_req(treq, NULL);
- io_put_req(req, NULL);
+ io_put_req(treq);
+ io_put_req(req);
return 0;
}
if (ret < 0 && (req->flags & REQ_F_LINK))
req->flags |= REQ_F_FAIL_LINK;
io_cqring_add_event(req, ret);
- io_put_req(req, nxt);
+ io_put_req_find_next(req, nxt);
return 0;
}
}
/* drop submission reference */
- io_put_req(req, NULL);
+ io_put_req(req);
if (ret) {
if (req->flags & REQ_F_LINK)
req->flags |= REQ_F_FAIL_LINK;
io_cqring_add_event(req, ret);
- io_put_req(req, NULL);
+ io_put_req(req);
}
/* async context always use a copy of the sqe */
}
io_cqring_add_event(req, ret);
- io_put_req(req, NULL);
+ io_put_req(req);
return HRTIMER_NORESTART;
}
ret = 0;
err:
/* drop submission reference */
- io_put_req(nxt, NULL);
+ io_put_req(nxt);
if (ret) {
struct io_ring_ctx *ctx = req->ctx;
io_cqring_fill_event(nxt, ret);
trace_io_uring_fail_link(req, nxt);
io_commit_cqring(ctx);
- io_put_req(nxt, NULL);
+ io_put_req(nxt);
ret = -ECANCELED;
}
/* drop submission reference */
err:
- io_put_req(req, NULL);
+ io_put_req(req);
/* and drop final reference, if we failed */
if (ret) {
io_cqring_add_event(req, ret);
if (req->flags & REQ_F_LINK)
req->flags |= REQ_F_FAIL_LINK;
- io_put_req(req, NULL);
+ io_put_req(req);
}
return ret;