Skip to content

Commit

Permalink
pwm: sysfs: Properly convert from enum to string
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
thierryreding committed Jul 27, 2015
1 parent 15da7b5 commit 5a063d8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions drivers/pwm/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5a063d8

Please sign in to comment.