diff options
Diffstat (limited to 'drivers/hwmon/pwm-fan.c')
-rw-r--r-- | drivers/hwmon/pwm-fan.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 1991d9032c38..bd42d3996a86 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c | |||
@@ -33,20 +33,14 @@ struct pwm_fan_ctx { | |||
33 | unsigned char pwm_value; | 33 | unsigned char pwm_value; |
34 | }; | 34 | }; |
35 | 35 | ||
36 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | 36 | static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) |
37 | const char *buf, size_t count) | ||
38 | { | 37 | { |
39 | struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); | 38 | unsigned long duty; |
40 | unsigned long pwm, duty; | 39 | int ret = 0; |
41 | ssize_t ret; | ||
42 | |||
43 | if (kstrtoul(buf, 10, &pwm) || pwm > MAX_PWM) | ||
44 | return -EINVAL; | ||
45 | 40 | ||
46 | mutex_lock(&ctx->lock); | 41 | mutex_lock(&ctx->lock); |
47 | |||
48 | if (ctx->pwm_value == pwm) | 42 | if (ctx->pwm_value == pwm) |
49 | goto exit_set_pwm_no_change; | 43 | goto exit_set_pwm_err; |
50 | 44 | ||
51 | if (pwm == 0) { | 45 | if (pwm == 0) { |
52 | pwm_disable(ctx->pwm); | 46 | pwm_disable(ctx->pwm); |
@@ -66,13 +60,28 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
66 | 60 | ||
67 | exit_set_pwm: | 61 | exit_set_pwm: |
68 | ctx->pwm_value = pwm; | 62 | ctx->pwm_value = pwm; |
69 | exit_set_pwm_no_change: | ||
70 | ret = count; | ||
71 | exit_set_pwm_err: | 63 | exit_set_pwm_err: |
72 | mutex_unlock(&ctx->lock); | 64 | mutex_unlock(&ctx->lock); |
73 | return ret; | 65 | return ret; |
74 | } | 66 | } |
75 | 67 | ||
68 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | ||
69 | const char *buf, size_t count) | ||
70 | { | ||
71 | struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); | ||
72 | unsigned long pwm; | ||
73 | int ret; | ||
74 | |||
75 | if (kstrtoul(buf, 10, &pwm) || pwm > MAX_PWM) | ||
76 | return -EINVAL; | ||
77 | |||
78 | ret = __set_pwm(ctx, pwm); | ||
79 | if (ret) | ||
80 | return ret; | ||
81 | |||
82 | return count; | ||
83 | } | ||
84 | |||
76 | static ssize_t show_pwm(struct device *dev, | 85 | static ssize_t show_pwm(struct device *dev, |
77 | struct device_attribute *attr, char *buf) | 86 | struct device_attribute *attr, char *buf) |
78 | { | 87 | { |