diff options
author | Christoph Hellwig <hch@lst.de> | 2018-03-30 05:19:25 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2018-05-26 03:16:44 -0400 |
commit | f3a2752a43de18eb2eafa869d06f6e423ff0ce61 (patch) | |
tree | d61a9607b92e1bd3059af7f1cfbcb2965c5e522d /fs/aio.c | |
parent | 3deb642f0de4c14f37437dd247f9c77839f043f8 (diff) |
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>
Diffstat (limited to 'fs/aio.c')
-rw-r--r-- | fs/aio.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -46,6 +46,8 @@ | |||
46 | 46 | ||
47 | #include "internal.h" | 47 | #include "internal.h" |
48 | 48 | ||
49 | #define KIOCB_KEY 0 | ||
50 | |||
49 | #define AIO_RING_MAGIC 0xa10a10a1 | 51 | #define AIO_RING_MAGIC 0xa10a10a1 |
50 | #define AIO_RING_COMPAT_FEATURES 1 | 52 | #define AIO_RING_COMPAT_FEATURES 1 |
51 | #define AIO_RING_INCOMPAT_FEATURES 0 | 53 | #define AIO_RING_INCOMPAT_FEATURES 0 |
@@ -1811,15 +1813,12 @@ COMPAT_SYSCALL_DEFINE3(io_submit, compat_aio_context_t, ctx_id, | |||
1811 | * Finds a given iocb for cancellation. | 1813 | * Finds a given iocb for cancellation. |
1812 | */ | 1814 | */ |
1813 | static struct aio_kiocb * | 1815 | static struct aio_kiocb * |
1814 | lookup_kiocb(struct kioctx *ctx, struct iocb __user *iocb, u32 key) | 1816 | lookup_kiocb(struct kioctx *ctx, struct iocb __user *iocb) |
1815 | { | 1817 | { |
1816 | struct aio_kiocb *kiocb; | 1818 | struct aio_kiocb *kiocb; |
1817 | 1819 | ||
1818 | assert_spin_locked(&ctx->ctx_lock); | 1820 | assert_spin_locked(&ctx->ctx_lock); |
1819 | 1821 | ||
1820 | if (key != KIOCB_KEY) | ||
1821 | return NULL; | ||
1822 | |||
1823 | /* TODO: use a hash or array, this sucks. */ | 1822 | /* TODO: use a hash or array, this sucks. */ |
1824 | list_for_each_entry(kiocb, &ctx->active_reqs, ki_list) { | 1823 | list_for_each_entry(kiocb, &ctx->active_reqs, ki_list) { |
1825 | if (kiocb->ki_user_iocb == iocb) | 1824 | if (kiocb->ki_user_iocb == iocb) |
@@ -1846,9 +1845,10 @@ SYSCALL_DEFINE3(io_cancel, aio_context_t, ctx_id, struct iocb __user *, iocb, | |||
1846 | u32 key; | 1845 | u32 key; |
1847 | int ret; | 1846 | int ret; |
1848 | 1847 | ||
1849 | ret = get_user(key, &iocb->aio_key); | 1848 | if (unlikely(get_user(key, &iocb->aio_key))) |
1850 | if (unlikely(ret)) | ||
1851 | return -EFAULT; | 1849 | return -EFAULT; |
1850 | if (unlikely(key != KIOCB_KEY)) | ||
1851 | return -EINVAL; | ||
1852 | 1852 | ||
1853 | ctx = lookup_ioctx(ctx_id); | 1853 | ctx = lookup_ioctx(ctx_id); |
1854 | if (unlikely(!ctx)) | 1854 | if (unlikely(!ctx)) |
@@ -1856,7 +1856,7 @@ SYSCALL_DEFINE3(io_cancel, aio_context_t, ctx_id, struct iocb __user *, iocb, | |||
1856 | 1856 | ||
1857 | spin_lock_irq(&ctx->ctx_lock); | 1857 | spin_lock_irq(&ctx->ctx_lock); |
1858 | 1858 | ||
1859 | kiocb = lookup_kiocb(ctx, iocb, key); | 1859 | kiocb = lookup_kiocb(ctx, iocb); |
1860 | if (kiocb) | 1860 | if (kiocb) |
1861 | ret = kiocb_cancel(kiocb); | 1861 | ret = kiocb_cancel(kiocb); |
1862 | else | 1862 | else |