Skip to contentSkip to conversation

power: supply: twl4030_charger: Use sysfs_match_string() helper

PATCH In review Andy Shevchenko 2 participants 2 messages Jun 11, 2017 – Jun 14, 2017 Power supply

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 power: supply: twl4030_charger: Use sysfs_match_string() helper

Use sysfs_match_string() helper instead of open coded variant.

Cc Sebastian Reichel <[email protected]>

---
- constify array of mode names

 drivers/power/supply/twl4030_charger.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/power/supply/twl4030_charger.c +5 -9
index 785a07bc4f39..07c70e59f31a 100644
@@ -153,7 +153,7 @@ struct twl4030_bci {
 };
 
 /* strings for 'usb_mode' values */
-static char *modes[] = { "off", "auto", "continuous" };
+static const char *modes[] = { "off", "auto", "continuous" };
 
 /*
  * clear and set bits on an given register on a given module
@@ -669,14 +669,10 @@ twl4030_bci_mode_store(struct device *dev, struct device_attribute *attr,
 	int mode;
 	int status;
 
-	if (sysfs_streq(buf, modes[0]))
-		mode = 0;
-	else if (sysfs_streq(buf, modes[1]))
-		mode = 1;
-	else if (sysfs_streq(buf, modes[2]))
-		mode = 2;
-	else
-		return -EINVAL;
+	mode = sysfs_match_string(modes, buf);
+	if (mode < 0)
+		return mode;
+
 	if (dev == &bci->ac->dev) {
 		if (mode == 2)
 			return -EINVAL;
Signature · 1 line
2.11.0
#1 lore raw

Hi,

Quoted 4 lines · Andy Shevchenko

Use sysfs_match_string() helper instead of open coded variant.

Cc Sebastian Reichel <[email protected]>

Thanks, queued.

-- Sebastian

Quoted 40 lines

---
- constify array of mode names

 drivers/power/supply/twl4030_charger.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/power/supply/twl4030_charger.c +5 -9
index 785a07bc4f39..07c70e59f31a 100644
@@ -153,7 +153,7 @@ struct twl4030_bci {
 };
 
 /* strings for 'usb_mode' values */
-static char *modes[] = { "off", "auto", "continuous" };
+static const char *modes[] = { "off", "auto", "continuous" };
 
 /*
  * clear and set bits on an given register on a given module
@@ -669,14 +669,10 @@ twl4030_bci_mode_store(struct device *dev, struct device_attribute *attr,
 	int mode;
 	int status;
 
-	if (sysfs_streq(buf, modes[0]))
-		mode = 0;
-	else if (sysfs_streq(buf, modes[1]))
-		mode = 1;
-	else if (sysfs_streq(buf, modes[2]))
-		mode = 2;
-	else
-		return -EINVAL;
+	mode = sysfs_match_string(modes, buf);
+	if (mode < 0)
+		return mode;
+
 	if (dev == &bci->ac->dev) {
 		if (mode == 2)
 			return -EINVAL;
Signature · 1 line
2.11.0