Linux Input/HID development
 help / color / mirror / Atom feed
From: Bivash Kumar Singh <bivashraj750@gmail.com>
To: linux-input@vger.kernel.org
Cc: dmitry.torokhov@gmail.com, Bivash Kumar Singh <bivashraj750@gmail.com>
Subject: [PATCH v6] Input: gunze: replace deprecated APIs and fix warning style
Date: Fri, 24 Jul 2026 00:10:52 +0530	[thread overview]
Message-ID: <20260723184052.5144-1-bivashraj750@gmail.com> (raw)
In-Reply-To: <20260718190040.10613-1-bivashraj750@gmail.com>

Replace printk(KERN_WARNING) with dev_warn_ratelimited(), and
simple_strtoul() with sscanf() to parse the coordinate data.
NUL-terminate the receive buffer in gunze_interrupt() so it can
safely be treated as a string.

Enlarge gunze->data by one byte to avoid the NUL terminator
overflowing into the adjacent phys field. Also report BTN_TOUCH
release on a corrupted 'R' packet so touch state can't get stuck
down.

Signed-off-by: Bivash Kumar Singh <bivashraj750@gmail.com>
---
Changes in v6:
  - Enlarge gunze->data[] by one byte (GUNZE_MAX_LENGTH + 1) to fix
    an off-by-one overflow: NUL-terminating a full-length packet at
    gunze->data[gunze->idx] wrote one byte past the array into the
    adjacent phys field. (reported by Sashiko AI review)
  - Restore BTN_TOUCH release reporting when sscanf() fails to parse
    coordinates on a release ('R') packet, so touch state cannot get
    stuck down.

Changes in v5:
  - Switch from kstrtoul() to sscanf() as suggested by Dmitry Torokhov.
    sscanf() naturally handles comma-separated coordinate data without
    needing a local buffer copy or manual NUL termination tricks.
  - NUL-terminate receive buffer in gunze_interrupt() before processing.
  - Use dev_warn_ratelimited() to prevent log spam on noisy serial lines.

Changes in v4:
  - Remove early return on kstrtoul() failure to prevent touch state
    getting permanently stuck if a release packet contains noisy data.
    Initialize x and y to 0 as safe fallback values instead.
    (reported by Sashiko AI review)

Changes in v3:
  - Fix comment style: add space after /* and use NUL instead of NULL
  - Add missing Changes section that was absent in v2

Changes in v2:
  - Copy packet data to a local NUL-terminated buffer before calling
    kstrtoul(), so the comma separator does not cause parsing to fail
    on every valid touch event. (reported by Sashiko AI review)
---
 drivers/input/touchscreen/gunze.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/input/touchscreen/gunze.c b/drivers/input/touchscreen/gunze.c
index 2baeb4f3b941..e2b1e1d970c6 100644
--- a/drivers/input/touchscreen/gunze.c
+++ b/drivers/input/touchscreen/gunze.c
@@ -34,22 +34,31 @@ struct gunze {
 	struct input_dev *dev;
 	struct serio *serio;
 	int idx;
-	unsigned char data[GUNZE_MAX_LENGTH];
+	unsigned char data[GUNZE_MAX_LENGTH + 1];
 	char phys[32];
 };
 
 static void gunze_process_packet(struct gunze *gunze)
 {
 	struct input_dev *dev = gunze->dev;
+	unsigned int x, y;
 
-	if (gunze->idx != GUNZE_MAX_LENGTH || gunze->data[5] != ',' ||
-		(gunze->data[0] != 'T' && gunze->data[0] != 'R')) {
-		printk(KERN_WARNING "gunze.c: bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, gunze->data);
+	if (gunze->data[0] != 'T' && gunze->data[0] != 'R') {
+		dev_warn_ratelimited(&gunze->serio->dev, "bad packet: >%s<\n", gunze->data);
 		return;
 	}
 
-	input_report_abs(dev, ABS_X, simple_strtoul(gunze->data + 1, NULL, 10));
-	input_report_abs(dev, ABS_Y, 1024 - simple_strtoul(gunze->data + 6, NULL, 10));
+	if (sscanf(gunze->data + 1, "%4u,%4u", &x, &y) != 2) {
+		dev_warn_ratelimited(&gunze->serio->dev, "bad packet: >%s<\n", gunze->data);
+		if (gunze->data[0] == 'R') {
+			input_report_key(dev, BTN_TOUCH, 0);
+			input_sync(dev);
+		}
+		return;
+	}
+
+	input_report_abs(dev, ABS_X, x);
+	input_report_abs(dev, ABS_Y, 1024 - y);
 	input_report_key(dev, BTN_TOUCH, gunze->data[0] == 'T');
 	input_sync(dev);
 }
@@ -60,6 +69,7 @@ static irqreturn_t gunze_interrupt(struct serio *serio,
 	struct gunze *gunze = serio_get_drvdata(serio);
 
 	if (data == '\r') {
+		gunze->data[gunze->idx] = '\0';
 		gunze_process_packet(gunze);
 		gunze->idx = 0;
 	} else {
-- 
2.53.0


      parent reply	other threads:[~2026-07-23 18:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-18 19:00 [PATCH] Input: gunze: replace deprecated APIs and fix warning style Bivash Kumar Singh
2026-07-18 19:12 ` sashiko-bot
2026-07-19  5:41 ` [PATCH v2] " Bivash Kumar Singh
2026-07-19  5:53   ` sashiko-bot
2026-07-19  6:02 ` [PATCH v3] " Bivash Kumar Singh
2026-07-19  6:13   ` sashiko-bot
2026-07-19 17:37 ` [PATCH v4] " Bivash Kumar Singh
2026-07-19 17:54   ` sashiko-bot
2026-07-20  1:24   ` Dmitry Torokhov
2026-07-20  3:24 ` [PATCH v5] " Bivash Kumar Singh
2026-07-20  3:32   ` sashiko-bot
2026-07-23 18:40 ` Bivash Kumar Singh [this message]

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=20260723184052.5144-1-bivashraj750@gmail.com \
    --to=bivashraj750@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@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