Skip to contentSkip to conversation

Input: gunze: replace deprecated APIs and fix warning style

PATCH Superseded Bivash Kumar Singh 3 participants 12 messages Jul 18 – Jul 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: gunze: replace deprecated APIs and fix warning style

Replace two uses of simple_strtoul() with kstrtoul() as the former is deprecated. kstrtoul() also properly handles parse errors, so add an early return if parsing fails.

Replace printk(KERN_WARNING) with dev_warn() using the serio device, which is the correct logging style for driver code and removes the redundant 'gunze.c:' filename prefix.

---
 drivers/input/touchscreen/gunze.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/input/touchscreen/gunze.c +7 -3
index 2baeb4f3b941..38450cabdd11 100644
@@ -41,15 +41,19 @@ struct gunze {
 static void gunze_process_packet(struct gunze *gunze)
 {
 	struct input_dev *dev = gunze->dev;
+	unsigned long 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);
+		dev_warn(&gunze->serio->dev, "bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, 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 (kstrtoul(gunze->data + 1, 10, &x) || kstrtoul(gunze->data + 6, 10, &y))
+		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);
 }
Signature · 1 line
2.53.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Replacing simple_strtoul() with kstrtoul() breaks packet parsing by unconditionally returning an…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Replacing simple_strtoul() with kstrtoul() breaks packet parsing by unconditionally returning an error, dropping all touch events. --

--- Patch [1]: [PATCH] Input: gunze: replace deprecated APIs and fix warning style --- commit c6cb2e487b7cdb132629587d8da300e20e580c31
Author: Bivash Kumar Singh <[email protected]>

Input: gunze: replace deprecated APIs and fix warning style

This commit replaces deprecated simple_strtoul() calls with kstrtoul() and adds an early return on parsing failures. It also updates the printk warning to use dev_warn() with the serio device.

