pwm: omap-dmtimer: Remove PWM chip in .remove before making it unfunctional
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Mon, 11 Nov 2019 09:03:54 +0000 (10:03 +0100)
committerThierry Reding <thierry.reding@gmail.com>
Mon, 20 Jan 2020 11:29:34 +0000 (12:29 +0100)
In the old code (e.g.) mutex_destroy() was called before
pwmchip_remove(). Between these two calls it is possible that a PWM
callback is used which tries to grab the mutex.

Fixes: 6604c6556db9 ("pwm: Add PWM driver for OMAP using dual-mode timers")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-omap-dmtimer.c

index 00772fc5349062bab9f906dbccc0c31814d730c9..bdf94c78655f120f90c8139b0f9443725781876a 100644 (file)
@@ -351,6 +351,11 @@ put:
 static int pwm_omap_dmtimer_remove(struct platform_device *pdev)
 {
        struct pwm_omap_dmtimer_chip *omap = platform_get_drvdata(pdev);
+       int ret;
+
+       ret = pwmchip_remove(&omap->chip);
+       if (ret)
+               return ret;
 
        if (pm_runtime_active(&omap->dm_timer_pdev->dev))
                omap->pdata->stop(omap->dm_timer);
@@ -359,7 +364,7 @@ static int pwm_omap_dmtimer_remove(struct platform_device *pdev)
 
        mutex_destroy(&omap->mutex);
 
-       return pwmchip_remove(&omap->chip);
+       return 0;
 }
 
 static const struct of_device_id pwm_omap_dmtimer_of_match[] = {