Skip to content

Commit a08b318

Browse files
Andre-ARMthierryreding
authored andcommitted
pwm: sun4i: Propagate errors in .get_state() to the caller
.get_state() can return an error indication now. Make use of it to propagate an impossible prescaler encoding, should that have sneaked in somehow. Also check the return value of clk_get_rate(). That's unlikely to fail, but we use that in two divide operations down in the code, so let's avoid a divide-by-zero condition on the way. Signed-off-by: Andre Przywara <[email protected]> Reviewed-by: Uwe Kleine-König <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Reviewed-by: Jernej Skrabec <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent c73a310 commit a08b318

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/pwm/pwm-sun4i.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ static int sun4i_pwm_get_state(struct pwm_chip *chip,
118118
unsigned int prescaler;
119119

120120
clk_rate = clk_get_rate(sun4i_pwm->clk);
121+
if (!clk_rate)
122+
return -EINVAL;
121123

122124
val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
123125

@@ -142,7 +144,7 @@ static int sun4i_pwm_get_state(struct pwm_chip *chip,
142144
prescaler = prescaler_table[PWM_REG_PRESCAL(val, pwm->hwpwm)];
143145

144146
if (prescaler == 0)
145-
return 0;
147+
return -EINVAL;
146148

147149
if (val & BIT_CH(PWM_ACT_STATE, pwm->hwpwm))
148150
state->polarity = PWM_POLARITY_NORMAL;

0 commit comments

Comments
 (0)