Skip to content

Commit 494e63e

Browse files
committed
Merge 9bb48c8 ("tty: implement write_iter") into tty-linus
We want the single "splice/sendfile to a tty" regression fix into tty-linus so it can get into 5.11-final, while the larger patch series fixing "splice/sendfile from a tty" should wait for 5.12-rc1 so that we get more testing. Signed-off-by: Greg Kroah-Hartman <[email protected]>
2 parents 54ca955 + 9bb48c8 commit 494e63e

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

drivers/tty/tty_io.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers */
143143
DEFINE_MUTEX(tty_mutex);
144144

145145
static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
146-
static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
147-
ssize_t redirected_tty_write(struct file *, const char __user *,
148-
size_t, loff_t *);
146+
static ssize_t tty_write(struct kiocb *, struct iov_iter *);
147+
ssize_t redirected_tty_write(struct kiocb *, struct iov_iter *);
149148
static __poll_t tty_poll(struct file *, poll_table *);
150149
static int tty_open(struct inode *, struct file *);
151150
long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
@@ -478,7 +477,8 @@ static void tty_show_fdinfo(struct seq_file *m, struct file *file)
478477
static const struct file_operations tty_fops = {
479478
.llseek = no_llseek,
480479
.read = tty_read,
481-
.write = tty_write,
480+
.write_iter = tty_write,
481+
.splice_write = iter_file_splice_write,
482482
.poll = tty_poll,
483483
.unlocked_ioctl = tty_ioctl,
484484
.compat_ioctl = tty_compat_ioctl,
@@ -491,7 +491,8 @@ static const struct file_operations tty_fops = {
491491
static const struct file_operations console_fops = {
492492
.llseek = no_llseek,
493493
.read = tty_read,
494-
.write = redirected_tty_write,
494+
.write_iter = redirected_tty_write,
495+
.splice_write = iter_file_splice_write,
495496
.poll = tty_poll,
496497
.unlocked_ioctl = tty_ioctl,
497498
.compat_ioctl = tty_compat_ioctl,
@@ -606,9 +607,9 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
606607
/* This breaks for file handles being sent over AF_UNIX sockets ? */
607608
list_for_each_entry(priv, &tty->tty_files, list) {
608609
filp = priv->file;
609-
if (filp->f_op->write == redirected_tty_write)
610+
if (filp->f_op->write_iter == redirected_tty_write)
610611
cons_filp = filp;
611-
if (filp->f_op->write != tty_write)
612+
if (filp->f_op->write_iter != tty_write)
612613
continue;
613614
closecount++;
614615
__tty_fasync(-1, filp, 0); /* can't block */
@@ -901,9 +902,9 @@ static inline ssize_t do_tty_write(
901902
ssize_t (*write)(struct tty_struct *, struct file *, const unsigned char *, size_t),
902903
struct tty_struct *tty,
903904
struct file *file,
904-
const char __user *buf,
905-
size_t count)
905+
struct iov_iter *from)
906906
{
907+
size_t count = iov_iter_count(from);
907908
ssize_t ret, written = 0;
908909
unsigned int chunk;
909910

@@ -955,14 +956,20 @@ static inline ssize_t do_tty_write(
955956
size_t size = count;
956957
if (size > chunk)
957958
size = chunk;
959+
958960
ret = -EFAULT;
959-
if (copy_from_user(tty->write_buf, buf, size))
961+
if (copy_from_iter(tty->write_buf, size, from) != size)
960962
break;
963+
961964
ret = write(tty, file, tty->write_buf, size);
962965
if (ret <= 0)
963966
break;
967+
968+
/* FIXME! Have Al check this! */
969+
if (ret != size)
970+
iov_iter_revert(from, size-ret);
971+
964972
written += ret;
965-
buf += ret;
966973
count -= ret;
967974
if (!count)
968975
break;
@@ -1022,9 +1029,9 @@ void tty_write_message(struct tty_struct *tty, char *msg)
10221029
* write method will not be invoked in parallel for each device.
10231030
*/
10241031

1025-
static ssize_t tty_write(struct file *file, const char __user *buf,
1026-
size_t count, loff_t *ppos)
1032+
static ssize_t tty_write(struct kiocb *iocb, struct iov_iter *from)
10271033
{
1034+
struct file *file = iocb->ki_filp;
10281035
struct tty_struct *tty = file_tty(file);
10291036
struct tty_ldisc *ld;
10301037
ssize_t ret;
@@ -1037,18 +1044,15 @@ static ssize_t tty_write(struct file *file, const char __user *buf,
10371044
if (tty->ops->write_room == NULL)
10381045
tty_err(tty, "missing write_room method\n");
10391046
ld = tty_ldisc_ref_wait(tty);
1040-
if (!ld)
1041-
return hung_up_tty_write(file, buf, count, ppos);
1042-
if (!ld->ops->write)
1047+
if (!ld || !ld->ops->write)
10431048
ret = -EIO;
10441049
else
1045-
ret = do_tty_write(ld->ops->write, tty, file, buf, count);
1050+
ret = do_tty_write(ld->ops->write, tty, file, from);
10461051
tty_ldisc_deref(ld);
10471052
return ret;
10481053
}
10491054

1050-
ssize_t redirected_tty_write(struct file *file, const char __user *buf,
1051-
size_t count, loff_t *ppos)
1055+
ssize_t redirected_tty_write(struct kiocb *iocb, struct iov_iter *iter)
10521056
{
10531057
struct file *p = NULL;
10541058

@@ -1059,11 +1063,11 @@ ssize_t redirected_tty_write(struct file *file, const char __user *buf,
10591063

10601064
if (p) {
10611065
ssize_t res;
1062-
res = vfs_write(p, buf, count, &p->f_pos);
1066+
res = vfs_iocb_iter_write(p, iocb, iter);
10631067
fput(p);
10641068
return res;
10651069
}
1066-
return tty_write(file, buf, count, ppos);
1070+
return tty_write(iocb, iter);
10671071
}
10681072

10691073
/*
@@ -2295,7 +2299,7 @@ static int tioccons(struct file *file)
22952299
{
22962300
if (!capable(CAP_SYS_ADMIN))
22972301
return -EPERM;
2298-
if (file->f_op->write == redirected_tty_write) {
2302+
if (file->f_op->write_iter == redirected_tty_write) {
22992303
struct file *f;
23002304
spin_lock(&redirect_lock);
23012305
f = redirect;

0 commit comments

Comments
 (0)