public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
	Pavel Machek <pavel@ucw.cz>
Subject: Re: [PATCH v1 2/4] leds: trigger: gpio: Convert to use kstrtox()
Date: Thu, 23 Nov 2023 11:05:38 +0000	[thread overview]
Message-ID: <20231123110538.GA1243364@google.com> (raw)
In-Reply-To: <20231103195310.948327-2-andriy.shevchenko@linux.intel.com>

On Fri, 03 Nov 2023, Andy Shevchenko wrote:

> sscanf() is a heavy one and moreover requires additional boundary checks.
> Convert driver to use kstrtou8() in gpio_trig_inverted_store().
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/leds/trigger/ledtrig-gpio.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/leds/trigger/ledtrig-gpio.c b/drivers/leds/trigger/ledtrig-gpio.c
> index d91ae7fde3cf..8a30f9228186 100644
> --- a/drivers/leds/trigger/ledtrig-gpio.c
> +++ b/drivers/leds/trigger/ledtrig-gpio.c
> @@ -53,14 +53,12 @@ static ssize_t gpio_trig_brightness_store(struct device *dev,
>  		struct device_attribute *attr, const char *buf, size_t n)
>  {
>  	struct gpio_trig_data *gpio_data = led_trigger_get_drvdata(dev);
> -	unsigned desired_brightness;
> +	u8 desired_brightness;
>  	int ret;
>  
> -	ret = sscanf(buf, "%u", &desired_brightness);
> -	if (ret < 1 || desired_brightness > 255) {
> -		dev_err(dev, "invalid value\n");
> -		return -EINVAL;
> -	}
> +	ret = kstrtou8(buf, 10, &desired_brightness);

Where does 10 come from?

> +	if (ret)
> +		return ret;
>  
>  	gpio_data->desired_brightness = desired_brightness;
>  
> -- 
> 2.40.0.1.gaa8946217a0b
> 

-- 
Lee Jones [李琼斯]

  parent reply	other threads:[~2023-11-23 11:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-03 19:53 [PATCH v1 1/4] leds: trigger: gpio: Replace custom code for gpiod_get_optional() Andy Shevchenko
2023-11-03 19:53 ` [PATCH v1 2/4] leds: trigger: gpio: Convert to use kstrtox() Andy Shevchenko
2023-11-04 22:26   ` Linus Walleij
2023-11-23 11:05   ` Lee Jones [this message]
2023-11-23 14:11     ` Andy Shevchenko
2023-11-23 14:47       ` Lee Jones
2023-11-03 19:53 ` [PATCH v1 3/4] leds: trigger: gpio: Use sysfs_emit() to instead of s*printf() Andy Shevchenko
2023-11-04 22:24   ` Linus Walleij
2023-11-03 19:53 ` [PATCH v1 4/4] leds: trigger: gpio: Convert to DEVICE_ATTR_RW() Andy Shevchenko
2023-11-04 22:26   ` Linus Walleij
2023-11-04 22:26 ` [PATCH v1 1/4] leds: trigger: gpio: Replace custom code for gpiod_get_optional() Linus Walleij
2023-11-23 14:48 ` Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231123110538.GA1243364@google.com \
    --to=lee@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox