Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 7ca59947b5fc ("pwm: mediatek: Prevent divide-by-zero in pwm_mediatek_config()")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/20250704172728.626815-2-u.kleine-koenig@baylibre.com
Cc: stable@vger.kernel.org
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>

authored by

Uwe Kleine-König and committed by
Uwe Kleine-König
505b730e 9ee124ca

+8 -5
+8 -5
drivers/pwm/pwm-mediatek.c
··· 130 130 return ret; 131 131 132 132 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 + } 135 137 136 138 /* Make sure we use the bus clock and not the 26MHz clock */ 137 139 if (pc->soc->has_ck_26m_sel) ··· 152 150 } 153 151 154 152 if (clkdiv > PWM_CLK_DIV_MAX) { 155 - pwm_mediatek_clk_disable(chip, pwm); 156 153 dev_err(pwmchip_parent(chip), "period of %d ns not supported\n", period_ns); 157 - return -EINVAL; 154 + ret = -EINVAL; 155 + goto out; 158 156 } 159 157 160 158 if (pc->soc->pwm45_fixup && pwm->hwpwm > 2) { ··· 171 169 pwm_mediatek_writel(pc, pwm->hwpwm, reg_width, cnt_period); 172 170 pwm_mediatek_writel(pc, pwm->hwpwm, reg_thres, cnt_duty); 173 171 172 + out: 174 173 pwm_mediatek_clk_disable(chip, pwm); 175 174 176 - return 0; 175 + return ret; 177 176 } 178 177 179 178 static int pwm_mediatek_enable(struct pwm_chip *chip, struct pwm_device *pwm)