Quoted 7 lines
drivers/input/touchscreen/gunze.c +0 -0
index 2baeb4f3b941c..38450cabdd113 100644
@@ -41,15 +41,19 @@ struct gunze {
 static void gunze_process_packet(struct gunze *gunze)
 {

[ ... ]

drivers/input/touchscreen/gunze.c struct gunze { · line 53

Quoted 4 lines
drivers/input/touchscreen/gunze.c +2 -2
-	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 (kstrtoul(gunze->data + 1, 10, &x) || kstrtoul(gunze->data + 6, 10, &y))
+		return;

[Severity: High]
Does this replacement break packet parsing by unconditionally returning an error?

The kstrtoul() API strictly requires the parsed string to be NUL-terminated and contain no trailing non-digit characters other than an optional newline.

Because the input data is a comma-separated string like "T1234,5678" and the buffer is not NUL-terminated, kstrtoul() will encounter the comma when parsing the X coordinate and return -EINVAL. It will also fail when parsing the Y coordinate due to the missing NUL terminator.

This early return will unconditionally trigger on every valid touch event, causing all packets to be dropped and rendering the touchscreen unusable.

Quoted 6 lines
drivers/input/touchscreen/gunze.c +3 -0
+
+	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);
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw

PATCH v2 1/1 Input: gunze: replace deprecated APIs and fix warning style

In reply to Bivash Kumar Singh

Replace two uses of simple_strtoul() with kstrtoul() as the former is deprecated. kstrtoul() also properly handles parse errors, so add an early return if parsing fails.

Replace printk(KERN_WARNING) with dev_warn() using the serio device, which is the correct logging style for driver code and removes the redundant 'gunze.c:' filename prefix.

---
 drivers/input/touchscreen/gunze.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/input/touchscreen/gunze.c +12 -3
index 2baeb4f3b941..e9c028430420 100644
@@ -41,15 +41,24 @@ struct gunze {
 static void gunze_process_packet(struct gunze *gunze)
 {
 	struct input_dev *dev = gunze->dev;
+	char buf[GUNZE_MAX_LENGTH + 1];
+	unsigned long 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);
+		dev_warn(&gunze->serio->dev, "bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, 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));
+	memcpy(buf, gunze->data, GUNZE_MAX_LENGTH);
+	buf[5] = '\0';		/*NULL-terminate X portion: "1234\0" */
+	buf[GUNZE_MAX_LENGTH] = '\0';	/*NULL-terminate Y portion */
+
+	if (kstrtoul(buf + 1, 10, &x) || kstrtoul(buf + 6, 10, &y))
+		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);
 }
Signature · 1 line
2.53.0
#3 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Strict parsing with kstrtoul() and an early return drops packets on non-digit coordinate data…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Strict parsing with kstrtoul() and an early return drops packets on non-digit coordinate data, potentially causing permanently stuck touch states. --

--- Patch [1]: [PATCH v2] Input: gunze: replace deprecated APIs and fix warning style --- commit 448e772e264a7d37aec51432b84a51cdf06f350f
Author: Bivash Kumar Singh <[email protected]>

Input: gunze: replace deprecated APIs and fix warning style

This commit replaces the deprecated simple_strtoul() API with kstrtoul() and updates the logging style to use dev_warn(). It also adds an early return in the packet processing path if coordinate parsing fails.

Quoted 4 lines
drivers/input/touchscreen/gunze.c +0 -0
index 2baeb4f3b941c..e9c028430420c 100644

[ ... ]

Quoted 1 line
drivers/input/touchscreen/gunze.c +0 -0
@@ -41,15 +41,24 @@ static void gunze_process_packet(struct gunze *gunze)

[ ... ]

drivers/input/touchscreen/gunze.c struct gunze { · line 58

Quoted 8 lines
drivers/input/touchscreen/gunze.c +6 -2
-	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));
+	memcpy(buf, gunze->data, GUNZE_MAX_LENGTH);
+	buf[5] = '\0';		/*NULL-terminate X portion: "1234\0" */
+	buf[GUNZE_MAX_LENGTH] = '\0';	/*NULL-terminate Y portion */
+
+	if (kstrtoul(buf + 1, 10, &x) || kstrtoul(buf + 6, 10, &y))
+		return;

[Severity: High]
Could this strict parsing with kstrtoul() and early return drop valid events and cause the touch state to get permanently stuck?

Unlike simple_strtoul(), which stops parsing at the first non-digit character, kstrtoul() will return an error if the string contains trailing spaces or serial line noise.

If a touch release packet (starting with 'R') contains non-digit padding, kstrtoul() will return an error and trigger this early return.

drivers/input/touchscreen/gunze.c struct gunze { · line 63

Quoted 5 lines
drivers/input/touchscreen/gunze.c +3 -0
+
+	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);

Bypassing the BTN_TOUCH state update and input_sync() would cause the touchscreen to remain stuck in a pressed state until a subsequent valid packet is received.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw

PATCH v3 1/1 Input: gunze: replace deprecated APIs and fix warning style

In reply to Bivash Kumar Singh

Replace two uses of simple_strtoul() with kstrtoul() as the former is deprecated. kstrtoul() also properly handles parse errors, so add an early return if parsing fails.

Replace printk(KERN_WARNING) with dev_warn() using the serio device, which is the correct logging style for driver code and removes the redundant 'gunze.c:' filename prefix.

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 | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/input/touchscreen/gunze.c +12 -3
index 2baeb4f3b941..0e8131cad647 100644
@@ -41,15 +41,24 @@ struct gunze {
 static void gunze_process_packet(struct gunze *gunze)
 {
 	struct input_dev *dev = gunze->dev;
+	char buf[GUNZE_MAX_LENGTH + 1];
+	unsigned long 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);
+		dev_warn(&gunze->serio->dev, "bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, 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));
+	memcpy(buf, gunze->data, GUNZE_MAX_LENGTH);
+	buf[5] = '\0';		/* NUL-terminate X portion: "1234\0" */
+	buf[GUNZE_MAX_LENGTH] = '\0';	/* NUL-terminate Y portion */
+
+	if (kstrtoul(buf + 1, 10, &x) || kstrtoul(buf + 6, 10, &y))
+		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);
 }
Signature · 1 line
2.53.0
#5 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The newly added early return on coordinate parsing failure drops critical touch state transitions…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The newly added early return on coordinate parsing failure drops critical touch state transitions (like touch releases), causing stuck touches. --

--- Patch [1]: [PATCH v3] Input: gunze: replace deprecated APIs and fix warning style --- commit 7585c5c9a9ed51c8709aeaa8875aeb5e7e1646b2
Author: Bivash Kumar Singh <[email protected]>

Input: gunze: replace deprecated APIs and fix warning style

This commit replaces deprecated simple_strtoul calls with kstrtoul and adds an early return for parsing failures. It also updates the logging from printk to dev_warn using the serio device.

Quoted 15 lines
drivers/input/touchscreen/gunze.c +3 -1
index 2baeb4f3b941c..0e8131cad647e 100644
@@ -41,15 +41,24 @@ static void gunze_process_packet(struct gunze *gunze)
 {
 	struct input_dev *dev = gunze->dev;
+	char buf[GUNZE_MAX_LENGTH + 1];
+	unsigned long 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);
+		dev_warn(&gunze->serio->dev, "bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, gunze->data);
 		return;

drivers/input/touchscreen/gunze.c static void gunze_process_packet(struct gunze *gunze) · line 57

Quoted 10 lines
drivers/input/touchscreen/gunze.c +6 -2
 	}
 
-	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));
+	memcpy(buf, gunze->data, GUNZE_MAX_LENGTH);
+	buf[5] = '\0';		/* NUL-terminate X portion: "1234\0" */
+	buf[GUNZE_MAX_LENGTH] = '\0';	/* NUL-terminate Y portion */
+
+	if (kstrtoul(buf + 1, 10, &x) || kstrtoul(buf + 6, 10, &y))
+		return;

