From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Pavel Machek <pavel@ucw.cz>, Dan Murphy <dmurphy@ti.com>,
linux-leds@vger.kernel.org
Subject: Re: [PATCH v1 2/2] leds: trigger: gpio: Convert to use kstrtox()
Date: Sat, 24 Aug 2019 18:51:10 +0200 [thread overview]
Message-ID: <fcac91ba-5048-912f-47b4-490421f04fc1@gmail.com> (raw)
In-Reply-To: <20190821171727.87886-2-andriy.shevchenko@linux.intel.com>
Hi Andy,
Thank you for the patch.
On 8/21/19 7:17 PM, Andy Shevchenko wrote:
> sscanf() is a heavy one and moreover requires additional boundary checks.
> Convert driver to use kstrtox() and replace kstrtoul() by kstrtobool() in
> gpio_trig_inverted_store()
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> drivers/leds/trigger/ledtrig-gpio.c | 23 ++++++++++-------------
> 1 file changed, 10 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/leds/trigger/ledtrig-gpio.c b/drivers/leds/trigger/ledtrig-gpio.c
> index 31f456dd4417..b01862b94c99 100644
> --- a/drivers/leds/trigger/ledtrig-gpio.c
> +++ b/drivers/leds/trigger/ledtrig-gpio.c
> @@ -57,13 +57,13 @@ 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) {
LED_FULL (255) is already not a hard limit for quite a long time.
While we are at it we could change that to led->max_brightness.
> + ret = kstrtou8(buf, 10, &desired_brightness);
> + if (ret) {
> dev_err(dev, "invalid value\n");
> - return -EINVAL;
> + return ret;
> }
>
> gpio_data->desired_brightness = desired_brightness;
> @@ -86,16 +86,13 @@ static ssize_t gpio_trig_inverted_store(struct device *dev,
> {
> struct led_classdev *led = led_trigger_get_led(dev);
> struct gpio_trig_data *gpio_data = led_trigger_get_drvdata(dev);
> - unsigned long inverted;
> + bool inverted;
> int ret;
>
> - ret = kstrtoul(buf, 10, &inverted);
> - if (ret < 0)
> + ret = kstrtobool(buf, &inverted);
> + if (ret)
> return ret;
>
> - if (inverted > 1)
> - return -EINVAL;
> -
> gpio_data->inverted = inverted;
>
> /* After inverting, we need to update the LED. */
> @@ -122,10 +119,10 @@ static ssize_t gpio_trig_gpio_store(struct device *dev,
> unsigned gpio;
> int ret;
>
> - ret = sscanf(buf, "%u", &gpio);
> - if (ret < 1) {
> + ret = kstrtouint(buf, 10, &gpio);
> + if (ret) {
> dev_err(dev, "couldn't read gpio number\n");
> - return -EINVAL;
> + return ret;
> }
>
> if (gpio_data->gpio == gpio)
>
--
Best regards,
Jacek Anaszewski
next prev parent reply other threads:[~2019-08-24 16:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-21 17:17 [PATCH v1 1/2] leds: trigger: gpio: GPIO 0 is valid Andy Shevchenko
2019-08-21 17:17 ` [PATCH v1 2/2] leds: trigger: gpio: Convert to use kstrtox() Andy Shevchenko
2019-08-24 16:51 ` Jacek Anaszewski [this message]
2019-08-24 16:47 ` [PATCH v1 1/2] leds: trigger: gpio: GPIO 0 is valid Jacek Anaszewski
2019-08-26 9:57 ` Andy Shevchenko
2019-08-26 18:36 ` Jacek Anaszewski
2019-08-30 15:01 ` Andy Shevchenko
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=fcac91ba-5048-912f-47b4-490421f04fc1@gmail.com \
--to=jacek.anaszewski@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dmurphy@ti.com \
--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;
as well as URLs for NNTP newsgroup(s).