aio: simplify KIOCB_KEY handling
No need to pass the key field to lookup_iocb to compare it with KIOCB_KEY, as we can do that right after retrieving it from userspace. Also move the KIOCB_KEY definition to aio.c as it is an internal value not used by any other place in the kernel. Signed-off-by: Christoph Hellwig <hch@lst.de>hifive-unleashed-5.1
parent
3deb642f0d
commit
f3a2752a43
14
fs/aio.c
14
fs/aio.c
|
@ -46,6 +46,8 @@
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
#define KIOCB_KEY 0
|
||||||
|
|
||||||
#define AIO_RING_MAGIC 0xa10a10a1
|
#define AIO_RING_MAGIC 0xa10a10a1
|
||||||
#define AIO_RING_COMPAT_FEATURES 1
|
#define AIO_RING_COMPAT_FEATURES 1
|
||||||
#define AIO_RING_INCOMPAT_FEATURES 0
|
#define AIO_RING_INCOMPAT_FEATURES 0
|
||||||
|
@ -1811,15 +1813,12 @@ COMPAT_SYSCALL_DEFINE3(io_submit, compat_aio_context_t, ctx_id,
|
||||||
* Finds a given iocb for cancellation.
|
* Finds a given iocb for cancellation.
|
||||||
*/
|
*/
|
||||||
static struct aio_kiocb *
|
static struct aio_kiocb *
|
||||||
lookup_kiocb(struct kioctx *ctx, struct iocb __user *iocb, u32 key)
|
lookup_kiocb(struct kioctx *ctx, struct iocb __user *iocb)
|
||||||
{
|
{
|
||||||
struct aio_kiocb *kiocb;
|
struct aio_kiocb *kiocb;
|
||||||
|
|
||||||
assert_spin_locked(&ctx->ctx_lock);
|
assert_spin_locked(&ctx->ctx_lock);
|
||||||
|
|
||||||
if (key != KIOCB_KEY)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/* TODO: use a hash or array, this sucks. */
|
/* TODO: use a hash or array, this sucks. */
|
||||||
list_for_each_entry(kiocb, &ctx->active_reqs, ki_list) {
|
list_for_each_entry(kiocb, &ctx->active_reqs, ki_list) {
|
||||||
if (kiocb->ki_user_iocb == iocb)
|
if (kiocb->ki_user_iocb == iocb)
|
||||||
|
@ -1846,9 +1845,10 @@ SYSCALL_DEFINE3(io_cancel, aio_context_t, ctx_id, struct iocb __user *, iocb,
|
||||||
u32 key;
|
u32 key;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = get_user(key, &iocb->aio_key);
|
if (unlikely(get_user(key, &iocb->aio_key)))
|
||||||
if (unlikely(ret))
|
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
if (unlikely(key != KIOCB_KEY))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
ctx = lookup_ioctx(ctx_id);
|
ctx = lookup_ioctx(ctx_id);
|
||||||
if (unlikely(!ctx))
|
if (unlikely(!ctx))
|
||||||
|
@ -1856,7 +1856,7 @@ SYSCALL_DEFINE3(io_cancel, aio_context_t, ctx_id, struct iocb __user *, iocb,
|
||||||
|
|
||||||
spin_lock_irq(&ctx->ctx_lock);
|
spin_lock_irq(&ctx->ctx_lock);
|
||||||
|
|
||||||
kiocb = lookup_kiocb(ctx, iocb, key);
|
kiocb = lookup_kiocb(ctx, iocb);
|
||||||
if (kiocb)
|
if (kiocb)
|
||||||
ret = kiocb_cancel(kiocb);
|
ret = kiocb_cancel(kiocb);
|
||||||
else
|
else
|
||||||
|
|
|
@ -8,8 +8,6 @@ struct kioctx;
|
||||||
struct kiocb;
|
struct kiocb;
|
||||||
struct mm_struct;
|
struct mm_struct;
|
||||||
|
|
||||||
#define KIOCB_KEY 0
|
|
||||||
|
|
||||||
typedef int (kiocb_cancel_fn)(struct kiocb *);
|
typedef int (kiocb_cancel_fn)(struct kiocb *);
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
|
|
Loading…
Reference in New Issue