All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pwm: tegra: Fix 32 bit build
@ 2022-11-10 11:45 Steven Price
  2022-11-10 13:18 ` Jon Hunter
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Steven Price @ 2022-11-10 11:45 UTC (permalink / raw)
  To: Jonathan Hunter, Thierry Reding
  Cc: Steven Price, Uwe Kleine-König, linux-kernel, linux-pwm,
	linux-tegra

The value of NSEC_PER_SEC << PWM_DUTY_WIDTH doesn't fix within a 32 bit
integer causing a build warning/error (and the value truncated):

  drivers/pwm/pwm-tegra.c: In function ‘tegra_pwm_config’:
  drivers/pwm/pwm-tegra.c:148:53: error: result of ‘1000000000 << 8’ requires 39 bits to represent, but ‘long int’ only has 32 bits [-Werror=shift-overflow=]
    148 |   required_clk_rate = DIV_ROUND_UP_ULL(NSEC_PER_SEC << PWM_DUTY_WIDTH,
        |                                                     ^~

Explicitly cast to a u64 to ensure the correct result.

Fixes: cfcb68817fb3 ("pwm: tegra: Improve required rate calculation")
Signed-off-by: Steven Price <steven.price@arm.com>
---
 drivers/pwm/pwm-tegra.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
index 6fc4b69a3ba7..249dc0193297 100644
--- a/drivers/pwm/pwm-tegra.c
+++ b/drivers/pwm/pwm-tegra.c
@@ -145,7 +145,7 @@ static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 		 * source clock rate as required_clk_rate, PWM controller will
 		 * be able to configure the requested period.
 		 */
-		required_clk_rate = DIV_ROUND_UP_ULL(NSEC_PER_SEC << PWM_DUTY_WIDTH,
+		required_clk_rate = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC << PWM_DUTY_WIDTH,
 						     period_ns);
 
 		if (required_clk_rate > clk_round_rate(pc->clk, required_clk_rate))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] pwm: tegra: Fix 32 bit build
  2022-11-10 11:45 [PATCH] pwm: tegra: Fix 32 bit build Steven Price
@ 2022-11-10 13:18 ` Jon Hunter
  2022-11-10 14:53 ` Uwe Kleine-König
  2022-11-11 14:30 ` Thierry Reding
  2 siblings, 0 replies; 4+ messages in thread
From: Jon Hunter @ 2022-11-10 13:18 UTC (permalink / raw)
  To: Steven Price, Thierry Reding
  Cc: Uwe Kleine-König, linux-kernel, linux-pwm, linux-tegra


On 10/11/2022 11:45, Steven Price wrote:
> The value of NSEC_PER_SEC << PWM_DUTY_WIDTH doesn't fix within a 32 bit
> integer causing a build warning/error (and the value truncated):
> 
>    drivers/pwm/pwm-tegra.c: In function ‘tegra_pwm_config’:
>    drivers/pwm/pwm-tegra.c:148:53: error: result of ‘1000000000 << 8’ requires 39 bits to represent, but ‘long int’ only has 32 bits [-Werror=shift-overflow=]
>      148 |   required_clk_rate = DIV_ROUND_UP_ULL(NSEC_PER_SEC << PWM_DUTY_WIDTH,
>          |                                                     ^~
> 
> Explicitly cast to a u64 to ensure the correct result.
> 
> Fixes: cfcb68817fb3 ("pwm: tegra: Improve required rate calculation")
> Signed-off-by: Steven Price <steven.price@arm.com>
> ---
>   drivers/pwm/pwm-tegra.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
> index 6fc4b69a3ba7..249dc0193297 100644
> --- a/drivers/pwm/pwm-tegra.c
> +++ b/drivers/pwm/pwm-tegra.c
> @@ -145,7 +145,7 @@ static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>   		 * source clock rate as required_clk_rate, PWM controller will
>   		 * be able to configure the requested period.
>   		 */
> -		required_clk_rate = DIV_ROUND_UP_ULL(NSEC_PER_SEC << PWM_DUTY_WIDTH,
> +		required_clk_rate = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC << PWM_DUTY_WIDTH,
>   						     period_ns);
>   
>   		if (required_clk_rate > clk_round_rate(pc->clk, required_clk_rate))


Thanks!

Reviewed-by: Jon Hunter <jonathanh@nvidia.com>

Jon

-- 
nvpublic

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pwm: tegra: Fix 32 bit build
  2022-11-10 11:45 [PATCH] pwm: tegra: Fix 32 bit build Steven Price
  2022-11-10 13:18 ` Jon Hunter
@ 2022-11-10 14:53 ` Uwe Kleine-König
  2022-11-11 14:30 ` Thierry Reding
  2 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2022-11-10 14:53 UTC (permalink / raw)
  To: Steven Price
  Cc: Jonathan Hunter, Thierry Reding, linux-kernel, linux-pwm, linux-tegra

[-- Attachment #1: Type: text/plain, Size: 977 bytes --]

Hello,

On Thu, Nov 10, 2022 at 11:45:48AM +0000, Steven Price wrote:
> The value of NSEC_PER_SEC << PWM_DUTY_WIDTH doesn't fix within a 32 bit
> integer causing a build warning/error (and the value truncated):
> 
>   drivers/pwm/pwm-tegra.c: In function ‘tegra_pwm_config’:
>   drivers/pwm/pwm-tegra.c:148:53: error: result of ‘1000000000 << 8’ requires 39 bits to represent, but ‘long int’ only has 32 bits [-Werror=shift-overflow=]
>     148 |   required_clk_rate = DIV_ROUND_UP_ULL(NSEC_PER_SEC << PWM_DUTY_WIDTH,
>         |                                                     ^~
> 
> Explicitly cast to a u64 to ensure the correct result.

Hmm, ideally this should have popped up earlier :-\

Anyhow:

Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks
Uwe

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pwm: tegra: Fix 32 bit build
  2022-11-10 11:45 [PATCH] pwm: tegra: Fix 32 bit build Steven Price
  2022-11-10 13:18 ` Jon Hunter
  2022-11-10 14:53 ` Uwe Kleine-König
@ 2022-11-11 14:30 ` Thierry Reding
  2 siblings, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2022-11-11 14:30 UTC (permalink / raw)
  To: Jonathan Hunter, Steven Price
  Cc: linux-kernel, linux-pwm, linux-tegra, Uwe Kleine-König

On Thu, 10 Nov 2022 11:45:48 +0000, Steven Price wrote:
> The value of NSEC_PER_SEC << PWM_DUTY_WIDTH doesn't fix within a 32 bit
> integer causing a build warning/error (and the value truncated):
> 
>   drivers/pwm/pwm-tegra.c: In function ‘tegra_pwm_config’:
>   drivers/pwm/pwm-tegra.c:148:53: error: result of ‘1000000000 << 8’ requires 39 bits to represent, but ‘long int’ only has 32 bits [-Werror=shift-overflow=]
>     148 |   required_clk_rate = DIV_ROUND_UP_ULL(NSEC_PER_SEC << PWM_DUTY_WIDTH,
>         |                                                     ^~
> 
> [...]

Applied, thanks!

[1/1] pwm: tegra: Fix 32 bit build
      commit: dd1f1da4ada5d8ac774c2ebe97230637820b3323

Best regards,
-- 
Thierry Reding <thierry.reding@gmail.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-11 14:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10 11:45 [PATCH] pwm: tegra: Fix 32 bit build Steven Price
2022-11-10 13:18 ` Jon Hunter
2022-11-10 14:53 ` Uwe Kleine-König
2022-11-11 14:30 ` Thierry Reding

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.