@@ -1777,35 +1777,12 @@ static int aio_poll(struct aio_kiocb *aiocb, const struct iocb *iocb)
1777
1777
}
1778
1778
1779
1779
static int __io_submit_one (struct kioctx * ctx , const struct iocb * iocb ,
1780
- struct iocb __user * user_iocb , bool compat )
1780
+ struct iocb __user * user_iocb , struct aio_kiocb * req ,
1781
+ bool compat )
1781
1782
{
1782
- struct aio_kiocb * req ;
1783
- int ret ;
1784
-
1785
- /* enforce forwards compatibility on users */
1786
- if (unlikely (iocb -> aio_reserved2 )) {
1787
- pr_debug ("EINVAL: reserve field set\n" );
1788
- return - EINVAL ;
1789
- }
1790
-
1791
- /* prevent overflows */
1792
- if (unlikely (
1793
- (iocb -> aio_buf != (unsigned long )iocb -> aio_buf ) ||
1794
- (iocb -> aio_nbytes != (size_t )iocb -> aio_nbytes ) ||
1795
- ((ssize_t )iocb -> aio_nbytes < 0 )
1796
- )) {
1797
- pr_debug ("EINVAL: overflow check\n" );
1798
- return - EINVAL ;
1799
- }
1800
-
1801
- req = aio_get_req (ctx );
1802
- if (unlikely (!req ))
1803
- return - EAGAIN ;
1804
-
1805
1783
req -> ki_filp = fget (iocb -> aio_fildes );
1806
- ret = - EBADF ;
1807
1784
if (unlikely (!req -> ki_filp ))
1808
- goto out_put_req ;
1785
+ return - EBADF ;
1809
1786
1810
1787
if (iocb -> aio_flags & IOCB_FLAG_RESFD ) {
1811
1788
struct eventfd_ctx * eventfd ;
@@ -1816,17 +1793,15 @@ static int __io_submit_one(struct kioctx *ctx, const struct iocb *iocb,
1816
1793
* event using the eventfd_signal() function.
1817
1794
*/
1818
1795
eventfd = eventfd_ctx_fdget (iocb -> aio_resfd );
1819
- if (IS_ERR (eventfd )) {
1820
- ret = PTR_ERR (eventfd );
1821
- goto out_put_req ;
1822
- }
1796
+ if (IS_ERR (eventfd ))
1797
+ return PTR_ERR (req -> ki_eventfd );
1798
+
1823
1799
req -> ki_eventfd = eventfd ;
1824
1800
}
1825
1801
1826
- ret = put_user (KIOCB_KEY , & user_iocb -> aio_key );
1827
- if (unlikely (ret )) {
1802
+ if (unlikely (put_user (KIOCB_KEY , & user_iocb -> aio_key ))) {
1828
1803
pr_debug ("EFAULT: aio_key\n" );
1829
- goto out_put_req ;
1804
+ return - EFAULT ;
1830
1805
}
1831
1806
1832
1807
req -> ki_res .obj = (u64 )(unsigned long )user_iocb ;
@@ -1836,58 +1811,70 @@ static int __io_submit_one(struct kioctx *ctx, const struct iocb *iocb,
1836
1811
1837
1812
switch (iocb -> aio_lio_opcode ) {
1838
1813
case IOCB_CMD_PREAD :
1839
- ret = aio_read (& req -> rw , iocb , false, compat );
1840
- break ;
1814
+ return aio_read (& req -> rw , iocb , false, compat );
1841
1815
case IOCB_CMD_PWRITE :
1842
- ret = aio_write (& req -> rw , iocb , false, compat );
1843
- break ;
1816
+ return aio_write (& req -> rw , iocb , false, compat );
1844
1817
case IOCB_CMD_PREADV :
1845
- ret = aio_read (& req -> rw , iocb , true, compat );
1846
- break ;
1818
+ return aio_read (& req -> rw , iocb , true, compat );
1847
1819
case IOCB_CMD_PWRITEV :
1848
- ret = aio_write (& req -> rw , iocb , true, compat );
1849
- break ;
1820
+ return aio_write (& req -> rw , iocb , true, compat );
1850
1821
case IOCB_CMD_FSYNC :
1851
- ret = aio_fsync (& req -> fsync , iocb , false);
1852
- break ;
1822
+ return aio_fsync (& req -> fsync , iocb , false);
1853
1823
case IOCB_CMD_FDSYNC :
1854
- ret = aio_fsync (& req -> fsync , iocb , true);
1855
- break ;
1824
+ return aio_fsync (& req -> fsync , iocb , true);
1856
1825
case IOCB_CMD_POLL :
1857
- ret = aio_poll (req , iocb );
1858
- break ;
1826
+ return aio_poll (req , iocb );
1859
1827
default :
1860
1828
pr_debug ("invalid aio operation %d\n" , iocb -> aio_lio_opcode );
1861
- ret = - EINVAL ;
1862
- break ;
1829
+ return - EINVAL ;
1863
1830
}
1864
-
1865
- /* Done with the synchronous reference */
1866
- iocb_put (req );
1867
-
1868
- /*
1869
- * If ret is 0, we'd either done aio_complete() ourselves or have
1870
- * arranged for that to be done asynchronously. Anything non-zero
1871
- * means that we need to destroy req ourselves.
1872
- */
1873
- if (!ret )
1874
- return 0 ;
1875
-
1876
- out_put_req :
1877
- iocb_destroy (req );
1878
- put_reqs_available (ctx , 1 );
1879
- return ret ;
1880
1831
}
1881
1832
1882
1833
static int io_submit_one (struct kioctx * ctx , struct iocb __user * user_iocb ,
1883
1834
bool compat )
1884
1835
{
1836
+ struct aio_kiocb * req ;
1885
1837
struct iocb iocb ;
1838
+ int err ;
1886
1839
1887
1840
if (unlikely (copy_from_user (& iocb , user_iocb , sizeof (iocb ))))
1888
1841
return - EFAULT ;
1889
1842
1890
- return __io_submit_one (ctx , & iocb , user_iocb , compat );
1843
+ /* enforce forwards compatibility on users */
1844
+ if (unlikely (iocb .aio_reserved2 )) {
1845
+ pr_debug ("EINVAL: reserve field set\n" );
1846
+ return - EINVAL ;
1847
+ }
1848
+
1849
+ /* prevent overflows */
1850
+ if (unlikely (
1851
+ (iocb .aio_buf != (unsigned long )iocb .aio_buf ) ||
1852
+ (iocb .aio_nbytes != (size_t )iocb .aio_nbytes ) ||
1853
+ ((ssize_t )iocb .aio_nbytes < 0 )
1854
+ )) {
1855
+ pr_debug ("EINVAL: overflow check\n" );
1856
+ return - EINVAL ;
1857
+ }
1858
+
1859
+ req = aio_get_req (ctx );
1860
+ if (unlikely (!req ))
1861
+ return - EAGAIN ;
1862
+
1863
+ err = __io_submit_one (ctx , & iocb , user_iocb , req , compat );
1864
+
1865
+ /* Done with the synchronous reference */
1866
+ iocb_put (req );
1867
+
1868
+ /*
1869
+ * If err is 0, we'd either done aio_complete() ourselves or have
1870
+ * arranged for that to be done asynchronously. Anything non-zero
1871
+ * means that we need to destroy req ourselves.
1872
+ */
1873
+ if (unlikely (err )) {
1874
+ iocb_destroy (req );
1875
+ put_reqs_available (ctx , 1 );
1876
+ }
1877
+ return err ;
1891
1878
}
1892
1879
1893
1880
/* sys_io_submit:
0 commit comments