pwm: mxs: Don't modify HW state in .probe() after the PWM chip was registered
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 7 Jul 2021 16:27:50 +0000 (18:27 +0200)
committerThierry Reding <thierry.reding@gmail.com>
Thu, 2 Sep 2021 19:38:36 +0000 (21:38 +0200)
This fixes a race condition: After pwmchip_add() is called there might
already be a consumer and then modifying the hardware behind the
consumer's back is bad. So reset before calling pwmchip_add().

Note that reseting the hardware isn't the right thing to do if the PWM
is already running as it might e.g. disable (or even enable) a backlight
that is supposed to be on (or off).

Fixes: 4dce82c1e840 ("pwm: add pwm-mxs support")
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-mxs.c

index a22180803bd7dd2b03f13f54e3843e2ad820b337..558dc1de8f5d5ef56cdc894a1505cea06327337a 100644 (file)
@@ -145,6 +145,11 @@ static int mxs_pwm_probe(struct platform_device *pdev)
                return ret;
        }
 
+       /* FIXME: Only do this if the PWM isn't already running */
+       ret = stmp_reset_block(mxs->base);
+       if (ret)
+               return dev_err_probe(&pdev->dev, ret, "failed to reset PWM\n");
+
        ret = pwmchip_add(&mxs->chip);
        if (ret < 0) {
                dev_err(&pdev->dev, "failed to add pwm chip %d\n", ret);
@@ -153,15 +158,7 @@ static int mxs_pwm_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, mxs);
 
-       ret = stmp_reset_block(mxs->base);
-       if (ret)
-               goto pwm_remove;
-
        return 0;
-
-pwm_remove:
-       pwmchip_remove(&mxs->chip);
-       return ret;
 }
 
 static int mxs_pwm_remove(struct platform_device *pdev)