mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pwm: gpio: unregister the chip on driver unbind
@ 2026-11-01  3:26 Yu Zhang
  2026-11-01 12:55 ` Stefan Wahren
  0 siblings, 1 reply; 2+ messages in thread
From: Yu Zhang @ 2026-11-01  3:26 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Stefan Wahren, Linus Walleij, linux-pwm, linux-kernel, stable

pwm_gpio_probe() registers the chip with pwmchip_add(), but the driver
has neither a remove callback nor a devm action calling
pwmchip_remove(). On unbind the devres callbacks release the GPIO
descriptor, cancel the hrtimer and drop the reference taken by
devm_pwmchip_alloc(), while the chip stays registered: it is still in
the pwm_chips idr, its sysfs attributes and character device are still
there and chip->operational is still true.

The chip can therefore still be reached through sysfs export, the
character device, debugfs and pwm_get() from a consumer. Those paths
call into chip->ops, which point into unloaded module text once the
module is gone, and pwm_gpio_apply() re-arms the cancelled hrtimer and
drives a GPIO descriptor the driver no longer owns.

Use devm_pwmchip_add() so that the chip is removed before the hrtimer
is cancelled and the GPIO is released.

Fixes: 7f61257cd6e1 ("pwm: Add GPIO PWM driver")
Cc: stable@vger.kernel.org
Signed-off-by: Yu Zhang <yuz08559@gmail.com>
---
 drivers/pwm/pwm-gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pwm/pwm-gpio.c b/drivers/pwm/pwm-gpio.c
index 5644d78..cffdbcd 100644
--- a/drivers/pwm/pwm-gpio.c
+++ b/drivers/pwm/pwm-gpio.c
@@ -212,7 +212,7 @@ static int pwm_gpio_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = pwmchip_add(chip);
+	ret = devm_pwmchip_add(dev, chip);
 	if (ret < 0)
 		return dev_err_probe(dev, ret, "could not add pwmchip\n");
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] pwm: gpio: unregister the chip on driver unbind
  2026-11-01  3:26 [PATCH] pwm: gpio: unregister the chip on driver unbind Yu Zhang
@ 2026-11-01 12:55 ` Stefan Wahren
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Wahren @ 2026-11-01 12:55 UTC (permalink / raw)
  To: Yu Zhang, Uwe Kleine-König
  Cc: Linus Walleij, linux-pwm, linux-kernel, stable

Am 01.11.26 um 04:26 schrieb Yu Zhang:
> pwm_gpio_probe() registers the chip with pwmchip_add(), but the driver
> has neither a remove callback nor a devm action calling
> pwmchip_remove(). On unbind the devres callbacks release the GPIO
> descriptor, cancel the hrtimer and drop the reference taken by
> devm_pwmchip_alloc(), while the chip stays registered: it is still in
> the pwm_chips idr, its sysfs attributes and character device are still
> there and chip->operational is still true.
>
> The chip can therefore still be reached through sysfs export, the
> character device, debugfs and pwm_get() from a consumer. Those paths
> call into chip->ops, which point into unloaded module text once the
> module is gone, and pwm_gpio_apply() re-arms the cancelled hrtimer and
> drives a GPIO descriptor the driver no longer owns.
>
> Use devm_pwmchip_add() so that the chip is removed before the hrtimer
> is cancelled and the GPIO is released.
>
> Fixes: 7f61257cd6e1 ("pwm: Add GPIO PWM driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yu Zhang <yuz08559@gmail.com>
Reviewed-by: Stefan Wahren <wahrenst@gmx.net>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-01 12:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-01  3:26 [PATCH] pwm: gpio: unregister the chip on driver unbind Yu Zhang
2026-11-01 12:55 ` Stefan Wahren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®