diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2023-09-01 19:38:00 +0300 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2023-09-01 19:38:00 +0300 |
commit | 8e1e49550dc85694abd04d86a8ee36bc98bd8b9e (patch) | |
tree | 03133476605e455accd14770365ea05a3bce7007 /drivers/tty/tty_io.c | |
parent | e925992671907314b7db6793a28eb39b36bc21a4 (diff) | |
parent | ebf05c7dc92c11b0355aaa0e94064beadaa4b05c (diff) | |
download | linux-8e1e49550dc85694abd04d86a8ee36bc98bd8b9e.tar.xz |
Merge tag 'tty-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
Pull tty/serial driver updates from Greg KH:
"Here is the big set of tty and serial driver changes for 6.6-rc1.
Lots of cleanups in here this cycle, and some driver updates. Short
summary is:
- Jiri's continued work to make the tty code and apis be a bit more
sane with regards to modern kernel coding style and types
- cpm_uart driver updates
- n_gsm updates and fixes
- meson driver updates
- sc16is7xx driver updates
- 8250 driver updates for different hardware types
- qcom-geni driver fixes
- tegra serial driver change
- stm32 driver updates
- synclink_gt driver cleanups
- tty structure size reduction
All of these have been in linux-next this week with no reported
issues. The last bit of cleanups from Jiri and the tty structure size
reduction came in last week, a bit late but as they were just style
changes and size reductions, I figured they should get into this merge
cycle so that others can work on top of them with no merge conflicts"
* tag 'tty-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (199 commits)
tty: shrink the size of struct tty_struct by 40 bytes
tty: n_tty: deduplicate copy code in n_tty_receive_buf_real_raw()
tty: n_tty: extract ECHO_OP processing to a separate function
tty: n_tty: unify counts to size_t
tty: n_tty: use u8 for chars and flags
tty: n_tty: simplify chars_in_buffer()
tty: n_tty: remove unsigned char casts from character constants
tty: n_tty: move newline handling to a separate function
tty: n_tty: move canon handling to a separate function
tty: n_tty: use MASK() for masking out size bits
tty: n_tty: make n_tty_data::num_overrun unsigned
tty: n_tty: use time_is_before_jiffies() in n_tty_receive_overrun()
tty: n_tty: use 'num' for writes' counts
tty: n_tty: use output character directly
tty: n_tty: make flow of n_tty_receive_buf_common() a bool
Revert "tty: serial: meson: Add a earlycon for the T7 SoC"
Documentation: devices.txt: Fix minors for ttyCPM*
Documentation: devices.txt: Remove ttySIOC*
Documentation: devices.txt: Remove ttyIOC*
serial: 8250_bcm7271: improve bcm7271 8250 port
...
Diffstat (limited to 'drivers/tty/tty_io.c')
-rw-r--r-- | drivers/tty/tty_io.c | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 27d8e3a1aace..8a94e5a43c6d 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -270,7 +270,7 @@ static int tty_paranoia_check(struct tty_struct *tty, struct inode *inode, } /* Caller must hold tty_lock */ -static int check_tty_count(struct tty_struct *tty, const char *routine) +static void check_tty_count(struct tty_struct *tty, const char *routine) { #ifdef CHECK_TTY_COUNT struct list_head *p; @@ -290,10 +290,8 @@ static int check_tty_count(struct tty_struct *tty, const char *routine) if (tty->count != (count + kopen_count)) { tty_warn(tty, "%s: tty->count(%d) != (#fd's(%d) + #kopen's(%d))\n", routine, tty->count, count, kopen_count); - return (count + kopen_count); } #endif - return 0; } /** @@ -845,19 +843,18 @@ static void tty_update_time(struct tty_struct *tty, bool mtime) * data or clears the cookie. The cookie may be something that the * ldisc maintains state for and needs to free. */ -static int iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, - struct file *file, struct iov_iter *to) +static ssize_t iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, + struct file *file, struct iov_iter *to) { - int retval = 0; void *cookie = NULL; unsigned long offset = 0; char kernel_buf[64]; - size_t count = iov_iter_count(to); + ssize_t retval = 0; + size_t copied, count = iov_iter_count(to); do { - int size, copied; + ssize_t size = min(count, sizeof(kernel_buf)); - size = count > sizeof(kernel_buf) ? sizeof(kernel_buf) : count; size = ld->ops->read(tty, file, kernel_buf, size, &cookie, offset); if (!size) break; @@ -914,11 +911,11 @@ static int iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, */ static ssize_t tty_read(struct kiocb *iocb, struct iov_iter *to) { - int i; struct file *file = iocb->ki_filp; struct inode *inode = file_inode(file); struct tty_struct *tty = file_tty(file); struct tty_ldisc *ld; + ssize_t ret; if (tty_paranoia_check(tty, inode, "tty_read")) return -EIO; @@ -931,15 +928,15 @@ static ssize_t tty_read(struct kiocb *iocb, struct iov_iter *to) ld = tty_ldisc_ref_wait(tty); if (!ld) return hung_up_tty_read(iocb, to); - i = -EIO; + ret = -EIO; if (ld->ops->read) - i = iterate_tty_read(ld, tty, file, to); + ret = iterate_tty_read(ld, tty, file, to); tty_ldisc_deref(ld); - if (i > 0) + if (ret > 0) tty_update_time(tty, false); - return i; + return ret; } void tty_write_unlock(struct tty_struct *tty) @@ -948,7 +945,7 @@ void tty_write_unlock(struct tty_struct *tty) wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT); } -int tty_write_lock(struct tty_struct *tty, int ndelay) +int tty_write_lock(struct tty_struct *tty, bool ndelay) { if (!mutex_trylock(&tty->atomic_write_lock)) { if (ndelay) @@ -963,15 +960,11 @@ int tty_write_lock(struct tty_struct *tty, int ndelay) * Split writes up in sane blocksizes to avoid * denial-of-service type attacks */ -static inline ssize_t do_tty_write( - ssize_t (*write)(struct tty_struct *, struct file *, const unsigned char *, size_t), - struct tty_struct *tty, - struct file *file, - struct iov_iter *from) +static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty, + struct file *file, struct iov_iter *from) { - size_t count = iov_iter_count(from); + size_t chunk, count = iov_iter_count(from); ssize_t ret, written = 0; - unsigned int chunk; ret = tty_write_lock(tty, file->f_flags & O_NDELAY); if (ret < 0) @@ -1015,16 +1008,13 @@ static inline ssize_t do_tty_write( /* Do the write .. */ for (;;) { - size_t size = count; - - if (size > chunk) - size = chunk; + size_t size = min(chunk, count); ret = -EFAULT; if (copy_from_iter(tty->write_buf, size, from) != size) break; - ret = write(tty, file, tty->write_buf, size); + ret = ld->ops->write(tty, file, tty->write_buf, size); if (ret <= 0) break; @@ -1095,7 +1085,7 @@ static ssize_t file_tty_write(struct file *file, struct kiocb *iocb, struct iov_ if (!ld->ops->write) ret = -EIO; else - ret = do_tty_write(ld->ops->write, tty, file, from); + ret = iterate_tty_write(ld, tty, file, from); tty_ldisc_deref(ld); return ret; } @@ -1162,7 +1152,7 @@ int tty_send_xchar(struct tty_struct *tty, char ch) return 0; } - if (tty_write_lock(tty, 0) < 0) + if (tty_write_lock(tty, false) < 0) return -ERESTARTSYS; down_read(&tty->termios_rwsem); @@ -2488,7 +2478,7 @@ static int send_break(struct tty_struct *tty, unsigned int duration) retval = tty->ops->break_ctl(tty, duration); else { /* Do the work ourselves */ - if (tty_write_lock(tty, 0) < 0) + if (tty_write_lock(tty, false) < 0) return -EINTR; retval = tty->ops->break_ctl(tty, -1); if (retval) |