pwm: sysfs: Properly convert from enum to string
authorThierry Reding <thierry.reding@gmail.com>
Mon, 20 Jul 2015 07:56:05 +0000 (09:56 +0200)
committerThierry Reding <thierry.reding@gmail.com>
Mon, 27 Jul 2015 10:03:37 +0000 (12:03 +0200)
The current code will check for polarity in a boolean way. While it is
correct that polarity is either normal or inversed, make it more obvious
that it's an enumeration by using a switch statement and explicit
matches on the enumeration values.

Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/sysfs.c

index ac0abecfbaa017c6ef0ad7369db98762c3b143bc..fbfc9e903230cc068cd2d4abce93131369ca7428 100644 (file)
@@ -133,9 +133,19 @@ static ssize_t pwm_polarity_show(struct device *child,
                                 char *buf)
 {
        const struct pwm_device *pwm = child_to_pwm_device(child);
+       const char *polarity = "unknown";
 
-       return sprintf(buf, "%s\n",
-                      pwm_get_polarity(pwm) ? "inversed" : "normal");
+       switch (pwm_get_polarity(pwm)) {
+       case PWM_POLARITY_NORMAL:
+               polarity = "normal";
+               break;
+
+       case PWM_POLARITY_INVERSED:
+               polarity = "inversed";
+               break;
+       }
+
+       return sprintf(buf, "%s\n", polarity);
 }
 
 static ssize_t pwm_polarity_store(struct device *child,