lkml.org 
[lkml]   [2018]   [Aug]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 1/2] leds: core: Introduce LED pattern trigger
On Thu 02 Aug 14:21 PDT 2018, Jacek Anaszewski wrote:
> On 08/01/2018 11:01 AM, Baolin Wang wrote:
[..]
> > diff --git a/drivers/leds/trigger/ledtrig-pattern.c b/drivers/leds/trigger/ledtrig-pattern.c
[..]
> > +static ssize_t pattern_trig_store_pattern(struct device *dev,
> > + struct device_attribute *attr,
> > + const char *buf, size_t count)
> > +{
> > + struct led_classdev *led_cdev = dev_get_drvdata(dev);
> > + struct pattern_trig_data *data = led_cdev->trigger_data;
> > + int cr, ccount, offset = 0, err = 0;
> > +
> > + if (!data->hardware_pattern)
> > + del_timer_sync(&data->timer);
> > +
> > + mutex_lock(&data->lock);
> > +
> > + data->npatterns = 0;
> > + while (offset < count - 1 && data->npatterns < MAX_PATTERNS) {
> > + cr = 0;
> > + ccount = sscanf(buf + offset, "%d %d " PATTERN_SEPARATOR "%n",
> > + &data->patterns[data->npatterns].brightness,
> > + &data->patterns[data->npatterns].delta_t, &cr);
>
> In case user makes a typo while constructing list of pattern tuples,
> e.g. he forgets a comma, the pattern gets silently truncated.
>
> User is able to detect the truncation by reading pattern file,
> but it is not an immediate feedback anyway.
>

I agree, a failure to parse the entire pattern should result in an error
returned, rather than just silently truncating the pattern.

> I propose that pattern format should require number of tuples in the
> first position which would allow to get rid of this ambiguity, since
> we could verify if the number of parsed tuples is as intended.
>

I would prefer to see that we check that we have consumed the entire
input (accepting optional \n end), rather than having to prepend a count
to the string...

Regards,
Bjorn

\
 
 \ /
  Last update: 2018-08-02 23:55    [W:0.058 / U:10.176 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site