All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pwm: bcm-iproc: handle clk_get_rate() return
@ 2020-07-17 17:07 Scott Branden
  2020-07-17 17:22 ` Ray Jui
  0 siblings, 1 reply; 3+ messages in thread
From: Scott Branden @ 2020-07-17 17:07 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>
---
 drivers/pwm/pwm-bcm-iproc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
index 1f829edd8ee7..72a8607b6c8d 100644
--- a/drivers/pwm/pwm-bcm-iproc.c
+++ b/drivers/pwm/pwm-bcm-iproc.c
@@ -86,6 +86,11 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
 	u32 value, prescale;
 
 	rate = clk_get_rate(ip->clk);
+	if (rate == 0) {
+		state->period = 0;
+		state->duty_cycle = 0;
+		return;
+	}
 
 	value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);
 
-- 
2.17.1


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

* Re: [PATCH] pwm: bcm-iproc: handle clk_get_rate() return
  2020-07-17 17:07 [PATCH] pwm: bcm-iproc: handle clk_get_rate() return Scott Branden
@ 2020-07-17 17:22 ` Ray Jui
  2020-07-17 18:24   ` Scott Branden
  0 siblings, 1 reply; 3+ messages in thread
From: Ray Jui @ 2020-07-17 17:22 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 10:07 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>
> ---
>  drivers/pwm/pwm-bcm-iproc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
> index 1f829edd8ee7..72a8607b6c8d 100644
> --- a/drivers/pwm/pwm-bcm-iproc.c
> +++ b/drivers/pwm/pwm-bcm-iproc.c
> @@ -86,6 +86,11 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
>  	u32 value, prescale;
>  
>  	rate = clk_get_rate(ip->clk);
> +	if (rate == 0) {
> +		state->period = 0;
> +		state->duty_cycle = 0;
> +		return;
> +	}

Based on the pwm core code, 'get_state' expects the following fields to
be populated: 'polarity', 'enabled', 'period', and 'duty cycle'.

The above logic will leave 'polarity' and 'enabled' completely
unpopulated when clock rate is zero.

>  
>  	value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);
>  
> 

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

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



On 2020-07-17 10:22 a.m., Ray Jui wrote:
>
> On 7/17/2020 10:07 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>
>> ---
>>   drivers/pwm/pwm-bcm-iproc.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c
>> index 1f829edd8ee7..72a8607b6c8d 100644
>> --- a/drivers/pwm/pwm-bcm-iproc.c
>> +++ b/drivers/pwm/pwm-bcm-iproc.c
>> @@ -86,6 +86,11 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
>>   	u32 value, prescale;
>>   
>>   	rate = clk_get_rate(ip->clk);
>> +	if (rate == 0) {
>> +		state->period = 0;
>> +		state->duty_cycle = 0;
>> +		return;
>> +	}
I'll move the logic after the polarity and enabled fields are populated.
> Based on the pwm core code, 'get_state' expects the following fields to
> be populated: 'polarity', 'enabled', 'period', and 'duty cycle'.
>
> The above logic will leave 'polarity' and 'enabled' completely
> unpopulated when clock rate is zero.
>
>>   
>>   	value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);
>>   
>>


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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17 17:07 [PATCH] pwm: bcm-iproc: handle clk_get_rate() return Scott Branden
2020-07-17 17:22 ` Ray Jui
2020-07-17 18:24   ` Scott Branden

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.