]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tty: n_tty: clean up process_output_block()
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Mon, 17 Mar 2025 07:00:22 +0000 (08:00 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 20 Mar 2025 15:00:50 +0000 (08:00 -0700)
* 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>
drivers/tty/n_tty.c

index df52aae5f71ae18dd175b7d51ffdfc38d6d6e56c..5d172edbb03c67063a8872f88300a2ff2581babe 100644 (file)
@@ -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,