diff mbox series

[2/2] pwm: meson: add check for error from clk_round_rate()

Message ID 20240423161356.2522636-3-gnstark@salutedevices.com (mailing list archive)
State New, archived
Headers show
Series meson pwm small fixes | expand

Commit Message

George Stark April 23, 2024, 4:13 p.m. UTC
clk_round_rate() can return not only zero if requested frequency can not
be provided but also negative error code so add check for it too.

Fixes: 329db102a26d ("pwm: meson: make full use of common clock framework")
Signed-off-by: George Stark <gnstark@salutedevices.com>
Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com>
---
 drivers/pwm/pwm-meson.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Uwe Kleine-König April 24, 2024, 7:13 a.m. UTC | #1
Hello,

On Tue, Apr 23, 2024 at 07:13:56PM +0300, George Stark wrote:
> clk_round_rate() can return not only zero if requested frequency can not
> be provided but also negative error code so add check for it too.
> 
> Fixes: 329db102a26d ("pwm: meson: make full use of common clock framework")
> Signed-off-by: George Stark <gnstark@salutedevices.com>
> Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com>
> ---
>  drivers/pwm/pwm-meson.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
> index ebe76298f6e2..52604635b31e 100644
> --- a/drivers/pwm/pwm-meson.c
> +++ b/drivers/pwm/pwm-meson.c
> @@ -168,9 +168,10 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
>  		freq = ULONG_MAX;
>  
>  	fin_freq = clk_round_rate(channel->clk, freq);
> -	if (fin_freq == 0) {
> -		dev_err(pwmchip_parent(chip), "invalid source clock frequency\n");
> -		return -EINVAL;
> +	if (fin_freq <= 0) {

fin_freq is an unsigned long, so your change doesn't have the intended
effect.

Best regards
Uwe
diff mbox series

Patch

diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
index ebe76298f6e2..52604635b31e 100644
--- a/drivers/pwm/pwm-meson.c
+++ b/drivers/pwm/pwm-meson.c
@@ -168,9 +168,10 @@  static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
 		freq = ULONG_MAX;
 
 	fin_freq = clk_round_rate(channel->clk, freq);
-	if (fin_freq == 0) {
-		dev_err(pwmchip_parent(chip), "invalid source clock frequency\n");
-		return -EINVAL;
+	if (fin_freq <= 0) {
+		dev_err(pwmchip_parent(chip),
+			"invalid source clock frequency %llu\n", freq);
+		return fin_freq ? fin_freq : -EINVAL;
 	}
 
 	dev_dbg(pwmchip_parent(chip), "fin_freq: %lu Hz\n", fin_freq);