Linux LED subsystem development
 help / color / mirror / Atom feed
From: Wang Yufen <wangyufen@huawei.com>
To: <linux-leds@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <pavel@ucw.cz>, Wang Yufen <wangyufen@huawei.com>,
	Baolin Wang <baolin.wang@linaro.org>
Subject: [PATCH 11/13] leds: sc27xx: Fix devm vs. non-devm ordering
Date: Wed, 9 Nov 2022 16:48:12 +0800	[thread overview]
Message-ID: <1667983694-15040-12-git-send-email-wangyufen@huawei.com> (raw)
In-Reply-To: <1667983694-15040-1-git-send-email-wangyufen@huawei.com>

When non-devm resources are allocated they mustn't be followed by devm
allocations, otherwise it will break the tear down ordering and might
lead to crashes or other bugs during ->remove() stage. Fix this by
wrapping mutex_destroy() call with devm_add_action_or_reset().

Fixes: e081c49e30ec ("leds: Add Spreadtrum SC27xx breathing light controller driver")
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
Cc: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/leds/leds-sc27xx-bltc.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/leds/leds-sc27xx-bltc.c b/drivers/leds/leds-sc27xx-bltc.c
index e199ea1..43a821c 100644
--- a/drivers/leds/leds-sc27xx-bltc.c
+++ b/drivers/leds/leds-sc27xx-bltc.c
@@ -273,6 +273,11 @@ static int sc27xx_led_register(struct device *dev, struct sc27xx_led_priv *priv)
 	return 0;
 }
 
+static void sc27xx_led_mutex_destroy(void *lock)
+{
+	mutex_destroy(lock);
+}
+
 static int sc27xx_led_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -297,6 +302,11 @@ static int sc27xx_led_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, priv);
 	mutex_init(&priv->lock);
+	err = devm_add_action_or_reset(dev, sc27xx_led_mutex_destroy,
+				       &priv->lock);
+	if (err)
+		return err;
+
 	priv->base = base;
 	priv->regmap = dev_get_regmap(dev->parent, NULL);
 	if (!priv->regmap) {
@@ -309,13 +319,11 @@ static int sc27xx_led_probe(struct platform_device *pdev)
 		err = of_property_read_u32(child, "reg", &reg);
 		if (err) {
 			of_node_put(child);
-			mutex_destroy(&priv->lock);
 			return err;
 		}
 
 		if (reg >= SC27XX_LEDS_MAX || priv->leds[reg].active) {
 			of_node_put(child);
-			mutex_destroy(&priv->lock);
 			return -EINVAL;
 		}
 
@@ -323,19 +331,7 @@ static int sc27xx_led_probe(struct platform_device *pdev)
 		priv->leds[reg].active = true;
 	}
 
-	err = sc27xx_led_register(dev, priv);
-	if (err)
-		mutex_destroy(&priv->lock);
-
-	return err;
-}
-
-static int sc27xx_led_remove(struct platform_device *pdev)
-{
-	struct sc27xx_led_priv *priv = platform_get_drvdata(pdev);
-
-	mutex_destroy(&priv->lock);
-	return 0;
+	return sc27xx_led_register(dev, priv);
 }
 
 static const struct of_device_id sc27xx_led_of_match[] = {
@@ -350,7 +346,6 @@ static int sc27xx_led_remove(struct platform_device *pdev)
 		.of_match_table = sc27xx_led_of_match,
 	},
 	.probe = sc27xx_led_probe,
-	.remove = sc27xx_led_remove,
 };
 
 module_platform_driver(sc27xx_led_driver);
-- 
1.8.3.1


  parent reply	other threads:[~2022-11-09  8:28 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09  8:48 [PATCH 00/13] leds: Fix devm vs. non-devm ordering Wang Yufen
2022-11-09  8:48 ` [PATCH 01/13] leds: cr0014114: " Wang Yufen
2022-11-09  8:48 ` [PATCH 02/13] leds: el15203000: " Wang Yufen
2022-11-09  9:39   ` Oleh Kravchenko
2022-11-09 10:25     ` wangyufen
2022-11-09 10:43       ` Oleh Kravchenko
     [not found]         ` <c53e4614-eb06-cda8-f9da-2ca58396df54@huawei.com>
2022-11-11 10:39           ` Oleh Kravchenko
2022-11-15  2:06             ` Wei Yongjun
2022-11-22  1:10               ` Wang Yufen
2022-11-25 22:21                 ` Oleh Kravchenko
2022-11-09  8:48 ` [PATCH 03/13] leds: lm3532: " Wang Yufen
2022-11-09  8:48 ` [PATCH 04/13] leds: lm3692x: " Wang Yufen
2022-11-09  8:48 ` [PATCH 05/13] leds: lm3697: " Wang Yufen
2022-11-09  8:48 ` [PATCH 06/13] leds: lp50xx: " Wang Yufen
2022-11-09  8:48 ` [PATCH 07/13] leds: lp8860: " Wang Yufen
2022-11-09  8:48 ` [PATCH 08/13] leds: mlxreg: " Wang Yufen
2022-11-09  8:48 ` [PATCH 09/13] leds: mt6323: " Wang Yufen
2022-11-09  8:48 ` [PATCH 10/13] leds: powernv: " Wang Yufen
2022-11-09  8:48 ` Wang Yufen [this message]
2022-11-09  8:48 ` [PATCH 12/13] leds: spi-byte: " Wang Yufen
2022-11-09  8:48 ` [PATCH 13/13] leds: rt8515: " Wang Yufen
2022-12-07 20:20 ` [PATCH 00/13] leds: " Pavel Machek
2022-12-08  2:23   ` wangyufen

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=1667983694-15040-12-git-send-email-wangyufen@huawei.com \
    --to=wangyufen@huawei.com \
    --cc=baolin.wang@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox