From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
To: Pavel Machek <pavel@ucw.cz>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Dan Murphy <dmurphy@ti.com>, linux-leds@vger.kernel.org
Subject: Re: [PATCH v2 2/2] leds: trigger: gpio: Convert to use kstrtox()
Date: Sun, 1 Sep 2019 13:41:10 +0200 [thread overview]
Message-ID: <afd5eeae-5b83-f9d0-f689-aa49c628a514@gmail.com> (raw)
In-Reply-To: <b55b68cb-0c0b-ff5b-a4c3-d98c41b70b9f@gmail.com>
On 9/1/19 1:36 PM, Jacek Anaszewski wrote:
> Hi Pavel,
>
> On 9/1/19 12:23 PM, Pavel Machek wrote:
>> On Fri 2019-08-30 18:08:20, 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().
>>>
>>> While here, check the desired brightness against maximum defined for
>>> a certain LED.
>>
>> One change per patch, please.
>>
>> Because this one will not end well.
>>
>>> @@ -60,10 +60,10 @@ static ssize_t gpio_trig_brightness_store(struct device *dev,
>>> unsigned desired_brightness;
>>> int ret;
>>>
>>> - ret = sscanf(buf, "%u", &desired_brightness);
>>> - if (ret < 1 || desired_brightness > 255) {
>>> + ret = kstrtouint(buf, 10, &desired_brightness);
>>> + if (ret || desired_brightness > gpio_data->led->max_brightness) {
>>> dev_err(dev, "invalid value\n");
>>> - return -EINVAL;
>>> + return ret ? ret : -EINVAL;
>>> }
>>
>> We have people writing 255 into brightness, because that's what we
>> used to do even for on/off LEDS. It is expected to work even for leds
>> with max_brightness of 1.
>>
>> So... we want to saturate here, not return -EINVAL. (And we will
>> eventually want to switch on/off leds to max_brightness = 1...)
>
> Good point. We shouldn't fail here but proceed similarly as in case
> of setting brightness for a LED in led_set_brightness_nosleep(), i.e.
> here it should be:
>
> desired_brightness = min(desired_brightness,
> gpio_data->led->->max_brightness);
PS. Dropped the patch.
--
Best regards,
Jacek Anaszewski
next prev parent reply other threads:[~2019-09-01 11:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-30 15:08 [PATCH v2 1/2] leds: trigger: gpio: GPIO 0 is valid Andy Shevchenko
2019-08-30 15:08 ` [PATCH v2 2/2] leds: trigger: gpio: Convert to use kstrtox() Andy Shevchenko
2019-09-01 10:23 ` Pavel Machek
2019-09-01 11:36 ` Jacek Anaszewski
2019-09-01 11:41 ` Jacek Anaszewski [this message]
2019-09-02 10:08 ` Andy Shevchenko
2019-08-30 21:11 ` [PATCH v2 1/2] leds: trigger: gpio: GPIO 0 is valid Jacek Anaszewski
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=afd5eeae-5b83-f9d0-f689-aa49c628a514@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).