Skip to content

Commit a6f4657

Browse files
author
Al Viro
committed
convert vmsplice() to CLASS(fd)
Irregularity here is fdput() not in the same scope as fdget(); we could just lift it out vmsplice_type() in vmsplice(2), but there's no much point keeping vmsplice_type() separate after that... Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 0d113fc commit a6f4657

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

fs/splice.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,21 +1564,6 @@ static ssize_t vmsplice_to_pipe(struct file *file, struct iov_iter *iter,
15641564
return ret;
15651565
}
15661566

1567-
static int vmsplice_type(struct fd f, int *type)
1568-
{
1569-
if (!fd_file(f))
1570-
return -EBADF;
1571-
if (fd_file(f)->f_mode & FMODE_WRITE) {
1572-
*type = ITER_SOURCE;
1573-
} else if (fd_file(f)->f_mode & FMODE_READ) {
1574-
*type = ITER_DEST;
1575-
} else {
1576-
fdput(f);
1577-
return -EBADF;
1578-
}
1579-
return 0;
1580-
}
1581-
15821567
/*
15831568
* Note that vmsplice only really supports true splicing _from_ user memory
15841569
* to a pipe, not the other way around. Splicing from user memory is a simple
@@ -1602,21 +1587,25 @@ SYSCALL_DEFINE4(vmsplice, int, fd, const struct iovec __user *, uiov,
16021587
struct iovec *iov = iovstack;
16031588
struct iov_iter iter;
16041589
ssize_t error;
1605-
struct fd f;
16061590
int type;
16071591

16081592
if (unlikely(flags & ~SPLICE_F_ALL))
16091593
return -EINVAL;
16101594

1611-
f = fdget(fd);
1612-
error = vmsplice_type(f, &type);
1613-
if (error)
1614-
return error;
1595+
CLASS(fd, f)(fd);
1596+
if (fd_empty(f))
1597+
return -EBADF;
1598+
if (fd_file(f)->f_mode & FMODE_WRITE)
1599+
type = ITER_SOURCE;
1600+
else if (fd_file(f)->f_mode & FMODE_READ)
1601+
type = ITER_DEST;
1602+
else
1603+
return -EBADF;
16151604

16161605
error = import_iovec(type, uiov, nr_segs,
16171606
ARRAY_SIZE(iovstack), &iov, &iter);
16181607
if (error < 0)
1619-
goto out_fdput;
1608+
return error;
16201609

16211610
if (!iov_iter_count(&iter))
16221611
error = 0;
@@ -1626,8 +1615,6 @@ SYSCALL_DEFINE4(vmsplice, int, fd, const struct iovec __user *, uiov,
16261615
error = vmsplice_to_user(fd_file(f), &iter, flags);
16271616

16281617
kfree(iov);
1629-
out_fdput:
1630-
fdput(f);
16311618
return error;
16321619
}
16331620

0 commit comments

Comments
 (0)