lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <xb2prc5ewslr74eh22xo4heeiepeiu4rb72zekuatcuhp45p6s@nhwhnq26tthg>
Date: Wed, 24 Apr 2024 16:19:04 +0200
From: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
To: George Stark <gnstark@...utedevices.com>
Cc: neil.armstrong@...aro.org, khilman@...libre.com, jbrunet@...libre.com, 
	martin.blumenstingl@...glemail.com, thierry.reding@...il.com, hkallweit1@...il.com, 
	linux-pwm@...r.kernel.org, linux-amlogic@...ts.infradead.org, 
	linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org, kernel@...utedevices.com, 
	Dmitry Rokosov <ddrokosov@...utedevices.com>
Subject: Re: [PATCH v2 2/2] pwm: meson: Add check for error from
 clk_round_rate()

On Wed, Apr 24, 2024 at 04:24:08PM +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.
> 
> Also change type of variable holding clk_round_rate() result from
> unsigned long to long. It's safe due to clk_round_rate() returns long.
> 
> Fixes: 329db102a26d ("pwm: meson: make full use of common clock framework")
> Signed-off-by: Dmitry Rokosov <ddrokosov@...utedevices.com>
> Signed-off-by: George Stark <gnstark@...utedevices.com>
> ---
>  drivers/pwm/pwm-meson.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
> index f4d70da621ec..d4228ac1e7ea 100644
> --- a/drivers/pwm/pwm-meson.c
> +++ b/drivers/pwm/pwm-meson.c
> @@ -148,7 +148,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
>  	struct meson_pwm *meson = to_meson_pwm(chip);
>  	struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm];
>  	unsigned int cnt, duty_cnt;
> -	unsigned long fin_freq;
> +	long fin_freq;
>  	u64 duty, period, freq;
>  
>  	duty = state->duty_cycle;
> @@ -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);
                                                   ^
With fin_freq now being unsigned, this ------------' should be a 'd'.

If you want to still extend your fixes series: A bit further below there
is

	cnt = div_u64(fin_freq * period, NSEC_PER_SEC);

. The multiplication there might overflow. This should better use
mul_u64_u64_div_u64() (or one of it's variants).

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