]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
tty: simplify tty_dev_name_to_number() using guard(mutex)
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Mon, 5 Aug 2024 10:20:34 +0000 (12:20 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 7 Aug 2024 11:13:35 +0000 (13:13 +0200)
In tty_dev_name_to_number(), a guard can help to make the code easier to
follow. Especially how 0 is returned in the successful case. So use a
guard there.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20240805102046.307511-2-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/tty_io.c

index 407b0d87b7c10890da30bdd9f9c60605b85829b6..e817e12ae1341681771333b5f9397987f8cda4f4 100644 (file)
@@ -350,22 +350,19 @@ int tty_dev_name_to_number(const char *name, dev_t *number)
                return ret;
 
        prefix_length = str - name;
-       mutex_lock(&tty_mutex);
+
+       guard(mutex)(&tty_mutex);
 
        list_for_each_entry(p, &tty_drivers, tty_drivers)
                if (prefix_length == strlen(p->name) && strncmp(name,
                                        p->name, prefix_length) == 0) {
                        if (index < p->num) {
                                *number = MKDEV(p->major, p->minor_start + index);
-                               goto out;
+                               return 0;
                        }
                }
 
-       /* if here then driver wasn't found */
-       ret = -ENODEV;
-out:
-       mutex_unlock(&tty_mutex);
-       return ret;
+       return -ENODEV;
 }
 EXPORT_SYMBOL_GPL(tty_dev_name_to_number);