Re: [PATCH] platform/chrome: cros_ec_lightbar: replace sscanf with kstrtouint
From: Tzung-Bi Shih
Date: Mon Feb 23 2026 - 03:17:37 EST
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@xxxxxxxxxxxx>
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.