All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] pwm: bcm-iproc: handle clk_get_rate() return
@ 2020-07-18  4:46 Scott Branden
  2020-07-24 15:27 ` Ray Jui
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Scott Branden @ 2020-07-18  4:46 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 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>
Reviewed-by: Ray Jui <ray.jui@broadcom.com>

---
Changes from v3: fixed typo in commit message: Reviewed-off-by.
Hopefully everything clean now.
Changes from v2: update commit message to remove <= condition
as clk_get_rate only returns value >= 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 v4] pwm: bcm-iproc: handle clk_get_rate() return
  2020-07-18  4:46 [PATCH v4] pwm: bcm-iproc: handle clk_get_rate() return Scott Branden
@ 2020-07-24 15:27 ` Ray Jui
  2020-07-24 16:47 ` Uwe Kleine-König
  2020-07-27  8:29 ` Thierry Reding
  2 siblings, 0 replies; 4+ messages in thread
From: Ray Jui @ 2020-07-24 15: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

Hi Thierry/Uwe,

Do you have any further comment on this patch? If not, could you please
help to pick it up?

Thanks,

Ray

On 7/17/2020 9:46 PM, Scott Branden wrote:
> From: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> 
> Handle clk_get_rate() returning 0 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>
> Reviewed-by: Ray Jui <ray.jui@broadcom.com>
> 
> ---
> Changes from v3: fixed typo in commit message: Reviewed-off-by.
> Hopefully everything clean now.
> Changes from v2: update commit message to remove <= condition
> as clk_get_rate only returns value >= 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;
> 

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

* Re: [PATCH v4] pwm: bcm-iproc: handle clk_get_rate() return
  2020-07-18  4:46 [PATCH v4] pwm: bcm-iproc: handle clk_get_rate() return Scott Branden
  2020-07-24 15:27 ` Ray Jui
@ 2020-07-24 16:47 ` Uwe Kleine-König
  2020-07-27  8:29 ` Thierry Reding
  2 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2020-07-24 16:47 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: 722 bytes --]

On Fri, Jul 17, 2020 at 09:46:06PM -0700, Scott Branden wrote:
> From: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> 
> Handle clk_get_rate() returning 0 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>
> Reviewed-by: Ray Jui <ray.jui@broadcom.com>

LGTM

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

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 v4] pwm: bcm-iproc: handle clk_get_rate() return
  2020-07-18  4:46 [PATCH v4] pwm: bcm-iproc: handle clk_get_rate() return Scott Branden
  2020-07-24 15:27 ` Ray Jui
  2020-07-24 16:47 ` Uwe Kleine-König
@ 2020-07-27  8:29 ` Thierry Reding
  2 siblings, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2020-07-27  8:29 UTC (permalink / raw)
  To: Scott Branden
  Cc: Lee Jones, Uwe Kleine-König, BCM Kernel Feedback, linux-pwm,
	linux-kernel, Rayagonda Kokatanur

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

On Fri, Jul 17, 2020 at 09:46:06PM -0700, Scott Branden wrote:
> From: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> 
> Handle clk_get_rate() returning 0 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>
> Reviewed-by: Ray Jui <ray.jui@broadcom.com>
> 
> ---
> Changes from v3: fixed typo in commit message: Reviewed-off-by.
> Hopefully everything clean now.
> Changes from v2: update commit message to remove <= condition
> as clk_get_rate only returns value >= 0
> ---
>  drivers/pwm/pwm-bcm-iproc.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

Applied, thanks.

Thierry

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

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

end of thread, other threads:[~2020-07-27  8:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-18  4:46 [PATCH v4] pwm: bcm-iproc: handle clk_get_rate() return Scott Branden
2020-07-24 15:27 ` Ray Jui
2020-07-24 16:47 ` Uwe Kleine-König
2020-07-27  8:29 ` 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.