Skip to contentSkip to conversation

regulator: minor cleanup of virtual consumer

PATCH Applied David Brownell 4 participants 8 messages Jan 14, 2009 – Jan 16, 2009 Voltage and current regulator framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regulator: minor cleanup of virtual consumer

From: David Brownell <[email protected]>

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.

---
 drivers/regulator/virtual.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/regulator/virtual.c +4 -4
@@ -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;
 	else {
 		dev_err(dev, "Configuring invalid mode\n");
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · David Brownell

From: David Brownell <[email protected]>

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.

Excellent, thanks!

Quoted 25 lines

---
drivers/regulator/virtual.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
drivers/regulator/virtual.c +4 -4
@@ -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;
   else {
       dev_err(dev, "Configuring invalid mode\n");
#3 lore raw
In reply to David Brownell
Quoted 20 lines · On Wed, 14 Jan 2009 13:16:27 -0800 David Brownell <[email protected]> wrote:

From: David Brownell <[email protected]>

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.

---
 drivers/regulator/virtual.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/regulator/virtual.c +1 -1
@@ -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)

drivers/regulator/virtual.c static ssize_t set_mode(struct device *d · line 236

Quoted 10 lines
drivers/regulator/virtual.c +3 -3
 		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?

#4 lore raw
Quoted 21 lines · On Thu, 15 Jan 2009 16:10:22 -0800 Andrew Morton <[email protected]>…
Quoted 18 lines · On Wed, 14 Jan 2009 13:16:27 -0800 David Brownell <[email protected]> wrote:

From: David Brownell <[email protected]>

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.

---
 drivers/regulator/virtual.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/regulator/virtual.c +0 -0
@@ -226,13 +226,13 @@ static ssize_t set_mode(struct device *d
 	unsigned int mode;
 	int ret;
 
Quoted 14 lines

drivers/regulator/virtual.c static ssize_t set_mode(struct device *d · line 236

Quoted 12 lines
drivers/regulator/virtual.c +4 -4
-	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?

drivers/regulator/virtual.c renamed from drivers/regulator/virtual.c~regulator-minor-cleanup-of-virtual-consumer-fix +4 -0
@@ -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)

_

#6 lore raw
In reply to Andrew Morton
Quoted 17 lines · Andrew Morton

On Thu, 15 Jan 2009 16:10:22 -0800
Andrew Morton <[email protected]> wrote:

drivers/regulator/virtual.c renamed from drivers/regulator/virtual.c~regulator-minor-cleanup-of-virtual-consumer-fix +4 -0
@@ -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)
Quoted 2 lines

_

Applied.

Thanks

Liam

#7 lore raw
In reply to Andrew Morton
Quoted 5 lines · Andrew Morton

drivers/regulator/virtual.c static ssize_t set_mode(struct device *d · line 236

Quoted 3 lines
drivers/regulator/virtual.c +1 -1
-	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?

No, but ...

That's what saves an extra couple dozen bytes of
memory ... the strings, with newlines, are used
to *write* these sysfs attributes.

- Dave