mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Владислав Корнеев" <vladosov50@yandex.ru>
To: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"jirislaby@kernel.org" <jirislaby@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>
Subject: fix tty device index parsing [PATCH v1]
Date: Sat, 18 Oct 2025 21:51:25 +0700	[thread overview]
Message-ID: <105211760797925@mail.yandex.ru> (raw)

[-- 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


                 reply	other threads:[~2025-10-18 14:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=105211760797925@mail.yandex.ru \
    --to=vladosov50@yandex.ru \
    --cc=gregkh@linuxfoundation.org \
    --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

all inboxes | Powered by JetHome®