]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
hwmon: (pwm-fan) Ensure that calculation doesn't discard big period values
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tue, 15 Dec 2020 09:20:30 +0000 (10:20 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Jan 2021 17:26:15 +0000 (18:26 +0100)
commit1d05b91ab72eb31289f877f9932380ad251f06e4
treed9d59d8b0c36f7e5039c95f5c0a3b7ab9cd8cb32
parent1229d433960cd91140ba2c318867cca7f3e270c3
hwmon: (pwm-fan) Ensure that calculation doesn't discard big period values

[ Upstream commit 1eda52334e6d13eb1a85f713ce06dd39342b5020 ]

With MAX_PWM being defined to 255 the code

unsigned long period;
...
period = ctx->pwm->args.period;
state.duty_cycle = DIV_ROUND_UP(pwm * (period - 1), MAX_PWM);

calculates a too small value for duty_cycle if the configured period is
big (either by discarding the 64 bit value ctx->pwm->args.period or by
overflowing the multiplication). As this results in a too slow fan and
so maybe an overheating machine better be safe than sorry and error out
in .probe.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20201215092031.152243-1-u.kleine-koenig@pengutronix.de
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hwmon/pwm-fan.c