Skip to contentSkip to conversation

pwm: bcm-iproc: handle clk_get_rate() return

PATCH Superseded Scott Branden 2 participants 3 messages Jul 17, 2020

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pwm: bcm-iproc: handle clk_get_rate() return

From: Rayagonda Kokatanur <[email protected]>

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

Fixes daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller")
---
 drivers/pwm/pwm-bcm-iproc.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/pwm/pwm-bcm-iproc.c +5 -0
index 1f829edd8ee7..72a8607b6c8d 100644
@@ -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);
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 17 lines · Scott Branden

From: Rayagonda Kokatanur <[email protected]>

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

Fixes daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller")
---
 drivers/pwm/pwm-bcm-iproc.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/pwm/pwm-bcm-iproc.c +0 -0
index 1f829edd8ee7..72a8607b6c8d 100644

drivers/pwm/pwm-bcm-iproc.c static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm, · line 93

Quoted 8 lines
drivers/pwm/pwm-bcm-iproc.c +5 -0
@@ -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.

Quoted 4 lines
drivers/pwm/pwm-bcm-iproc.c +0 -0
 	value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);
 
 
#2 lore raw
Quoted 21 lines · Ray Jui
Quoted 19 lines · Scott Branden

From: Rayagonda Kokatanur <[email protected]>

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

Fixes daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller")
---
  drivers/pwm/pwm-bcm-iproc.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/pwm/pwm-bcm-iproc.c +0 -0
index 1f829edd8ee7..72a8607b6c8d 100644
@@ -86,6 +86,11 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
  	u32 value, prescale;
 
Quoted 6 lines

drivers/pwm/pwm-bcm-iproc.c static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm, · line 93

Quoted 6 lines
drivers/pwm/pwm-bcm-iproc.c +5 -0
  	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.

Quoted 10 lines

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.

Quoted 4 lines
drivers/pwm/pwm-bcm-iproc.c +0 -0
  	value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);