platform/chrome: cros_ec_lightbar: replace sscanf with kstrtouint
Subsystems (2)
PATCH 1/1 platform/chrome: cros_ec_lightbar: replace sscanf with kstrtouint
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.
--- drivers/platform/chrome/cros_ec_lightbar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_lightbar.c +2 -2
@@ -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 ;
Signature · 1 line
2.43.0
Tzung-Bi Shih
maintainerQuoted 5 lines · trunix-creator
Replace the use of
sscanf()withkstrtouint(), 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 <[email protected]>
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).
drivers/platform/chrome/cros_ec_lightbar.c static ssize_t led_rgb_store(struct device *dev, struct device_attribute *attr, · line 248
Quoted 8 lines
drivers/platform/chrome/cros_ec_lightbar.c +1
-1@@ -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.
drivers/platform/chrome/cros_ec_lightbar.c static ssize_t led_rgb_store(struct device *dev, struct device_attribute *attr, · line 249
Quoted 2 lines
drivers/platform/chrome/cros_ec_lightbar.c +1
-1- + i++;
Why it moves the increment to here? It seems unrelated to the patch.