linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* fix tty device index parsing [PATCH v1]
@ 2025-10-18 14:51 Владислав Корнеев
  0 siblings, 0 replies; only message in thread
From: Владислав Корнеев @ 2025-10-18 14:51 UTC (permalink / raw)
  To: gregkh@linuxfoundation.org, jirislaby@kernel.org,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org

[-- Attachment #1: Type: text/html, Size: 360 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-tty-fix-device-index-parsing.patch --]
[-- Type: text/x-diff; name="0001-tty-fix-device-index-parsing.patch", Size: 1406 bytes --]

From 29e0ae0b073b3c576b98df8553b0ef9e255d0bec Mon Sep 17 00:00:00 2001
From: Vlados Korneev <vladosov50@yandex.ru>
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 <vladosov50@yandex.ru>
---
 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-10-18 14:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-18 14:51 fix tty device index parsing [PATCH v1] Владислав Корнеев

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).