pwm: Fix order of freeing resources in pwmchip_remove()
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tue, 25 Jul 2023 08:10:04 +0000 (10:10 +0200)
committerThierry Reding <thierry.reding@gmail.com>
Fri, 28 Jul 2023 07:42:37 +0000 (09:42 +0200)
pwmchip_add() calls of_pwmchip_add() only after adding the chip to
pwm_chips and releasing pwm_lock. So the proper order in
pwmchip_remove() is to call of_pwmchip_remove() before taking the mutex
and removing the chip from pwm_chips. This way pwmchip_remove() releases
the resources in reverse order compared to pwmchip_add() requesting
them.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/core.c

index b4703df..dc66e34 100644 (file)
@@ -318,13 +318,13 @@ void pwmchip_remove(struct pwm_chip *chip)
 {
        pwmchip_sysfs_unexport(chip);
 
+       if (IS_ENABLED(CONFIG_OF))
+               of_pwmchip_remove(chip);
+
        mutex_lock(&pwm_lock);
 
        list_del_init(&chip->list);
 
-       if (IS_ENABLED(CONFIG_OF))
-               of_pwmchip_remove(chip);
-
        free_pwms(chip);
 
        mutex_unlock(&pwm_lock);