From 29e0ae0b073b3c576b98df8553b0ef9e255d0bec Mon Sep 17 00:00:00 2001 From: Vlados Korneev Date: Sat, 18 Oct 2025 21:16:50 +0700 Subject: [PATCH] tty: fix device index parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, searched for the first digit in the device name to determine the index. This caused incorrect parsing for device names that contain digits before the index, such as "ttyCH9344USB0" or "ttyCH9344USB10". The logic is updated to scan backwards from the end of the string and locate the start of the last contiguous sequence of digits, ensuring the correct device number is extracted. Example: Before: "ttyCH9344USB10" → parsed as "9344USB10" After: "ttyCH9344USB10" → parsed as "10" Signed-off-by: Vlados Korneev --- drivers/tty/tty_io.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index e2d92cf70eb7..25aa93a16349 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -338,8 +338,9 @@ int tty_dev_name_to_number(const char *name, dev_t *number) int index, prefix_length = 0; const char *str; - for (str = name; *str && !isdigit(*str); str++) - ; + str = name + strlen(name); + while (str > name && isdigit(*(str - 1))) + str--; if (!*str) return -EINVAL; -- 2.34.1