lkml.org 
[lkml]   [2008]   [Apr]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [patch/rfc 2/4] pcf875x I2C GPIO expander driver
Date
On Friday 04 April 2008, Jean Delvare wrote:
> > +static ssize_t gpio_direction_store(struct device *dev,
> > +             struct device_attribute *attr, const char *buf, size_t size)
> > +{
> > +     const struct gpio_desc *gdesc = dev_get_drvdata(dev);
> > +     int d, n = gdesc - gpio_desc;
> > +
> > +     if (size >= 3 && !strncmp(buf, "out", 3)) {
> > +             d = 1;
> > +     } else if (size >= 2 && !strncmp(buf, "in", 2)) {
> > +             d = 0;
>
> As far as I know, the string you receive from sysfs is guaranteed to be
> NUL-terminated, so the size checks are not needed.
>
> > +     } else {
> > +             d = simple_strtoul(buf, NULL, 0);
>
> This exposes to user-space the so far internal-only decision to encode
> output as 1 and input as 0. I don't see much benefit in doing this, in
> particular when you don't check for errors so for example an input of
> "Out" would result in value 0 i.e. input mode. I'd rather support only
> "in" and "out" as valid values and return -EINVAL otherwise.

So, after trimming trailing whitespace:

if (strcmp(buf, "out") == 0)
gpio_direction_output(...)
else if (strcmp(buf, "in") == 0)
gpio_direction_input(...)
Yes, that'd be a lot better.

>
> > +     }
> > +
> > +     if (d)
> > +             gpio_direction_output(n, 0);
> > +     else
> > +             gpio_direction_input(n);
> > +
> > +     return size;
> > +}


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2008-04-05 05:23    [from the cache]
©2003-2014 Jasper Spaans. hosted at Digital Ocean