Linux Serial subsystem development
 help / color / mirror / Atom feed
From: Thorsten Blum <blum@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	Hugo Villeneuve <hvilleneuve@dimonoff.com>
Cc: Thorsten Blum <blum@kernel.org>,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: [PATCH 2/2] serial: earlycon: Use isdigit() in earlycon_init()
Date: Wed, 14 Oct 2026 16:30:33 +0200	[thread overview]
Message-ID: <20261014143034.104950-4-blum@kernel.org> (raw)
In-Reply-To: <20261014143034.104950-3-blum@kernel.org>

Use isdigit() and a while loop to simplify the backward scan.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/tty/serial/earlycon.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
index ce740cdc7ceb..05d99ec6e709 100644
--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -11,6 +11,7 @@
 #define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
 
 #include <linux/console.h>
+#include <linux/ctype.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/io.h>
@@ -59,11 +60,10 @@ static void __init earlycon_init(struct earlycon_device *device,
 	const char *s;
 	size_t len;
 
-	/* scan backwards from end of string for first non-numeral */
-	for (s = name + strlen(name);
-	     s > name && s[-1] >= '0' && s[-1] <= '9';
-	     s--)
-		;
+	/* Scan backwards to split the trailing index from the console name. */
+	s = name + strlen(name);
+	while (s > name && isdigit(s[-1]))
+		s--;
 	if (*s)
 		earlycon->index = simple_strtoul(s, NULL, 10);
 	len = s - name;

  reply	other threads:[~2026-10-14 14:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 14:30 [PATCH 1/2] serial: core: Use isdigit() in uart_parse_options() Thorsten Blum
2026-10-14 14:30 ` Thorsten Blum [this message]
2026-10-14 14:34   ` [PATCH 2/2] serial: earlycon: Use isdigit() in earlycon_init() sashiko-bot
2026-10-14 14:35 ` [PATCH 1/2] serial: core: Use isdigit() in uart_parse_options() sashiko-bot
2026-10-14 14:54 ` John Ogness

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=20261014143034.104950-4-blum@kernel.org \
    --to=blum@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hvilleneuve@dimonoff.com \
    --cc=jirislaby@kernel.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