[Severity: High]
Does this early return risk dropping critical touch state transitions, such as touch releases, causing stuck touches?

If a release packet ('R') contains unparseable coordinates (such as space padding or noise), parsing will fail and trigger this early return.

Because the return bypasses the input_report_key call for BTN_TOUCH and the subsequent input_sync call, the release event would be silently dropped.

Could this leave the touchscreen desynchronized and permanently stuck in the pressed state?

Quoted 6 lines
drivers/input/touchscreen/gunze.c +3 -0
+
+	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);
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#6 lore raw

PATCH v4 1/1 Input: gunze: replace deprecated APIs and fix warning style

In reply to Bivash Kumar Singh

Replace two uses of simple_strtoul() with kstrtoul() as the former is deprecated. kstrtoul() requires a NUL-terminated string, so copy the packet data into a local buffer and NUL-terminate the X and Y fields before parsing. Initialize x and y to 0 so that if parsing fails the coordinates fall back to 0 rather than reporting garbage, and BTN_TOUCH is always updated regardless of parse result.

Replace printk(KERN_WARNING) with dev_warn() using the serio device, which is the correct logging style for driver code and removes the redundant 'gunze.c:' filename prefix.

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.
- Add dev_warn() on kstrtoul() parse failure so errors are logged but BTN_TOUCH is always updated regardless of parse result. (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 | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/input/touchscreen/gunze.c +14 -3
index 2baeb4f3b941..e787209dc965 100644
@@ -41,15 +41,26 @@ struct gunze {
 static void gunze_process_packet(struct gunze *gunze)
 {
 	struct input_dev *dev = gunze->dev;
+	char buf[GUNZE_MAX_LENGTH + 1];
+	unsigned long x = 0, y = 0;
 
 	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);
+		dev_warn(&gunze->serio->dev, "bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, 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));
+	memcpy(buf, gunze->data, GUNZE_MAX_LENGTH);
+	buf[5] = '\0';		/* NUL-terminate X portion: "1234\0" */
+	buf[GUNZE_MAX_LENGTH] = '\0';	/* NUL-terminate Y portion */
+
+	if (kstrtoul(buf + 1, 10, &x))
+		dev_warn(&gunze->serio->dev, "failed to parse X coordinate\n");
+	if (kstrtoul(buf + 6, 10, &y))
+		dev_warn(&gunze->serio->dev, "failed to parse Y coordinate\n");
+
+	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);
 }
Signature · 1 line
2.53.0
#7 lore raw
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] Un-ratelimited dev_warn() calls in the interrupt handler lead to severe kernel log spam (dmesg flooding).
- [High] Replacing simple_strtoul() with kstrtoul() causes a behavioral regression due to strict parsing requirements.

