pwm: sysfs: Properly convert from enum to string
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>hifive-unleashed-5.1
parent
15da7b5001
commit
5a063d87e9
|
@ -133,9 +133,19 @@ static ssize_t pwm_polarity_show(struct device *child,
|
||||||
char *buf)
|
char *buf)
|
||||||
{
|
{
|
||||||
const struct pwm_device *pwm = child_to_pwm_device(child);
|
const struct pwm_device *pwm = child_to_pwm_device(child);
|
||||||
|
const char *polarity = "unknown";
|
||||||
|
|
||||||
return sprintf(buf, "%s\n",
|
switch (pwm_get_polarity(pwm)) {
|
||||||
pwm_get_polarity(pwm) ? "inversed" : "normal");
|
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,
|
static ssize_t pwm_polarity_store(struct device *child,
|
||||||
|
|
Loading…
Reference in New Issue