diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2024-03-29 11:07:56 +0100 |
---|---|---|
committer | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2024-04-30 18:56:55 +0200 |
commit | c6837aa18016da3e524eb7bb51b8941c1ce8cd73 (patch) | |
tree | cde1dbfdae34861481d7f67d5bef5a21b48a37a7 /drivers/pwm | |
parent | 4c56b1434b814899c42a9d9f43d8265371282cd0 (diff) |
pwm: Don't check pointer for being non-NULL after use
After assigning chip = pwm->chip; the compiler is free to assume that
pwm is non-NULL and so can optimize out the check for pwm against NULL.
While it's probably a programming error to pass a NULL pointer to
pwm_put() this shouldn't be dropped without careful consideration and
wasn't intended.
So assign chip only after the NULL check.
Reported-by: David Lechner <dlechner@baylibre.com>
Link: https://lore.kernel.org/r/66a6f562-1fdd-4e45-995a-e7995432aa0c@baylibre.com
Fixes: 4c56b1434b81 ("pwm: Add a struct device to struct pwm_chip")
Link: https://lore.kernel.org/r/20240329101648.544155-2-u.kleine-koenig@pengutronix.de
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Diffstat (limited to 'drivers/pwm')
-rw-r--r-- | drivers/pwm/core.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 32871687c0a4..18574857641e 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -1525,11 +1525,13 @@ EXPORT_SYMBOL_GPL(pwm_get); */ void pwm_put(struct pwm_device *pwm) { - struct pwm_chip *chip = pwm->chip; + struct pwm_chip *chip; if (!pwm) return; + chip = pwm->chip; + mutex_lock(&pwm_lock); if (!test_and_clear_bit(PWMF_REQUESTED, &pwm->flags)) { |