Commit 75321b50 authored by Christoph Hellwig's avatar Christoph Hellwig
Browse files

aio: sanitize ki_list handling

Instead of handcoded non-null checks always initialize ki_list to an
empty list and use list_empty / list_empty_careful on it.  While we're
at it also error out on a double call to kiocb_set_cancel_fn instead
of ignoring it.
Signed-off-by: default avatarChristoph Hellwig <>
Acked-by: default avatarJeff Moyer <>
Reviewed-by: default avatarGreg Kroah-Hartman <>
Reviewed-by: default avatarDarrick J. Wong <>
parent c213dc82
......@@ -553,13 +553,12 @@ void kiocb_set_cancel_fn(struct kiocb *iocb, kiocb_cancel_fn *cancel)
struct kioctx *ctx = req->ki_ctx;
unsigned long flags;
spin_lock_irqsave(&ctx->ctx_lock, flags);
if (!req->
list_add(&req->ki_list, &ctx->active_reqs);
if (WARN_ON_ONCE(!list_empty(&req->ki_list)))
spin_lock_irqsave(&ctx->ctx_lock, flags);
list_add_tail(&req->ki_list, &ctx->active_reqs);
req->ki_cancel = cancel;
spin_unlock_irqrestore(&ctx->ctx_lock, flags);
......@@ -1039,7 +1038,7 @@ static inline struct aio_kiocb *aio_get_req(struct kioctx *ctx)
goto out_put;
req->ki_ctx = ctx;
return req;
......@@ -1107,7 +1106,7 @@ static void aio_complete(struct kiocb *kiocb, long res, long res2)
if (iocb-> {
if (!list_empty_careful(&iocb->ki_list)) {
unsigned long flags;
spin_lock_irqsave(&ctx->ctx_lock, flags);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment