Re: [patch 2.6.29-rc] regulator: minor cleanup of virtual consumer

From: Andrew Morton
Date: Thu Jan 15 2009 - 19:13:55 EST


On Thu, 15 Jan 2009 16:10:22 -0800
Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Wed, 14 Jan 2009 13:16:27 -0800
> David Brownell <david-b@xxxxxxxxxxx> wrote:
>
> > From: David Brownell <dbrownell@xxxxxxxxxxxxxxxxxxxxx>
> >
> > Minor cleanup to the regulator set_mode sysfs support:
> > switch to sysfs_streq() in set_mode(), which is also
> > a code shrink. Use the same strings that get_mode()
> > uses, shrinking data too.
> >
> > Signed-off-by: David Brownell <dbrownell@xxxxxxxxxxxxxxxxxxxxx>
> > ---
> > drivers/regulator/virtual.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > --- a/drivers/regulator/virtual.c
> > +++ b/drivers/regulator/virtual.c
> > @@ -226,13 +226,13 @@ static ssize_t set_mode(struct device *d
> > unsigned int mode;
> > int ret;
> >
> > - if (strncmp(buf, "fast", strlen("fast")) == 0)
> > + if (sysfs_streq(buf, "fast\n") == 0)
> > mode = REGULATOR_MODE_FAST;
> > - else if (strncmp(buf, "normal", strlen("normal")) == 0)
> > + else if (sysfs_streq(buf, "normal\n") == 0)
> > mode = REGULATOR_MODE_NORMAL;
> > - else if (strncmp(buf, "idle", strlen("idle")) == 0)
> > + else if (sysfs_streq(buf, "idle\n") == 0)
> > mode = REGULATOR_MODE_IDLE;
> > - else if (strncmp(buf, "standby", strlen("standby")) == 0)
> > + else if (sysfs_streq(buf, "standby\n") == 0)
> > mode = REGULATOR_MODE_STANDBY;
>
> we don't need the \n's, do we?

oh, it's for the string sharing. Sneaky.

I wonder how many people will try to fix that up for us?

--- a/drivers/regulator/virtual.c~regulator-minor-cleanup-of-virtual-consumer-fix
+++ a/drivers/regulator/virtual.c
@@ -226,6 +226,10 @@ static ssize_t set_mode(struct device *d
unsigned int mode;
int ret;

+ /*
+ * sysfs_streq() doesn't need the \n's, but we add them so the strings
+ * will be shared with show_mode(), above.
+ */
if (sysfs_streq(buf, "fast\n") == 0)
mode = REGULATOR_MODE_FAST;
else if (sysfs_streq(buf, "normal\n") == 0)
_

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