From: Guenter Roeck <linux@roeck-us.net>
To: Alexander Stein <alexander.stein@ew.tq-group.com>
Cc: "Jean Delvare" <jdelvare@suse.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Lee Jones" <lee.jones@linaro.org>,
linux-hwmon@vger.kernel.org, linux-pwm@vger.kernel.org,
"Markus Niebel" <Markus.Niebel@ew.tq-group.com>
Subject: Re: [PATCH v4 4/6] hwmon: pwm-fan: split __set_pwm into locked/unlocked functions
Date: Tue, 30 Aug 2022 06:52:38 -0700 [thread overview]
Message-ID: <20220830135238.GA230167@roeck-us.net> (raw)
In-Reply-To: <20220523110513.407516-5-alexander.stein@ew.tq-group.com>
On Mon, May 23, 2022 at 01:05:11PM +0200, Alexander Stein wrote:
> Regular calls to set_pwm don't hold the mutex, but the upcoming
> update_enable support needs to call set_pwm with the mutex being held.
> So provide the previous behavior in set_pwm (handling the lock), while
> adding __set_pwm which assumes the lock being held.
>
> Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
For my reference:
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> ---
> drivers/hwmon/pwm-fan.c | 23 +++++++++++++++--------
> 1 file changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
> index 04af24268963..fcc1b7b55a65 100644
> --- a/drivers/hwmon/pwm-fan.c
> +++ b/drivers/hwmon/pwm-fan.c
> @@ -152,14 +152,12 @@ static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
> unsigned long period;
> int ret = 0;
>
> - mutex_lock(&ctx->lock);
> -
> if (pwm > 0) {
> period = state->period;
> state->duty_cycle = DIV_ROUND_UP(pwm * (period - 1), MAX_PWM);
> ret = pwm_apply_state(ctx->pwm, state);
> if (ret)
> - goto exit_set_pwm_err;
> + return ret;
> ret = pwm_fan_power_on(ctx);
> } else {
> ret = pwm_fan_power_off(ctx);
> @@ -167,8 +165,17 @@ static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
> if (!ret)
> ctx->pwm_value = pwm;
>
> -exit_set_pwm_err:
> + return ret;
> +}
> +
> +static int set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
> +{
> + int ret;
> +
> + mutex_lock(&ctx->lock);
> + ret = __set_pwm(ctx, pwm);
> mutex_unlock(&ctx->lock);
> +
> return ret;
> }
>
> @@ -192,7 +199,7 @@ static int pwm_fan_write(struct device *dev, enum hwmon_sensor_types type,
> if (val < 0 || val > MAX_PWM)
> return -EINVAL;
>
> - ret = __set_pwm(ctx, val);
> + ret = set_pwm(ctx, val);
> if (ret)
> return ret;
>
> @@ -280,7 +287,7 @@ pwm_fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
> if (state == ctx->pwm_fan_state)
> return 0;
>
> - ret = __set_pwm(ctx, ctx->pwm_fan_cooling_levels[state]);
> + ret = set_pwm(ctx, ctx->pwm_fan_cooling_levels[state]);
> if (ret) {
> dev_err(&cdev->device, "Cannot set pwm!\n");
> return ret;
> @@ -400,7 +407,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
> pwm_init_state(ctx->pwm, &ctx->pwm_state);
>
> /*
> - * __set_pwm assumes that MAX_PWM * (period - 1) fits into an unsigned
> + * set_pwm assumes that MAX_PWM * (period - 1) fits into an unsigned
> * long. Check this here to prevent the fan running at a too low
> * frequency.
> */
> @@ -410,7 +417,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
> }
>
> /* Set duty cycle to maximum allowed and enable PWM output */
> - ret = __set_pwm(ctx, MAX_PWM);
> + ret = set_pwm(ctx, MAX_PWM);
> if (ret) {
> dev_err(dev, "Failed to configure PWM: %d\n", ret);
> return ret;
next prev parent reply other threads:[~2022-08-30 13:53 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-23 11:05 [PATCH v4 0/6] hwmon: pwm-fan: switch regulator dynamically Alexander Stein
2022-05-23 11:05 ` [PATCH v4 1/6] hwmon: pwm-fan: Refactor fan power on/off Alexander Stein
2022-08-30 13:45 ` Guenter Roeck
2022-05-23 11:05 ` [PATCH v4 2/6] hwmon: pwm-fan: Simplify enable/disable check Alexander Stein
2022-08-30 13:43 ` Guenter Roeck
2022-09-14 15:06 ` Alexander Stein
2022-05-23 11:05 ` [PATCH v4 3/6] hwmon: pwm-fan: Add dedicated power switch function Alexander Stein
2022-08-30 13:50 ` Guenter Roeck
2022-09-14 15:10 ` Alexander Stein
2022-05-23 11:05 ` [PATCH v4 4/6] hwmon: pwm-fan: split __set_pwm into locked/unlocked functions Alexander Stein
2022-08-30 13:52 ` Guenter Roeck [this message]
2022-05-23 11:05 ` [PATCH v4 5/6] hwmon: pwm-fan: Switch regulator dynamically Alexander Stein
2022-08-30 14:01 ` Guenter Roeck
2022-05-23 11:05 ` [PATCH v4 6/6] hwmon: pwm-fan: Remove internal duplicated pwm_state Alexander Stein
2022-05-23 12:46 ` Uwe Kleine-König
2022-05-23 13:55 ` Alexander Stein
2022-05-23 14:18 ` Guenter Roeck
2022-06-21 6:41 ` Alexander Stein
2022-06-21 7:22 ` Uwe Kleine-König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220830135238.GA230167@roeck-us.net \
--to=linux@roeck-us.net \
--cc=Markus.Niebel@ew.tq-group.com \
--cc=alexander.stein@ew.tq-group.com \
--cc=corbet@lwn.net \
--cc=jdelvare@suse.com \
--cc=lee.jones@linaro.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=thierry.reding@gmail.com \
--cc=u.kleine-koenig@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox