Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753770AbbBYPfD (ORCPT ); Wed, 25 Feb 2015 10:35:03 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:63939 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753785AbbBYPe6 (ORCPT ); Wed, 25 Feb 2015 10:34:58 -0500 X-AuditID: cbfee61a-f79c06d000004e71-f9-54edeba0a2bc 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 v5 4/6] hwmon: pwm-fan: Extract __set_pwm() function to only modify PWM duty cycle Date: Wed, 25 Feb 2015 16:34:20 +0100 Message-id: <1424878462-15511-5-git-send-email-l.majewski@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-reply-to: <1424878462-15511-1-git-send-email-l.majewski@samsung.com> References: <1418897591-18332-1-git-send-email-l.majewski@samsung.com> <1424878462-15511-1-git-send-email-l.majewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrMLMWRmVeSWpSXmKPExsVy+t9jAd0Fr9+GGOz9ZmPxeM1iJov5R86x Wsy/co3VYundT2wWP15fYLNY81fJonfBVTaL/sevmS3ePOK2ePNwM6PF5V1z2Cw+9x5htJhx fh+TxZOFZ5gs7kzby2Yx/fhbVgcBj7/Pr7N47Jx1l91j06pONo8HE3ezeayb9pbZY+f3BnaP vi2rGD02n672+LxJLoAzissmJTUnsyy1SN8ugStj/ZY+9oIPAhWb+6+zNDDu4u1i5OSQEDCR WDq1hx3CFpO4cG89G4gtJLCIUWLaLiCbC8juYpJoP7oTrIhNQE/i892nTCAJEYHtjBIr5n0D q2IWuMYssW/zUaAMB4ewQIrErvUGIA0sAqoSD2/dYQSxeQXcJD5vncYEsU1RovvZBLBtnALu EnPfPGeH2NbMKHHr4jTmCYy8CxgZVjGKphYkFxQnpeca6hUn5haX5qXrJefnbmIEB/UzqR2M KxssDjEKcDAq8fAmCL8JEWJNLCuuzD3EKMHBrCTC23r2bYgQb0piZVVqUX58UWlOavEhRmkO FiVxXiX7thAhgfTEktTs1NSC1CKYLBMHp1QDo8GhtCTNr2nfY5fsvzJd3rGZbany/LUGvK8s KzUk/XIjPdasdTdtfs7E8NpB91b1ld66NadTF72SVpqWVd6nIfljxq0XR1Yuu3lsP+PvsO3L n3LN33/ir/vdmTabIhL/H05SCSmKXn+3JvroGlt7tm13vWtK44XYFJhX7q8T+FD9xlS0fZKl rxJLcUaioRZzUXEiAGvh8ZxmAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2322 Lines: 88 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. Changes for v4: - Protect "if (ctx->pwm_value == pwm)" with ctx lock - Initialize ret with zero Changes for v5: - None --- drivers/hwmon/pwm-fan.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 1991d903..bd42d39 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -33,20 +33,14 @@ 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; + unsigned long duty; + int ret = 0; mutex_lock(&ctx->lock); - if (ctx->pwm_value == pwm) - goto exit_set_pwm_no_change; + goto exit_set_pwm_err; if (pwm == 0) { pwm_disable(ctx->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/