fix tty device index parsing [PATCH v1]
Hello.I am sending you the patch which fixes incorrect device index parsing in tty_dev_name_to_number().Thank you for your time and attention. I am looking forward to any comments or suggestions for improvement.Sorry for any mistakes, this is my first patch.
From 29e0ae0b073b3c576b98df8553b0ef9e255d0bec Mon Sep 17 00:00:00 2001
From: Vlados Korneev <[email protected]>
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"--- drivers/tty/tty_io.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/tty/tty_io.c +3 -2
@@ -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 ;
Signature · 1 line
2.34.1