Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758482AbbBFRAA (ORCPT ); Fri, 6 Feb 2015 12:00:00 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:28992 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758420AbbBFQ74 (ORCPT ); Fri, 6 Feb 2015 11:59:56 -0500 X-AuditID: cbfee61a-f79c06d000004e71-a8-54d4f30a1e43 From: Lukasz Majewski To: Eduardo Valentin , Kamil Debski , Jean Delvare , Guenter Roeck , Kukjin Kim Cc: lm-sensors@lm-sensors.org, Linux PM list , "linux-samsung-soc@vger.kernel.org" , devicetree@vger.kernel.org, Lukasz Majewski , Kukjin Kim , linux-kernel@vger.kernel.org, Sjoerd Simons , Abhilash Kesavan , Abhilash Kesavan , Lukasz Majewski Subject: [PATCH v3 6/8] hwmon: pwm-fan: Extract __set_pwm() function to only modify PWM duty cycle Date: Fri, 06 Feb 2015 17:59:06 +0100 Message-id: <1423241948-31981-7-git-send-email-l.majewski@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-reply-to: <1423241948-31981-1-git-send-email-l.majewski@samsung.com> References: <1418897591-18332-1-git-send-email-l.majewski@samsung.com> <1423241948-31981-1-git-send-email-l.majewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrMLMWRmVeSWpSXmKPExsVy+t9jAV2uz1dCDF7vVrF4vGYxk8X8I+dY LeZfucZqsfTuJzaLH68vsFms+atk0bvgKptF/+PXzBZvHnFbvHm4mdHi8q45bBafe48wWsw4 v4/J4snCM0wWd6btZbOYfvwtq4OAx9/n11k8ds66y+6xaVUnm8eDibvZPNZNe8vssfN7A7tH 35ZVjB6bT1d7fN4kF8AZxWWTkpqTWZZapG+XwJWx/oFOwXSBimfbNrI1MH7j6WLk5JAQMJFo +PeXEcIWk7hwbz1bFyMXh5DAIkaJ7wsmMoMkhAS6mCTOznEEsdkE9CQ+333KBFIkIrCdUWLF vG9gHcwC15gl9m0+ygRSJSyQIvFh1gewbhYBVYl9O6eC2bwCbhIzvm9mh1inKNH9bAIbiM0p 4C5x8N4udojVzYwSC3cdYZrAyLuAkWEVo2hqQXJBcVJ6rqFecWJucWleul5yfu4mRnBQP5Pa wbiyweIQowAHoxIPbwLvlRAh1sSy4srcQ4wSHMxKIrw9S4FCvCmJlVWpRfnxRaU5qcWHGKU5 WJTEeZXs20KEBNITS1KzU1MLUotgskwcnFINjM2rvqoen7NT7uauL6+CvW/aC39s/RR9+AGb 93XTFwx9uhInbA+aBE42/8J98+Fq9S2BP9nN3N8U+J0VvuuVssS/X2Lj2wqJR1IRrbesPi/f E1fl7S/rvUxAspXz26cZMR4qu+N+Pguf3ezgUCp6+tjk4gDGM1LfW5a2Pd51/v+9j34bijeU /VJiKc5INNRiLipOBAA0gxqhZgIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2236 Lines: 85 It was necessary to decouple code handling writing to sysfs from the one responsible for setting PWM of the fan. Due to that, new __set_pwm() method was extracted, which is responsible for only setting new PWM duty cycle. Signed-off-by: Lukasz Majewski --- Changes for v2: - None Changes for v3: - The commit headline has been reedited. --- drivers/hwmon/pwm-fan.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 1991d903..870e100 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -33,21 +33,15 @@ struct pwm_fan_ctx { unsigned char pwm_value; }; -static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) +static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) { - struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); - unsigned long pwm, duty; - ssize_t ret; - - if (kstrtoul(buf, 10, &pwm) || pwm > MAX_PWM) - return -EINVAL; - - mutex_lock(&ctx->lock); + unsigned long duty; + int ret; if (ctx->pwm_value == pwm) - goto exit_set_pwm_no_change; + return 0; + mutex_lock(&ctx->lock); if (pwm == 0) { pwm_disable(ctx->pwm); goto exit_set_pwm; @@ -66,13 +60,28 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, exit_set_pwm: ctx->pwm_value = pwm; -exit_set_pwm_no_change: - ret = count; exit_set_pwm_err: mutex_unlock(&ctx->lock); return ret; } +static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); + unsigned long pwm; + int ret; + + if (kstrtoul(buf, 10, &pwm) || pwm > MAX_PWM) + return -EINVAL; + + ret = __set_pwm(ctx, pwm); + if (ret) + return ret; + + return count; +} + static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, char *buf) { -- 2.0.0.rc2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/