Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759027AbbBIAcI (ORCPT ); Sun, 8 Feb 2015 19:32:08 -0500 Received: from 11.mo3.mail-out.ovh.net ([87.98.184.158]:49763 "EHLO 11.mo3.mail-out.ovh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754208AbbBIAcG (ORCPT ); Sun, 8 Feb 2015 19:32:06 -0500 X-Greylist: delayed 11998 seconds by postgrey-1.27 at vger.kernel.org; Sun, 08 Feb 2015 19:32:05 EST Date: Sun, 8 Feb 2015 21:52:43 +0100 From: Lukasz Majewski To: Guenter Roeck Cc: Lukasz Majewski , Eduardo Valentin , Kamil Debski , Jean Delvare , Kukjin Kim , lm-sensors@lm-sensors.org, Linux PM list , "linux-samsung-soc@vger.kernel.org" , devicetree@vger.kernel.org, Kukjin Kim , linux-kernel@vger.kernel.org, Sjoerd Simons , Abhilash Kesavan , Abhilash Kesavan Subject: Re: [PATCH v3 6/8] hwmon: pwm-fan: Extract __set_pwm() function to only modify PWM duty cycle Message-ID: <20150208215243.22085c97@jawa> In-Reply-To: <20150206182725.GA25410@roeck-us.net> References: <1418897591-18332-1-git-send-email-l.majewski@samsung.com> <1423241948-31981-1-git-send-email-l.majewski@samsung.com> <1423241948-31981-7-git-send-email-l.majewski@samsung.com> <20150206182725.GA25410@roeck-us.net> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; boundary="Sig_/BPabe_PY5yHylU13fGbDcaU"; protocol="application/pgp-signature" X-Ovh-Tracer-Id: 14745348131201008143 X-Ovh-Remote: 109.241.105.88 (109241105088.warszawa.vectranet.pl) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: -200 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeejkedrieeiucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdengfhvvghrhghhihhtvgdqqdetucdlqddutddtmd X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -200 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeejkedrieeiucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdengfhvvghrhghhihhtvgdqqdetucdlqddutddtmd Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3477 Lines: 122 --Sig_/BPabe_PY5yHylU13fGbDcaU Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Fri, 6 Feb 2015 10:27:25 -0800 Guenter Roeck wrote: > On Fri, Feb 06, 2015 at 05:59:06PM +0100, Lukasz Majewski wrote: > > 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. > >=20 > > 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(-) > >=20 > > 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; > > }; > > =20 > > -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 =3D 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; > > =20 > > if (ctx->pwm_value =3D=3D pwm) > > - goto exit_set_pwm_no_change; > > + return 0; > > =20 > Why did you move this check outside the lock ? With this change there=20 > is no guarantee that pwm_value wasn't changed while waiting for the > lock. Grrr. You are obviously right here. I will fix this. Thanks for spotting Best regards, Lukasz Majewski >=20 > Guenter >=20 > > + mutex_lock(&ctx->lock); > > if (pwm =3D=3D 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,=20 > > exit_set_pwm: > > ctx->pwm_value =3D pwm; > > -exit_set_pwm_no_change: > > - ret =3D count; > > exit_set_pwm_err: > > mutex_unlock(&ctx->lock); > > return ret; > > } > > =20 > > +static ssize_t set_pwm(struct device *dev, struct device_attribute > > *attr, > > + const char *buf, size_t count) > > +{ > > + struct pwm_fan_ctx *ctx =3D dev_get_drvdata(dev); > > + unsigned long pwm; > > + int ret; > > + > > + if (kstrtoul(buf, 10, &pwm) || pwm > MAX_PWM) > > + return -EINVAL; > > + > > + ret =3D __set_pwm(ctx, pwm); > > + if (ret) > > + return ret; > > + > > + return count; > > +} > > + > > static ssize_t show_pwm(struct device *dev, > > struct device_attribute *attr, char *buf) > > { > > --=20 > > 2.0.0.rc2 > >=20 --Sig_/BPabe_PY5yHylU13fGbDcaU Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAlTXzKEACgkQf9/hG2YwgjHPugCcCxRGEjB5x5p9qUUvPITaXmeO hZMAoKxxfV0eHZqPvPfA1EPQ3mxFT2+r =jamh -----END PGP SIGNATURE----- --Sig_/BPabe_PY5yHylU13fGbDcaU-- -- 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/