diff options
author | Jiri Slaby (SUSE) <jirislaby@kernel.org> | 2025-03-17 08:00:22 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-03-20 08:00:50 -0700 |
commit | e287d64605d6ab66884b6d473a04fc91d5dc16c3 (patch) | |
tree | deb19a497a0d3e85ad47162452479f0e52b1dd9c | |
parent | fdfa49a8c96500ef9e1fe1cd2e68c8fd71d8b53a (diff) |
tty: n_tty: clean up process_output_block()
* Use guard(mutex), which results in:
- the function can return directly when "space == 0".
- "i" can now be "unsigned" as it is no longer abused to hold a retval
from tty->ops->write(). Note the compared-to "nr" is already
"unsigned".
* The end label is now dubbed "do_write" as that is what happens there.
Unlike the uncertain "break_out" name.
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20250317070046.24386-8-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/n_tty.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index df52aae5f71a..5d172edbb03c 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -519,17 +519,15 @@ static ssize_t process_output_block(struct tty_struct *tty, const u8 *buf, unsigned int nr) { struct n_tty_data *ldata = tty->disc_data; - unsigned int space; - int i; + unsigned int space, i; const u8 *cp; - mutex_lock(&ldata->output_lock); + guard(mutex)(&ldata->output_lock); space = tty_write_room(tty); - if (space == 0) { - mutex_unlock(&ldata->output_lock); + if (space == 0) return 0; - } + if (nr > space) nr = space; @@ -541,18 +539,18 @@ static ssize_t process_output_block(struct tty_struct *tty, if (O_ONLRET(tty)) ldata->column = 0; if (O_ONLCR(tty)) - goto break_out; + goto do_write; ldata->canon_column = ldata->column; break; case '\r': if (O_ONOCR(tty) && ldata->column == 0) - goto break_out; + goto do_write; if (O_OCRNL(tty)) - goto break_out; + goto do_write; ldata->canon_column = ldata->column = 0; break; case '\t': - goto break_out; + goto do_write; case '\b': if (ldata->column > 0) ldata->column--; @@ -560,18 +558,15 @@ static ssize_t process_output_block(struct tty_struct *tty, default: if (!iscntrl(c)) { if (O_OLCUC(tty)) - goto break_out; + goto do_write; if (!is_continuation(c, tty)) ldata->column++; } break; } } -break_out: - i = tty->ops->write(tty, buf, i); - - mutex_unlock(&ldata->output_lock); - return i; +do_write: + return tty->ops->write(tty, buf, i); } static int n_tty_process_echo_ops(struct tty_struct *tty, size_t *tail, |