[PATCH 2/2] serial: earlycon: Use isdigit() in earlycon_init()
From: Thorsten Blum
Date: Wed Oct 14 2026 - 10:31:29 EST
Use isdigit() and a while loop to simplify the backward scan.
Signed-off-by: Thorsten Blum <blum@xxxxxxxxxx>
---
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;