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: sti: Fix capture for st,pwm-num-chan < st,capture-num-chan

The driver only used the number of pwm channels to set the pwm_chip's
npwm member. The result is that if there are more capture channels than
PWM channels specified in the device tree, only a part of the capture
channel is usable. Fix that by passing the bigger channel count to the
pwm framework. This makes it possible that the .apply() callback is
called with .hwpwm >= pwm_num_devs, catch that case and return an error
code.

Fixes: c97267ae831d ("pwm: sti: Add PWM capture callback")
Link: https://lore.kernel.org/r/20240204212043.2951852-2-u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

+10 -1
+10 -1
drivers/pwm/pwm-sti.c
··· 395 395 static int sti_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 396 396 const struct pwm_state *state) 397 397 { 398 + struct sti_pwm_chip *pc = to_sti_pwmchip(chip); 399 + struct sti_pwm_compat_data *cdata = pc->cdata; 400 + struct device *dev = pc->dev; 398 401 int err; 402 + 403 + if (pwm->hwpwm >= cdata->pwm_num_devs) { 404 + dev_err(dev, "device %u is not valid for pwm mode\n", 405 + pwm->hwpwm); 406 + return -EINVAL; 407 + } 399 408 400 409 if (state->polarity != PWM_POLARITY_NORMAL) 401 410 return -EINVAL; ··· 655 646 656 647 pc->chip.dev = dev; 657 648 pc->chip.ops = &sti_pwm_ops; 658 - pc->chip.npwm = pc->cdata->pwm_num_devs; 649 + pc->chip.npwm = max(cdata->pwm_num_devs, cdata->cpt_num_devs); 659 650 660 651 for (i = 0; i < cdata->cpt_num_devs; i++) { 661 652 struct sti_cpt_ddata *ddata = &cdata->ddata[i];