@@ -1118,19 +1118,17 @@ long do_splice(struct file *in, loff_t __user *off_in,
1118
1118
loff_t offset ;
1119
1119
long ret ;
1120
1120
1121
+ if (unlikely (!(in -> f_mode & FMODE_READ ) ||
1122
+ !(out -> f_mode & FMODE_WRITE )))
1123
+ return - EBADF ;
1124
+
1121
1125
ipipe = get_pipe_info (in );
1122
1126
opipe = get_pipe_info (out );
1123
1127
1124
1128
if (ipipe && opipe ) {
1125
1129
if (off_in || off_out )
1126
1130
return - ESPIPE ;
1127
1131
1128
- if (!(in -> f_mode & FMODE_READ ))
1129
- return - EBADF ;
1130
-
1131
- if (!(out -> f_mode & FMODE_WRITE ))
1132
- return - EBADF ;
1133
-
1134
1132
/* Splicing to self would be fun, but... */
1135
1133
if (ipipe == opipe )
1136
1134
return - EINVAL ;
@@ -1153,9 +1151,6 @@ long do_splice(struct file *in, loff_t __user *off_in,
1153
1151
offset = out -> f_pos ;
1154
1152
}
1155
1153
1156
- if (unlikely (!(out -> f_mode & FMODE_WRITE )))
1157
- return - EBADF ;
1158
-
1159
1154
if (unlikely (out -> f_flags & O_APPEND ))
1160
1155
return - EINVAL ;
1161
1156
@@ -1440,15 +1435,11 @@ SYSCALL_DEFINE6(splice, int, fd_in, loff_t __user *, off_in,
1440
1435
error = - EBADF ;
1441
1436
in = fdget (fd_in );
1442
1437
if (in .file ) {
1443
- if (in .file -> f_mode & FMODE_READ ) {
1444
- out = fdget (fd_out );
1445
- if (out .file ) {
1446
- if (out .file -> f_mode & FMODE_WRITE )
1447
- error = do_splice (in .file , off_in ,
1448
- out .file , off_out ,
1449
- len , flags );
1450
- fdput (out );
1451
- }
1438
+ out = fdget (fd_out );
1439
+ if (out .file ) {
1440
+ error = do_splice (in .file , off_in , out .file , off_out ,
1441
+ len , flags );
1442
+ fdput (out );
1452
1443
}
1453
1444
fdput (in );
1454
1445
}
@@ -1770,6 +1761,10 @@ static long do_tee(struct file *in, struct file *out, size_t len,
1770
1761
struct pipe_inode_info * opipe = get_pipe_info (out );
1771
1762
int ret = - EINVAL ;
1772
1763
1764
+ if (unlikely (!(in -> f_mode & FMODE_READ ) ||
1765
+ !(out -> f_mode & FMODE_WRITE )))
1766
+ return - EBADF ;
1767
+
1773
1768
/*
1774
1769
* Duplicate the contents of ipipe to opipe without actually
1775
1770
* copying the data.
@@ -1795,7 +1790,7 @@ static long do_tee(struct file *in, struct file *out, size_t len,
1795
1790
1796
1791
SYSCALL_DEFINE4 (tee , int , fdin , int , fdout , size_t , len , unsigned int , flags )
1797
1792
{
1798
- struct fd in ;
1793
+ struct fd in , out ;
1799
1794
int error ;
1800
1795
1801
1796
if (unlikely (flags & ~SPLICE_F_ALL ))
@@ -1807,14 +1802,10 @@ SYSCALL_DEFINE4(tee, int, fdin, int, fdout, size_t, len, unsigned int, flags)
1807
1802
error = - EBADF ;
1808
1803
in = fdget (fdin );
1809
1804
if (in .file ) {
1810
- if (in .file -> f_mode & FMODE_READ ) {
1811
- struct fd out = fdget (fdout );
1812
- if (out .file ) {
1813
- if (out .file -> f_mode & FMODE_WRITE )
1814
- error = do_tee (in .file , out .file ,
1815
- len , flags );
1816
- fdput (out );
1817
- }
1805
+ out = fdget (fdout );
1806
+ if (out .file ) {
1807
+ error = do_tee (in .file , out .file , len , flags );
1808
+ fdput (out );
1818
1809
}
1819
1810
fdput (in );
1820
1811
}
0 commit comments