linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linaro.org>
To: Pavel Machek <pavel@ucw.cz>
Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>,
	rteysseyre@gmail.com,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Mark Brown <broonie@kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Linux LED Subsystem <linux-leds@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: More checks for patterns? was: Fix pattern handling optimalization
Date: Fri, 26 Oct 2018 16:02:10 +0800	[thread overview]
Message-ID: <CAMz4kuLgV2Nz9yX3y=nT-_jiuFGSA+CY5g7EWQN4Yu-+oojH1g@mail.gmail.com> (raw)
In-Reply-To: <20181025212429.GB18016@amd>

Hi Pavel,

On 26 October 2018 at 05:24, Pavel Machek <pavel@ucw.cz> wrote:
>
> We don't want brightness < 0, but this may not be best way to do
> this. We also don't want brightness > max_brightness, but I'm not sure
> this check is effective.

I think this is reasonable, but we can simplify the patch as:

diff --git a/drivers/leds/trigger/ledtrig-pattern.c
b/drivers/leds/trigger/ledtrig-pattern.c
index ce7acd1..3a4ecb9 100644
--- a/drivers/leds/trigger/ledtrig-pattern.c
+++ b/drivers/leds/trigger/ledtrig-pattern.c
@@ -250,10 +250,11 @@ static ssize_t
pattern_trig_store_patterns(struct led_classdev *led_cdev,

        while (offset < count - 1 && data->npatterns < MAX_PATTERNS) {
                cr = 0;
-               ccount = sscanf(buf + offset, "%d %u %n",
+               ccount = sscanf(buf + offset, "%u %u %n",
                                &data->patterns[data->npatterns].brightness,
                                &data->patterns[data->npatterns].delta_t, &cr);
-               if (ccount != 2) {
+               if (ccount != 2 ||
+                   data->patterns[data->npatterns].brightness >
data->led_cdev->max_brightness) {
                        data->npatterns = 0;
                        err = -EINVAL;
                        goto out;

>
> We probably also don't want pattern where all the delta_t s are zero.

Yes. Maybe add one function to valid the patterns.

>
> I came up with this so far....
>                                                             Pavel
>
>
>
> diff --git a/drivers/leds/trigger/ledtrig-pattern.c b/drivers/leds/trigger/ledtrig-pattern.c
> index ce7acd1..bc5f495 100644
> --- a/drivers/leds/trigger/ledtrig-pattern.c
> +++ b/drivers/leds/trigger/ledtrig-pattern.c
> @@ -250,9 +251,16 @@ static ssize_t pattern_trig_store_patterns(struct led_classdev *led_cdev,
>
>         while (offset < count - 1 && data->npatterns < MAX_PATTERNS) {
>                 cr = 0;
> -               ccount = sscanf(buf + offset, "%d %u %n",
> +               ccount = sscanf(buf + offset, "%u %u %n",
>                                 &data->patterns[data->npatterns].brightness,
>                                 &data->patterns[data->npatterns].delta_t, &cr);
> +
> +               if (data->patterns[data->npatterns].brightness > data->led_cdev->max_brightness) {
> +                       data->npatterns = 0;
> +                       err = -EINVAL;
> +                       goto out;
> +               }
> +
>                 if (ccount != 2) {
>                         data->npatterns = 0;
>                         err = -EINVAL;
>
>
>
>
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html



-- 
Baolin Wang
Best Regards

  reply	other threads:[~2018-10-26  8:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-11  4:07 [PATCH v15 1/2] leds: core: Introduce LED pattern trigger Baolin Wang
2018-10-11  4:07 ` [PATCH v15 2/2] leds: sc27xx: Add pattern_set/clear interfaces for LED controller Baolin Wang
2018-10-11 20:07 ` [PATCH v15 1/2] leds: core: Introduce LED pattern trigger Jacek Anaszewski
2018-10-12  1:40   ` Baolin Wang
2018-10-24  8:34     ` Pavel Machek
2018-10-24  8:31   ` Pavel Machek
2018-10-24 19:17     ` Jacek Anaszewski
2018-10-24 19:55       ` Pavel Machek
2018-10-24 20:44       ` [PATCH] Fix pattern handling optimalization Pavel Machek
2018-10-25 19:17         ` Jacek Anaszewski
2018-10-25 21:24           ` More checks for patterns? was: " Pavel Machek
2018-10-26  8:02             ` Baolin Wang [this message]
2018-10-26 19:56             ` 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='CAMz4kuLgV2Nz9yX3y=nT-_jiuFGSA+CY5g7EWQN4Yu-+oojH1g@mail.gmail.com' \
    --to=baolin.wang@linaro.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=broonie@kernel.org \
    --cc=jacek.anaszewski@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rteysseyre@gmail.com \
    --subject='Re: More checks for patterns? was: Fix pattern handling optimalization' \
    /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

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).