diff mbox series

hwmon: (pwm-fan) Let ctx->pwm_value be assigned only in __set_pwm

Message ID 20211130030046.3920-1-billy_tsai@aspeedtech.com (mailing list archive)
State Superseded
Headers show
Series hwmon: (pwm-fan) Let ctx->pwm_value be assigned only in __set_pwm | expand

Commit Message

Billy Tsai Nov. 30, 2021, 3 a.m. UTC
This patch is used to fix the bug when pwm_fan_probe the pwm_value will
be out of sync with the PWM hardware drivers.

Fixes: 86585c61972f ("hwmon: (pwm-fan) stop using legacy PWM functions and some cleanups")
Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
---
 drivers/hwmon/pwm-fan.c | 2 --
 1 file changed, 2 deletions(-)

Comments

Uwe Kleine-König Nov. 30, 2021, 6:55 a.m. UTC | #1
Hello,

On Tue, Nov 30, 2021 at 11:00:46AM +0800, Billy Tsai wrote:
> This patch is used to fix the bug when pwm_fan_probe the pwm_value will
> be out of sync with the PWM hardware drivers.
> 
> Fixes: 86585c61972f ("hwmon: (pwm-fan) stop using legacy PWM functions and some cleanups")
> Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
> ---
>  drivers/hwmon/pwm-fan.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
> index 17518b4cab1b..f12b9a28a232 100644
> --- a/drivers/hwmon/pwm-fan.c
> +++ b/drivers/hwmon/pwm-fan.c
> @@ -336,8 +336,6 @@ static int pwm_fan_probe(struct platform_device *pdev)
>  			return ret;
>  	}
>  
> -	ctx->pwm_value = MAX_PWM;
> -
>  	pwm_init_state(ctx->pwm, &ctx->pwm_state);

Ah, I see. The effect is that the FAN is supposed to be running at full
speed after probe, but this isn't asserted.

So the patch is fine, but I suggest to make the commit log a bit more
frightening. Something like:

	hwmon: (pwm-fan) Ensure the fan going on in .probe()
	
	Before commit 86585c61972f ("hwmon: (pwm-fan) stop using legacy
	PWM functions and some cleanups") pwm_apply_state() was called
	unconditionally in pwm_fan_probe(). In this commit this direct
	call was replaced by a call to __set_pwm(ct, MAX_PWM) which
	however is a noop if ctx->pwm_value already matches the value to
	set.

	After probe the fan is supposed to run at full speed, and the
	internal driver state suggests it does, but this isn't asserted
	and depending on bootloader and pwm low-level driver, the fan
	might just be off.

	So drop setting pwm_value to MAXX_PWM to ensure the check in
	__set_pwm doesn't make it exit early and the fan goes on as
	intended.

	Cc: stable@vger.kernel.org
	Fixes: 86585c61972f ("hwmon: (pwm-fan) stop using legacy PWM functions and some cleanups")

Best regards and thanks for cleaning up after me,
Uwe
Billy Tsai Nov. 30, 2021, 9:12 a.m. UTC | #2
Hi Uwe,

On 2021/11/30, 4:21 PM, "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de> wrote:

    Hello,

    On Tue, Nov 30, 2021 at 11:00:46AM +0800, Billy Tsai wrote:
    >   > This patch is used to fix the bug when pwm_fan_probe the pwm_value will
    >   > be out of sync with the PWM hardware drivers.
    >   > 
    >   > Fixes: 86585c61972f ("hwmon: (pwm-fan) stop using legacy PWM functions and some cleanups")
    >   > Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
    >   > ---
    >   >  drivers/hwmon/pwm-fan.c | 2 --
    >   >  1 file changed, 2 deletions(-)
    >   > 
    >   > diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
    >   > index 17518b4cab1b..f12b9a28a232 100644
    >   > --- a/drivers/hwmon/pwm-fan.c
    >   > +++ b/drivers/hwmon/pwm-fan.c
    >   > @@ -336,8 +336,6 @@ static int pwm_fan_probe(struct platform_device *pdev)
    >   >  			return ret;
    >   >  	}
    >   >  
    >   > -	ctx->pwm_value = MAX_PWM;
    >   > -
    >   >  	pwm_init_state(ctx->pwm, &ctx->pwm_state);

    >   Ah, I see. The effect is that the FAN is supposed to be running at full
    >   speed after probe, but this isn't asserted.

    >   So the patch is fine, but I suggest to make the commit log a bit more
    >   frightening. Something like:

    >   	hwmon: (pwm-fan) Ensure the fan going on in .probe()

    >   	Before commit 86585c61972f ("hwmon: (pwm-fan) stop using legacy
    >   	PWM functions and some cleanups") pwm_apply_state() was called
    >   	unconditionally in pwm_fan_probe(). In this commit this direct
    >   	call was replaced by a call to __set_pwm(ct, MAX_PWM) which
    >   	however is a noop if ctx->pwm_value already matches the value to
    >   	set.

    >   	After probe the fan is supposed to run at full speed, and the
    >   	internal driver state suggests it does, but this isn't asserted
    >   	and depending on bootloader and pwm low-level driver, the fan
    >   	might just be off.

    >   	So drop setting pwm_value to MAXX_PWM to ensure the check in
    >   	__set_pwm doesn't make it exit early and the fan goes on as
    >   	intended.

    >   	Cc: stable@vger.kernel.org
    >   	Fixes: 86585c61972f ("hwmon: (pwm-fan) stop using legacy PWM functions and some cleanups")
Ok, I will use this commit log and resend the patch.

Best Regards,
Billy Tsai
diff mbox series

Patch

diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 17518b4cab1b..f12b9a28a232 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -336,8 +336,6 @@  static int pwm_fan_probe(struct platform_device *pdev)
 			return ret;
 	}
 
-	ctx->pwm_value = MAX_PWM;
-
 	pwm_init_state(ctx->pwm, &ctx->pwm_state);
 
 	/*