Commit 50be9e02 authored by Chunyan Zhang's avatar Chunyan Zhang Committed by Lee Jones

leds: sc27xx: Move mutex_init() down

Move the mutex_init() to avoid redundant mutex_destroy() calls after
that for each time the probe fails.
Signed-off-by: default avatarChunyan Zhang <chunyan.zhang@unisoc.com>
Reviewed-by: default avatarBaolin Wang <baolin.wang@linux.alibaba.com>
Link: https://lore.kernel.org/r/20231013022010.854367-1-chunyan.zhang@unisoc.comSigned-off-by: default avatarLee Jones <lee@kernel.org>
parent 259e33cb
...@@ -296,7 +296,6 @@ static int sc27xx_led_probe(struct platform_device *pdev) ...@@ -296,7 +296,6 @@ static int sc27xx_led_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
platform_set_drvdata(pdev, priv); platform_set_drvdata(pdev, priv);
mutex_init(&priv->lock);
priv->base = base; priv->base = base;
priv->regmap = dev_get_regmap(dev->parent, NULL); priv->regmap = dev_get_regmap(dev->parent, NULL);
if (!priv->regmap) { if (!priv->regmap) {
...@@ -309,13 +308,11 @@ static int sc27xx_led_probe(struct platform_device *pdev) ...@@ -309,13 +308,11 @@ static int sc27xx_led_probe(struct platform_device *pdev)
err = of_property_read_u32(child, "reg", &reg); err = of_property_read_u32(child, "reg", &reg);
if (err) { if (err) {
of_node_put(child); of_node_put(child);
mutex_destroy(&priv->lock);
return err; return err;
} }
if (reg >= SC27XX_LEDS_MAX || priv->leds[reg].active) { if (reg >= SC27XX_LEDS_MAX || priv->leds[reg].active) {
of_node_put(child); of_node_put(child);
mutex_destroy(&priv->lock);
return -EINVAL; return -EINVAL;
} }
...@@ -323,6 +320,8 @@ static int sc27xx_led_probe(struct platform_device *pdev) ...@@ -323,6 +320,8 @@ static int sc27xx_led_probe(struct platform_device *pdev)
priv->leds[reg].active = true; priv->leds[reg].active = true;
} }
mutex_init(&priv->lock);
err = sc27xx_led_register(dev, priv); err = sc27xx_led_register(dev, priv);
if (err) if (err)
mutex_destroy(&priv->lock); mutex_destroy(&priv->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment