All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Thierry Reding <thierry.reding@gmail.com>,
	Lee Jones <lee.jones@linaro.org>
Cc: linux-pwm@vger.kernel.org, kernel@pengutronix.de,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Shawn Guo <shawnguo@kernel.org>
Subject: [PATCH 02/47] pwm: mxs: Don't modify HW state in .probe() after the PWM chip was registered
Date: Wed,  7 Jul 2021 18:27:50 +0200	[thread overview]
Message-ID: <20210707162835.1772882-3-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20210707162835.1772882-1-u.kleine-koenig@pengutronix.de>

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>
---
 drivers/pwm/pwm-mxs.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c
index a22180803bd7..558dc1de8f5d 100644
--- a/drivers/pwm/pwm-mxs.c
+++ b/drivers/pwm/pwm-mxs.c
@@ -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)
-- 
2.30.2


  parent reply	other threads:[~2021-07-07 16:28 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-07 16:27 [PATCH 00/47] pwm: Make pwmchip_remove return void Uwe Kleine-König
2021-07-07 16:27 ` [PATCH 01/47] pwm: lpc32xx: Don't modify HW state in .probe() after the PWM chip was registered Uwe Kleine-König
2021-07-07 16:27 ` Uwe Kleine-König [this message]
2021-07-07 16:27 ` [PATCH 03/47] pwm: img: Don't modify HW state in .remove() callback Uwe Kleine-König
2021-07-07 16:27 ` [PATCH 04/47] pwm: rockchip: " Uwe Kleine-König
2021-07-07 16:27 ` [PATCH 05/47] pwm: stm32-lp: " Uwe Kleine-König
2021-07-07 16:27 ` [PATCH 06/47] pwm: hibvt: Disable the clock only after the PWM was unregistered Uwe Kleine-König
2021-07-07 16:27 ` [PATCH 07/47] pwm: rockchip: Unprepare clocks " Uwe Kleine-König
2021-07-07 16:27 ` [PATCH 08/47] pwm: tiehrpwm: Unprepare clock " Uwe Kleine-König
2021-07-07 16:27 ` [PATCH 09/47] pwm: ntxec: Drop useless assignment to struct pwmchip::base Uwe Kleine-König
2021-07-07 16:27 ` [PATCH 10/47] pwm: jz4740: Improve compile coverage by allowing to enable on !MIPS Uwe Kleine-König
2021-07-07 16:27 ` [PATCH 11/47] pwm: keembay: Improve compile coverage by allowing to enable on !ARM64 Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 12/47] pwm: ab8500: Simplify using devm_pwmchip_add() Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 13/47] pwm: bcm-kona: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 14/47] pwm: ep93xx: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 15/47] pwm: fsl-ftm: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 16/47] pwm: imx27: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 17/47] pwm: intel-lgm: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 18/47] pwm: iqs620a: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 19/47] pwm: jz4740: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 20/47] pwm: keembay: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 21/47] pwm: lp3943: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 22/47] pwm: lpc32xx: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 23/47] pwm: mediatek: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 24/47] pwm: mxs: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 25/47] pwm: ntxec: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 26/47] pwm: pxa: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 27/47] pwm: raspberrypi-poe: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 28/47] pwm: sl28cpld: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 29/47] pwm: stm32-lp: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 30/47] pwm: tiecap: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 31/47] pwm: twl-led: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 32/47] pwm: twl: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 33/47] pwm: atmel-hlcdc: Don't check the return code of pwmchip_remove() Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 34/47] pwm: atmel-tcb: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 35/47] pwm: brcmstb: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 36/47] pwm: cros-ec: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 37/47] pwm: img: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 38/47] pwm: imx-tpm: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 39/47] pwm: mtk-disp: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 40/47] pwm: omap-dmtimer: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 41/47] pwm: pca9685: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 42/47] pwm: rcar: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 43/47] pwm: renesas-tpu: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 44/47] pwm: samsung: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 45/47] pwm: sifive: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 46/47] pwm: sun4i: " Uwe Kleine-König
2021-07-07 16:28 ` [PATCH 47/47] pwm: Make pwmchip_remove() return void Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210707162835.1772882-3-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=kernel@pengutronix.de \
    --cc=lee.jones@linaro.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.