]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tty: n_tty: simplify process_output()
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Mon, 17 Mar 2025 07:00:21 +0000 (08:00 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 20 Mar 2025 15:00:50 +0000 (08:00 -0700)
Using guard(mutex), the function can be written in a much more efficient
way.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20250317070046.24386-7-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/n_tty.c

index 765d24268d75ca90430327168e4a753117ad6985..df52aae5f71ae18dd175b7d51ffdfc38d6d6e56c 100644 (file)
@@ -488,19 +488,13 @@ static int do_output_char(u8 c, struct tty_struct *tty, int space)
 static int process_output(u8 c, struct tty_struct *tty)
 {
        struct n_tty_data *ldata = tty->disc_data;
-       unsigned int space;
-       int retval;
 
-       mutex_lock(&ldata->output_lock);
+       guard(mutex)(&ldata->output_lock);
 
-       space = tty_write_room(tty);
-       retval = do_output_char(c, tty, space);
-
-       mutex_unlock(&ldata->output_lock);
-       if (retval < 0)
+       if (do_output_char(c, tty, tty_write_room(tty)) < 0)
                return -1;
-       else
-               return 0;
+
+       return 0;
 }
 
 /**