mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nicolas Pitre <nico@fluxnic.net>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>
Cc: Nicolas Pitre <npitre@baylibre.com>,
	linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 01/14] vt: minor cleanup to vc_translate_unicode()
Date: Thu, 17 Apr 2025 14:45:03 -0400	[thread overview]
Message-ID: <20250417184849.475581-2-nico@fluxnic.net> (raw)
In-Reply-To: <20250417184849.475581-1-nico@fluxnic.net>

From: Nicolas Pitre <npitre@baylibre.com>

Make it clearer when a sequence is bad.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
---
 drivers/tty/vt/vt.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index f5642b3038..b5f3c8a818 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -2817,7 +2817,7 @@ static int vc_translate_unicode(struct vc_data *vc, int c, bool *rescan)
 	if ((c & 0xc0) == 0x80) {
 		/* Unexpected continuation byte? */
 		if (!vc->vc_utf_count)
-			return 0xfffd;
+			goto bad_sequence;
 
 		vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f);
 		vc->vc_npar++;
@@ -2829,17 +2829,17 @@ static int vc_translate_unicode(struct vc_data *vc, int c, bool *rescan)
 		/* Reject overlong sequences */
 		if (c <= utf8_length_changes[vc->vc_npar - 1] ||
 				c > utf8_length_changes[vc->vc_npar])
-			return 0xfffd;
+			goto bad_sequence;
 
 		return vc_sanitize_unicode(c);
 	}
 
 	/* Single ASCII byte or first byte of a sequence received */
 	if (vc->vc_utf_count) {
-		/* Continuation byte expected */
+		/* A continuation byte was expected */
 		*rescan = true;
 		vc->vc_utf_count = 0;
-		return 0xfffd;
+		goto bad_sequence;
 	}
 
 	/* Nothing to do if an ASCII byte was received */
@@ -2858,11 +2858,14 @@ static int vc_translate_unicode(struct vc_data *vc, int c, bool *rescan)
 		vc->vc_utf_count = 3;
 		vc->vc_utf_char = (c & 0x07);
 	} else {
-		return 0xfffd;
+		goto bad_sequence;
 	}
 
 need_more_bytes:
 	return -1;
+
+bad_sequence:
+	return 0xfffd;
 }
 
 static int vc_translate(struct vc_data *vc, int *c, bool *rescan)
-- 
2.49.0


  reply	other threads:[~2025-04-17 18:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-17 18:45 [PATCH v3 00/14] vt: implement proper Unicode handling Nicolas Pitre
2025-04-17 18:45 ` Nicolas Pitre [this message]
2025-04-17 18:45 ` [PATCH v3 02/14] vt: move unicode processing to a separate file Nicolas Pitre
2025-04-17 18:45 ` [PATCH v3 03/14] vt: properly support zero-width Unicode code points Nicolas Pitre
2025-04-17 18:45 ` [PATCH v3 04/14] vt: introduce gen_ucs_width_table.py to create ucs_width_table.h Nicolas Pitre
2025-04-17 18:45 ` [PATCH v3 05/14] vt: create ucs_width_table.h with gen_ucs_width_table.py Nicolas Pitre
2025-04-17 18:45 ` [PATCH v3 06/14] vt: use new tables in ucs.c Nicolas Pitre
2025-04-17 18:45 ` [PATCH v3 07/14] vt: introduce gen_ucs_recompose_table.py to create ucs_recompose_table.h Nicolas Pitre
2025-04-17 18:45 ` [PATCH v3 08/14] vt: create ucs_recompose_table.h with gen_ucs_recompose_table.py Nicolas Pitre
2025-04-17 18:45 ` [PATCH v3 09/14] vt: support Unicode recomposition Nicolas Pitre
2025-04-17 18:45 ` [PATCH v3 10/14] vt: pad double-width code points with a zero-width space Nicolas Pitre
2025-04-17 18:45 ` [PATCH v3 11/14] vt: remove zero-width-space handling from conv_uni_to_pc() Nicolas Pitre
2025-04-17 18:45 ` [PATCH v3 12/14] vt: update gen_ucs_width_table.py to make tables more space efficient Nicolas Pitre
2025-04-17 18:45 ` [PATCH v3 13/14] vt: refresh ucs_width_table.h and adjust code in ucs.c accordingly Nicolas Pitre
2025-04-17 18:45 ` [PATCH v3 14/14] vt: move UCS tables to the "shipped" form Nicolas Pitre
2025-04-25 14:29 ` [PATCH v3 00/14] vt: implement proper Unicode handling Greg Kroah-Hartman
2025-04-25 16:13   ` Nicolas Pitre
2025-04-26  9:24     ` Greg Kroah-Hartman

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=20250417184849.475581-2-nico@fluxnic.net \
    --to=nico@fluxnic.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=npitre@baylibre.com \
    /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®