Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH] Input: gunze: replace deprecated APIs and fix warning style
@ 2026-07-18 19:00 Bivash Kumar Singh
  2026-07-18 19:12 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Bivash Kumar Singh @ 2026-07-18 19:00 UTC (permalink / raw)
  To: linux-input; +Cc: dmitry.torokhov, 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.

Signed-off-by: Bivash Kumar Singh <bivashraj750@gmail.com>
---
 drivers/input/touchscreen/gunze.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/input/touchscreen/gunze.c b/drivers/input/touchscreen/gunze.c
index 2baeb4f3b941..38450cabdd11 100644
--- a/drivers/input/touchscreen/gunze.c
+++ b/drivers/input/touchscreen/gunze.c
@@ -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);
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Input: gunze: replace deprecated APIs and fix warning style
  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  6:02 ` [PATCH v3] " Bivash Kumar Singh
  2 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-07-18 19:12 UTC (permalink / raw)
  To: Bivash Kumar Singh; +Cc: linux-input, dmitry.torokhov

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 <bivashraj750@gmail.com>

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.

> diff --git a/drivers/input/touchscreen/gunze.c b/drivers/input/touchscreen/gunze.c
> index 2baeb4f3b941c..38450cabdd113 100644
> --- a/drivers/input/touchscreen/gunze.c
> +++ b/drivers/input/touchscreen/gunze.c
> @@ -41,15 +41,19 @@ struct gunze {
>  static void gunze_process_packet(struct gunze *gunze)
>  {
[ ... ]
> -	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.

> +
> +	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);
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260718190040.10613-1-bivashraj750@gmail.com?part=1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] Input: gunze: replace deprecated APIs and fix warning style
  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 ` Bivash Kumar Singh
  2026-07-19  5:53   ` sashiko-bot
  2026-07-19  6:02 ` [PATCH v3] " Bivash Kumar Singh
  2 siblings, 1 reply; 6+ messages in thread
From: Bivash Kumar Singh @ 2026-07-19  5:41 UTC (permalink / raw)
  To: linux-input; +Cc: dmitry.torokhov, 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.

Signed-off-by: Bivash Kumar Singh <bivashraj750@gmail.com>
---
 drivers/input/touchscreen/gunze.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/input/touchscreen/gunze.c b/drivers/input/touchscreen/gunze.c
index 2baeb4f3b941..e9c028430420 100644
--- a/drivers/input/touchscreen/gunze.c
+++ b/drivers/input/touchscreen/gunze.c
@@ -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);
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] Input: gunze: replace deprecated APIs and fix warning style
  2026-07-19  5:41 ` [PATCH v2] " Bivash Kumar Singh
@ 2026-07-19  5:53   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-07-19  5:53 UTC (permalink / raw)
  To: Bivash Kumar Singh; +Cc: dmitry.torokhov, linux-input

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 <bivashraj750@gmail.com>

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.

> diff --git a/drivers/input/touchscreen/gunze.c b/drivers/input/touchscreen/gunze.c
> index 2baeb4f3b941c..e9c028430420c 100644
> --- a/drivers/input/touchscreen/gunze.c
> +++ b/drivers/input/touchscreen/gunze.c
[ ... ]
> @@ -41,15 +41,24 @@ static void gunze_process_packet(struct gunze *gunze)
[ ... ]
> -	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.

> +
> +	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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260719054121.5917-1-bivashraj750@gmail.com?part=1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3] Input: gunze: replace deprecated APIs and fix warning style
  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  6:02 ` Bivash Kumar Singh
  2026-07-19  6:13   ` sashiko-bot
  2 siblings, 1 reply; 6+ messages in thread
From: Bivash Kumar Singh @ 2026-07-19  6:02 UTC (permalink / raw)
  To: linux-input; +Cc: dmitry.torokhov, 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.

Signed-off-by: Bivash Kumar Singh <bivashraj750@gmail.com>

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(-)

diff --git a/drivers/input/touchscreen/gunze.c b/drivers/input/touchscreen/gunze.c
index 2baeb4f3b941..0e8131cad647 100644
--- a/drivers/input/touchscreen/gunze.c
+++ b/drivers/input/touchscreen/gunze.c
@@ -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);
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] Input: gunze: replace deprecated APIs and fix warning style
  2026-07-19  6:02 ` [PATCH v3] " Bivash Kumar Singh
@ 2026-07-19  6:13   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-07-19  6:13 UTC (permalink / raw)
  To: Bivash Kumar Singh; +Cc: linux-input, dmitry.torokhov

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 <bivashraj750@gmail.com>

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.

> diff --git a/drivers/input/touchscreen/gunze.c b/drivers/input/touchscreen/gunze.c
> index 2baeb4f3b941c..0e8131cad647e 100644
> --- a/drivers/input/touchscreen/gunze.c
> +++ b/drivers/input/touchscreen/gunze.c
> @@ -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;
>  	}
>  
> -	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?

> +
> +	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);
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260719060238.6440-1-bivashraj750@gmail.com?part=1

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-19  6:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox