[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <200804041953.54020.david-b@pacbell.net>
Date: Fri, 4 Apr 2008 19:53:53 -0700
From: David Brownell <david-b@...bell.net>
To: Jean Delvare <khali@...ux-fr.org>
Cc: Trent Piepho <tpiepho@...escale.com>,
Linux Kernel list <linux-kernel@...r.kernel.org>
Subject: Re: [patch/rfc 2/4] pcf875x I2C GPIO expander driver
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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists