From: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
"Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Subject: [PATCH 01/13] tty: simplify tty_dev_name_to_number() using guard(mutex)
Date: Mon, 5 Aug 2024 12:20:34 +0200 [thread overview]
Message-ID: <20240805102046.307511-2-jirislaby@kernel.org> (raw)
In-Reply-To: <20240805102046.307511-1-jirislaby@kernel.org>
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>
---
drivers/tty/tty_io.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index bc9aebcb873f..267682bcfea0 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -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);
--
2.46.0
next prev parent reply other threads:[~2024-08-05 10:20 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-05 10:20 [PATCH 00/13] tty: random fixes and cleanups Jiri Slaby (SUSE)
2024-08-05 10:20 ` Jiri Slaby (SUSE) [this message]
2024-08-05 14:25 ` [PATCH 01/13] tty: simplify tty_dev_name_to_number() using guard(mutex) Ilpo Järvinen
2024-08-05 10:20 ` [PATCH 02/13] serial: protect uart_port_dtr_rts() in uart_shutdown() too Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 03/13] serial: don't use uninitialized value in uart_poll_init() Jiri Slaby (SUSE)
2024-08-05 14:28 ` Ilpo Järvinen
2024-08-05 15:46 ` Doug Anderson
2024-08-08 7:34 ` Jiri Slaby
2024-08-08 7:44 ` Greg Kroah-Hartman
2024-08-08 9:15 ` Ilpo Järvinen
2024-08-05 15:43 ` Doug Anderson
2024-08-05 10:20 ` [PATCH 04/13] serial: remove quot_frac from serial8250_do_set_divisor() Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 05/13] serial: use guards for simple mutex locks Jiri Slaby (SUSE)
2024-08-05 17:57 ` kernel test robot
2024-08-05 18:09 ` kernel test robot
2024-08-07 11:15 ` Greg KH
2024-08-05 10:20 ` [PATCH 06/13] mxser: remove stale comment Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 07/13] mxser: remove doubled sets of close times Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 08/13] mctp: serial: propagage new tty types Jiri Slaby (SUSE)
2024-08-06 4:51 ` Jeremy Kerr
2024-08-08 10:35 ` Jiri Slaby
2024-08-05 10:20 ` [PATCH 09/13] 6pack: remove sixpack::rbuff Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 10/13] 6pack: drop sixpack::mtu Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 11/13] 6pack: drop sixpack::buffsize Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 12/13] 6pack: remove global strings Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 13/13] 6pack: propagage new tty types Jiri Slaby (SUSE)
2024-08-07 11:14 ` [PATCH 00/13] tty: random fixes and cleanups Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240805102046.307511-2-jirislaby@kernel.org \
--to=jirislaby@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox