Skip to content

Commit 505b730

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: mediatek: Ensure to disable clocks in error path
After enabling the clocks each error path must disable the clocks again. One of them failed to do so. Unify the error paths to use goto to make it harder for future changes to add a similar bug. Fixes: 7ca5994 ("pwm: mediatek: Prevent divide-by-zero in pwm_mediatek_config()") Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 9ee124c commit 505b730

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/pwm/pwm-mediatek.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,
130130
return ret;
131131

132132
clk_rate = clk_get_rate(pc->clk_pwms[pwm->hwpwm]);
133-
if (!clk_rate)
134-
return -EINVAL;
133+
if (!clk_rate) {
134+
ret = -EINVAL;
135+
goto out;
136+
}
135137

136138
/* Make sure we use the bus clock and not the 26MHz clock */
137139
if (pc->soc->has_ck_26m_sel)
@@ -150,9 +152,9 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,
150152
}
151153

152154
if (clkdiv > PWM_CLK_DIV_MAX) {
153-
pwm_mediatek_clk_disable(chip, pwm);
154155
dev_err(pwmchip_parent(chip), "period of %d ns not supported\n", period_ns);
155-
return -EINVAL;
156+
ret = -EINVAL;
157+
goto out;
156158
}
157159

158160
if (pc->soc->pwm45_fixup && pwm->hwpwm > 2) {
@@ -169,9 +171,10 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,
169171
pwm_mediatek_writel(pc, pwm->hwpwm, reg_width, cnt_period);
170172
pwm_mediatek_writel(pc, pwm->hwpwm, reg_thres, cnt_duty);
171173

174+
out:
172175
pwm_mediatek_clk_disable(chip, pwm);
173176

174-
return 0;
177+
return ret;
175178
}
176179

177180
static int pwm_mediatek_enable(struct pwm_chip *chip, struct pwm_device *pwm)

0 commit comments

Comments
 (0)