Pre-existing issues:
- [High] Unconditional reporting of fallback coordinates on parse failure causes out-of-bounds values and cursor jumps. --

--- Patch [1]: [PATCH v4] Input: gunze: replace deprecated APIs and fix warning style --- commit 7f14b2c0978a817cc80d8103302866bba7c3bf3f
Author: Bivash Kumar Singh <[email protected]>

Input: gunze: replace deprecated APIs and fix warning style

This commit replaces simple_strtoul() with kstrtoul() by copying the packet data into a local NUL-terminated buffer first. It also updates the logging style from printk() to dev_warn().

Quoted 12 lines
drivers/input/touchscreen/gunze.c +3 -1
@@ -41,15 +41,26 @@ static void gunze_process_packet(struct gunze *gunze)
 	struct input_dev *dev = gunze->dev;
+	char buf[GUNZE_MAX_LENGTH + 1];
+	unsigned long x = 0, y = 0;
 
 	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);
+		dev_warn(&gunze->serio->dev, "bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, gunze->data);

drivers/input/touchscreen/gunze.c static void gunze_process_packet(struct gunze *gunze) · line 55

Quoted 10 lines
drivers/input/touchscreen/gunze.c +5 -2
 		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));
+	memcpy(buf, gunze->data, GUNZE_MAX_LENGTH);
+	buf[5] = '\0';		/* NUL-terminate X portion: "1234\0" */
+	buf[GUNZE_MAX_LENGTH] = '\0';	/* NUL-terminate Y portion */
+
+	if (kstrtoul(buf + 1, 10, &x))

[Severity: High]
In gunze_process_packet(), kstrtoul() requires a perfectly clean string without trailing spaces or non-digit characters, whereas simple_strtoul() would successfully stop parsing at the first non-digit.

If the legacy fixed-width hardware protocol pads coordinates with spaces or contains noisy data, will kstrtoul() reject the entire packet and return -EINVAL, resulting in a loss of valid touch coordinate data?

