linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] pwm: bcm-iproc: handle clk_get_rate() return
@ 2020-07-17 18:25 Scott Branden
  2020-07-17 22:27 ` Ray Jui
  2020-07-17 23:04 ` Uwe Kleine-König
  0 siblings, 2 replies; 4+ messages in thread
From: Scott Branden @ 2020-07-17 18:25 UTC (permalink / raw)
  To: Thierry Reding, Lee Jones
  Cc: Uwe Kleine-König, BCM Kernel Feedback, linux-pwm,
	linux-kernel, Rayagonda Kokatanur, Scott Branden

From: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>

Handle clk_get_rate() returning <= 0 condition to avoid
possible division by zero.

Fixes: daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller")
Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
Signed-off-by: Scott Branden <scott.branden@broadcom.com>

---
Changes from v1: ensure  'polarity' and 'enabled' are populated
when clk_get_rate is 0.
---
 drivers/pwm/pwm-bcm-iproc.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
index 1f829edd8ee7..d392a828fc49 100644
--- a/drivers/pwm/pwm-bcm-iproc.c
+++ b/drivers/pwm/pwm-bcm-iproc.c
@@ -85,8 +85,6 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
 	u64 tmp, multi, rate;
 	u32 value, prescale;
 
-	rate = clk_get_rate(ip->clk);
-
 	value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);
 
 	if (value & BIT(IPROC_PWM_CTRL_EN_SHIFT(pwm->hwpwm)))
@@ -99,6 +97,13 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
 	else
 		state->polarity = PWM_POLARITY_INVERSED;
 
+	rate = clk_get_rate(ip->clk);
+	if (rate == 0) {
+		state->period = 0;
+		state->duty_cycle = 0;
+		return;
+	}
+
 	value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET);
 	prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm);
 	prescale &= IPROC_PWM_PRESCALE_MAX;
-- 
2.17.1

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

* Re: [PATCH v2] pwm: bcm-iproc: handle clk_get_rate() return
  2020-07-17 18:25 [PATCH v2] pwm: bcm-iproc: handle clk_get_rate() return Scott Branden
@ 2020-07-17 22:27 ` Ray Jui
  2020-07-17 23:04 ` Uwe Kleine-König
  1 sibling, 0 replies; 4+ messages in thread
From: Ray Jui @ 2020-07-17 22:27 UTC (permalink / raw)
  To: Scott Branden, Thierry Reding, Lee Jones
  Cc: Uwe Kleine-König, BCM Kernel Feedback, linux-pwm,
	linux-kernel, Rayagonda Kokatanur



On 7/17/2020 11:25 AM, Scott Branden wrote:
> From: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> 
> Handle clk_get_rate() returning <= 0 condition to avoid
> possible division by zero.
> 
> Fixes: daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller")
> Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> Signed-off-by: Scott Branden <scott.branden@broadcom.com>
> 
> ---
> Changes from v1: ensure  'polarity' and 'enabled' are populated
> when clk_get_rate is 0.
> ---
>  drivers/pwm/pwm-bcm-iproc.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
> index 1f829edd8ee7..d392a828fc49 100644
> --- a/drivers/pwm/pwm-bcm-iproc.c
> +++ b/drivers/pwm/pwm-bcm-iproc.c
> @@ -85,8 +85,6 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
>  	u64 tmp, multi, rate;
>  	u32 value, prescale;
>  
> -	rate = clk_get_rate(ip->clk);
> -
>  	value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);
>  
>  	if (value & BIT(IPROC_PWM_CTRL_EN_SHIFT(pwm->hwpwm)))
> @@ -99,6 +97,13 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
>  	else
>  		state->polarity = PWM_POLARITY_INVERSED;
>  
> +	rate = clk_get_rate(ip->clk);
> +	if (rate == 0) {
> +		state->period = 0;
> +		state->duty_cycle = 0;
> +		return;
> +	}
> +
>  	value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET);
>  	prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm);
>  	prescale &= IPROC_PWM_PRESCALE_MAX;
> 

This patch looks good to me. Thanks!

Reviewed-by: Ray Jui <ray.jui@broadcom.com>

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

* Re: [PATCH v2] pwm: bcm-iproc: handle clk_get_rate() return
  2020-07-17 18:25 [PATCH v2] pwm: bcm-iproc: handle clk_get_rate() return Scott Branden
  2020-07-17 22:27 ` Ray Jui
@ 2020-07-17 23:04 ` Uwe Kleine-König
  2020-07-17 23:11   ` Scott Branden
  1 sibling, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2020-07-17 23:04 UTC (permalink / raw)
  To: Scott Branden
  Cc: Thierry Reding, Lee Jones, BCM Kernel Feedback, linux-pwm,
	linux-kernel, Rayagonda Kokatanur

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

On Fri, Jul 17, 2020 at 11:25:12AM -0700, Scott Branden wrote:
> From: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> 
> Handle clk_get_rate() returning <= 0 condition to avoid
> possible division by zero.

You advertise handling <= 0, but in the code only == 0 is checked. One
of the two is wrong ...

Best regards
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 v2] pwm: bcm-iproc: handle clk_get_rate() return
  2020-07-17 23:04 ` Uwe Kleine-König
@ 2020-07-17 23:11   ` Scott Branden
  0 siblings, 0 replies; 4+ messages in thread
From: Scott Branden @ 2020-07-17 23:11 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Thierry Reding, Lee Jones, BCM Kernel Feedback, linux-pwm,
	linux-kernel, Rayagonda Kokatanur



On 2020-07-17 4:04 p.m., Uwe Kleine-König wrote:
> On Fri, Jul 17, 2020 at 11:25:12AM -0700, Scott Branden wrote:
>> From: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
>>
>> Handle clk_get_rate() returning <= 0 condition to avoid
>> possible division by zero.
> You advertise handling <= 0, but in the code only == 0 is checked. One
> of the two is wrong ...
I checked - clk_get_rate can't return negative values.
I'll update the commit message from <= to ==.
>
> Best regards
> Uwe
>
Thanks,
  Scott

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

end of thread, other threads:[~2020-07-17 23:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17 18:25 [PATCH v2] pwm: bcm-iproc: handle clk_get_rate() return Scott Branden
2020-07-17 22:27 ` Ray Jui
2020-07-17 23:04 ` Uwe Kleine-König
2020-07-17 23:11   ` Scott Branden

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).