Skip to contentSkip to conversation

leds: sc27xx: Move mutex_init() down

PATCH Applied Chunyan Zhang 3 participants 3 messages Oct 13, 2023 – Oct 19, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 leds: sc27xx: Move mutex_init() down

Move the mutex_init() to avoid redundant mutex_destroy() calls after that for each time the probe fails.

---
Rebased onto linux-next.

V3: Move the mutex_init() before sc27xx_led_register(), in case it maybe used right after led registerd.

V2: Move the mutex_init() to the end of .probe() instead of adding mutex_destroy().

---
 drivers/leds/leds-sc27xx-bltc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/leds/leds-sc27xx-bltc.c +2 -3
index af1f00a2f328..f04db793e8d6 100644
@@ -296,7 +296,6 @@ static int sc27xx_led_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	platform_set_drvdata(pdev, priv);
-	mutex_init(&priv->lock);
 	priv->base = base;
 	priv->regmap = dev_get_regmap(dev->parent, NULL);
 	if (!priv->regmap) {
@@ -309,13 +308,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,6 +320,8 @@ static int sc27xx_led_probe(struct platform_device *pdev)
 		priv->leds[reg].active = true;
 	}
 
+	mutex_init(&priv->lock);
+
 	err = sc27xx_led_register(dev, priv);
 	if (err)
 		mutex_destroy(&priv->lock);
Signature · 1 line
2.41.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 4 lines · Chunyan Zhang

Move the mutex_init() to avoid redundant mutex_destroy() calls after that for each time the probe fails.

LGTM. Thanks.

Quoted 46 lines

---
Rebased onto linux-next.

V3: Move the mutex_init() before sc27xx_led_register(), in case it maybe used right after led registerd.

V2: Move the mutex_init() to the end of .probe() instead of adding mutex_destroy().

---
  drivers/leds/leds-sc27xx-bltc.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/leds/leds-sc27xx-bltc.c +2 -3
index af1f00a2f328..f04db793e8d6 100644
@@ -296,7 +296,6 @@ static int sc27xx_led_probe(struct platform_device *pdev)
  		return -ENOMEM;
 
  	platform_set_drvdata(pdev, priv);
-	mutex_init(&priv->lock);
  	priv->base = base;
  	priv->regmap = dev_get_regmap(dev->parent, NULL);
  	if (!priv->regmap) {
@@ -309,13 +308,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,6 +320,8 @@ static int sc27xx_led_probe(struct platform_device *pdev)
  		priv->leds[reg].active = true;
  	}
 
+	mutex_init(&priv->lock);
+
  	err = sc27xx_led_register(dev, priv);
  	if (err)
  		mutex_destroy(&priv->lock);
maintainer Applied
#2 lore raw

Re: (subset) [PATCH V3] leds: sc27xx: Move mutex_init() down

In reply to Chunyan Zhang
Quoted 4 lines · Chunyan Zhang

Move the mutex_init() to avoid redundant mutex_destroy() calls after that for each time the probe fails.

Applied, thanks!

[1/1] leds: sc27xx: Move mutex_init() down

      commit: 8f3a620c7830d7b50d32614d48c4b7df7205309a

--
Lee Jones [李琼斯]