drivers/input/touchscreen/gunze.c struct gunze { · line 60

Quoted 3 lines
drivers/input/touchscreen/gunze.c +3 -0
+		dev_warn(&gunze->serio->dev, "failed to parse X coordinate\n");
+	if (kstrtoul(buf + 6, 10, &y))
+		dev_warn(&gunze->serio->dev, "failed to parse Y coordinate\n");

[Severity: High]
The commit message mentions that release packets can contain noisy data, meaning parsing failures are an expected event.

Because gunze_process_packet() is called directly from the hardware interrupt handler, could these un-ratelimited dev_warn() calls flood the kernel log and cause high CPU overhead when users interact with the touchscreen?

drivers/input/touchscreen/gunze.c struct gunze { · line 63

Quoted 3 lines
drivers/input/touchscreen/gunze.c +3 -0
+
+	input_report_abs(dev, ABS_X, x);
+	input_report_abs(dev, ABS_Y, 1024 - y);

[Severity: High]
This is a pre-existing issue, but when parsing fails, the y coordinate falls back to 0.

Does unconditionally reporting ABS_Y as 1024 - 0 cause the touch cursor to instantaneously jump out of bounds and trigger spurious clicks or swipe artifacts on the device?

Quoted 3 lines
drivers/input/touchscreen/gunze.c +0 -0
 	input_report_key(dev, BTN_TOUCH, gunze->data[0] == 'T');
 	input_sync(dev);
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#8 lore raw
In reply to Bivash Kumar Singh
Quoted 6 lines · Bivash Kumar Singh

Replace two uses of simple_strtoul() with kstrtoul() as the former is deprecated. kstrtoul() requires a NUL-terminated string, so copy the packet data into a local buffer and NUL-terminate the X and Y fields before parsing. Initialize x and y to 0 so that if parsing fails the coordinates fall back to 0 rather than reporting garbage, and BTN_TOUCH is always updated regardless of parse result.

Please stop forcing use of kstrtoul() where it is not fit. If you want to stop using simple_strtoul() then add '\0' when receive '\r' in gunze_interrupt(), and use

	if (sscanf(gunze->data + 1, "%4u,%4u", &x, &y) != 2) {
		dev_warn_ratelimited(...);
		return;
	}

Thanks.

Signature · 1 line
Dmitry
#9 lore raw

PATCH v5 1/1 Input: gunze: replace deprecated APIs and fix warning style

In reply to Bivash Kumar Singh

Replace printk(KERN_WARNING) with dev_warn_ratelimited() using the serio device, which is the correct logging style for driver code and prevents log spam on noisy serial lines.

Replace simple_strtoul() with sscanf() to parse the comma-separated coordinate data. NUL-terminate the receive buffer in gunze_interrupt() before calling gunze_process_packet() so sscanf() and the warning message can safely treat the data as a string.

---
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 | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/input/touchscreen/gunze.c +11 -5
index 2baeb4f3b941..7a92052eba80 100644
@@ -41,15 +41,20 @@ struct gunze {
 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);
+		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 +65,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 {
Signature · 1 line
2.53.0
#10 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Off-by-one buffer overflow when NUL-terminating the receive buffer corrupts the device physical…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Off-by-one buffer overflow when NUL-terminating the receive buffer corrupts the device physical path.
- [High] Early return on coordinate parsing failure drops malformed release packets, permanently sticking the touch state. --

--- Patch [1]: [PATCH v5] Input: gunze: replace deprecated APIs and fix warning style --- commit e46d9a0baa3ae281ee5b9c02aad4e7f63a5cf33f
Author: Bivash Kumar Singh <[email protected]>

Input: gunze: replace deprecated APIs and fix warning style

This commit updates the driver to use dev_warn_ratelimited() instead of printk() and replaces simple_strtoul() with sscanf() for parsing coordinate data. It also NUL-terminates the receive buffer to allow safe string parsing.

Quoted 14 lines
drivers/input/touchscreen/gunze.c +2 -3
index 2baeb4f3b941c..7a92052eba805 100644
@@ -41,15 +41,20 @@ struct gunze {
 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') {

drivers/input/touchscreen/gunze.c struct gunze { · line 54

Quoted 10 lines
drivers/input/touchscreen/gunze.c +5 -2
+		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);
+		return;
+	}

[Severity: High]
Does this early return risk leaving the touch state permanently stuck?

If a release packet (starting with 'R') is received but the coordinate data contains noise causing sscanf() to fail, this will return early and skip the input_report_key() call below, dropping the release event.

drivers/input/touchscreen/gunze.c static irqreturn_t gunze_interrupt(struct serio *serio, · line 68

Quoted 11 lines
drivers/input/touchscreen/gunze.c +4 -0
+
+	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 +65,7 @@ static irqreturn_t gunze_interrupt(struct serio *serio,
 	struct gunze *gunze = serio_get_drvdata(serio);
 
 	if (data == '\r') {
+		gunze->data[gunze->idx] = '\0';

[Severity: High]
Can this write past the end of the data array and corrupt the physical path?

The data array in struct gunze is sized exactly to GUNZE_MAX_LENGTH (10):

struct gunze {
	...
	unsigned char data[GUNZE_MAX_LENGTH];
	char phys[32];
};

When a full-length valid touch packet is received followed by a '\r', gunze->idx will be 10. Writing '\0' at this index will write out of bounds and overwrite the adjacent phys array. Could the array size be increased to accommodate the NUL terminator?

Quoted 3 lines
drivers/input/touchscreen/gunze.c +0 -0
 		gunze_process_packet(gunze);
 		gunze->idx = 0;
 	} else {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#11 lore raw

PATCH v6 1/1 Input: gunze: replace deprecated APIs and fix warning style

In reply to Bivash Kumar Singh

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.

---
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(-)
drivers/input/touchscreen/gunze.c +16 -6
index 2baeb4f3b941..e2b1e1d970c6 100644
@@ -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 {
Signature · 1 line
2.53.0