* [PATCH] platform/chrome: cros_ec_lightbar: replace sscanf with kstrtouint
@ 2026-02-08 22:13 trunix-creator
2026-02-23 8:17 ` Tzung-Bi Shih
0 siblings, 1 reply; 2+ messages in thread
From: trunix-creator @ 2026-02-08 22:13 UTC (permalink / raw)
To: bleung; +Cc: tzungbi, groeck, chrome-platform, linux-kernel, trunix-creator
Replace the use of sscanf() with kstrtouint(), which is the favored kernel
API for parsing integers from strings. This avoids format string parsing
overhead and improves robustness.
Signed-off-by: trunix-creator <trunixcodes@zohomail.com>
---
drivers/platform/chrome/cros_ec_lightbar.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platform/chrome/cros_ec_lightbar.c
index 922758c2cec1..e455ff440b11 100644
--- a/drivers/platform/chrome/cros_ec_lightbar.c
+++ b/drivers/platform/chrome/cros_ec_lightbar.c
@@ -243,10 +243,10 @@ static ssize_t led_rgb_store(struct device *dev, struct device_attribute *attr,
if (!*buf)
break;
- ret = sscanf(buf, "%i", &val[i++]);
+ ret = kstrtouint(buf, 0, &val[i]);
if (ret == 0)
goto exit;
-
+ i++;
if (i == 4) {
param = (struct ec_params_lightbar *)msg->data;
param->cmd = LIGHTBAR_CMD_SET_RGB;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] platform/chrome: cros_ec_lightbar: replace sscanf with kstrtouint
2026-02-08 22:13 [PATCH] platform/chrome: cros_ec_lightbar: replace sscanf with kstrtouint trunix-creator
@ 2026-02-23 8:17 ` Tzung-Bi Shih
0 siblings, 0 replies; 2+ messages in thread
From: Tzung-Bi Shih @ 2026-02-23 8:17 UTC (permalink / raw)
To: trunix-creator; +Cc: bleung, groeck, chrome-platform, linux-kernel
On Sun, Feb 08, 2026 at 02:13:35PM -0800, trunix-creator wrote:
> Replace the use of sscanf() with kstrtouint(), which is the favored kernel
> API for parsing integers from strings. This avoids format string parsing
> overhead and improves robustness.
>
> Signed-off-by: trunix-creator <trunixcodes@zohomail.com>
Thanks for the patch.
Before this can be considered for merging, you'll need to update the
Signed-off-by line. The kernel community requires the use of your real
name (legal name) rather than a handle (see also "Developer's Certificate
of Origin" in Documentation/process/submitting-patches.rst).
> @@ -243,10 +243,10 @@ static ssize_t led_rgb_store(struct device *dev, struct device_attribute *attr,
> if (!*buf)
> break;
>
> - ret = sscanf(buf, "%i", &val[i++]);
> + ret = kstrtouint(buf, 0, &val[i]);
> if (ret == 0)
> goto exit;
This is incorrect. `sscanf` returns the number of items matched (e.g., 1 on
success in the case). `kstrtouint` returns 0 on success.
> -
> + i++;
Why it moves the increment to here? It seems unrelated to the patch.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-23 8:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-08 22:13 [PATCH] platform/chrome: cros_ec_lightbar: replace sscanf with kstrtouint trunix-creator
2026-02-23 8:17 ` Tzung-Bi Shih
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox