Skip to contentSkip to conversation

ASoc: kirkwood: simplify probe error

PATCH Superseded Jean-Francois Moine 3 participants 7 messages Jul 31, 2013 – Aug 3, 2013

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/4 ASoc: kirkwood: simplify probe error

The function kirkwood_i2s_dev_remove() may be used when probe fails.

---
 sound/soc/kirkwood/kirkwood-i2s.c           | 40 +++++++++++-----------
 1 file changed, 20 insertions(+), 20 deletions(-)
sound/soc/kirkwood/kirkwood-i2s.c +20 -20
index 0109b1e..319086f 100644
@@ -449,6 +449,19 @@ static const struct snd_soc_component_driver kirkwood_i2s_component = {
 	.name		= DRV_NAME,
 };
 
+static int kirkwood_i2s_dev_remove(struct platform_device *pdev)
+{
+	struct kirkwood_dma_data *priv = dev_get_drvdata(&pdev->dev);
+
+	snd_soc_unregister_component(&pdev->dev);
+
+	if (!IS_ERR(priv->extclk))
+		clk_disable_unprepare(priv->extclk);
+	clk_disable_unprepare(priv->clk);
+
+	return 0;
+}
+
 static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
 {
 	struct kirkwood_asoc_platform_data *data = pdev->dev.platform_data;
@@ -519,30 +532,17 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
 
 	err = snd_soc_register_component(&pdev->dev, &kirkwood_i2s_component,
 					 soc_dai, 1);
-	if (!err)
-		return 0;
-	dev_err(&pdev->dev, "snd_soc_register_component failed\n");
-
-	if (!IS_ERR(priv->extclk))
-		clk_disable_unprepare(priv->extclk);
-	clk_disable_unprepare(priv->clk);
+	if (err) {
+		dev_err(&pdev->dev, "snd_soc_register_component failed\n");
+		goto fail;
+	}
+	return 0;
 
+fail:
+	kirkwood_i2s_dev_remove(pdev);
 	return err;
 }
 
-static int kirkwood_i2s_dev_remove(struct platform_device *pdev)
-{
-	struct kirkwood_dma_data *priv = dev_get_drvdata(&pdev->dev);
-
-	snd_soc_unregister_component(&pdev->dev);
-
-	if (!IS_ERR(priv->extclk))
-		clk_disable_unprepare(priv->extclk);
-	clk_disable_unprepare(priv->clk);
-
-	return 0;
-}
-
 static struct platform_driver kirkwood_i2s_driver = {
 	.probe  = kirkwood_i2s_dev_probe,
 	.remove = kirkwood_i2s_dev_remove,
Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
#1 lore raw
Quoted 6 lines · Jean-Francois Moine
sound/soc/kirkwood/kirkwood-i2s.c +0 -2
@@ -519,30 +532,17 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
 
 	err = snd_soc_register_component(&pdev->dev, &kirkwood_i2s_component,
 					 soc_dai, 1);
-	if (!err)
-		return 0;

sound/soc/kirkwood/kirkwood-i2s.c static int kirkwood_i2s_dev_probe(struct platform_device *pdev) · line 539

Quoted 10 lines
sound/soc/kirkwood/kirkwood-i2s.c +5 -5
-	dev_err(&pdev->dev, "snd_soc_register_component failed\n");
-
-	if (!IS_ERR(priv->extclk))
-		clk_disable_unprepare(priv->extclk);
-	clk_disable_unprepare(priv->clk);
+	if (err) {
+		dev_err(&pdev->dev, "snd_soc_register_component failed\n");
+		goto fail;
+	}
+	return 0;

This doesn't apply to mainline as there's a clk_put() there.

#5 lore raw
In reply to Jean-Francois Moine
Quoted 1 line · Jean-Francois Moine

The function kirkwood_i2s_dev_remove() may be used when probe fails.

Looking at this deeper, I'm not happy with this.

Quoted 5 lines
sound/soc/kirkwood/kirkwood-i2s.c +5 -0
+static int kirkwood_i2s_dev_remove(struct platform_device *pdev)
+{
+	struct kirkwood_dma_data *priv = dev_get_drvdata(&pdev->dev);
+
+	snd_soc_unregister_component(&pdev->dev);

...

sound/soc/kirkwood/kirkwood-i2s.c static int kirkwood_i2s_dev_probe(struct platform_device *pdev) · line 542

Quoted 12 lines
sound/soc/kirkwood/kirkwood-i2s.c +7 -0
@@ -519,30 +532,17 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
 
 	err = snd_soc_register_component(&pdev->dev, &kirkwood_i2s_component,
 					 soc_dai, 1);
+	if (err) {
+		dev_err(&pdev->dev, "snd_soc_register_component failed\n");
+		goto fail;
+	}
+	return 0;
 
+fail:
+	kirkwood_i2s_dev_remove(pdev);

What this means is that if snd_soc_register_component() fails, we end up calling snd_soc_unregister_component(). This may be fine with the way snd_soc_unregister_component() is currently implemented, but you're making the assumption that it's fine to call snd_soc_unregister_component() for a device which hasn't been registered. Technically, this is a layering violation, which makes this change fragile if the behaviour of snd_soc_unregister_component() changes in the future.

For the sake of two calls in the error path, I don't think the benefits of this patch outweigh the risk.

#2 lore raw
In reply to Russell King - ARM Linux
Quoted 1 line · On Sat, 3 Aug 2013 13:39:54 +0100 Russell King - ARM Linux…

This doesn't apply to mainline as there's a clk_put() there.

Right, it applies to linux-next:

Quoted 2 lines · Mark Brown

Always submit against where the code will be applied - -next in this case.

Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
#3 lore raw
Quoted 11 lines · Jean-Francois Moine
Quoted 1 line · On Sat, 3 Aug 2013 13:39:54 +0100 Russell King - ARM Linux…

This doesn't apply to mainline as there's a clk_put() there.

Right, it applies to linux-next:

Quoted 2 lines · Mark Brown

Always submit against where the code will be applied - -next in this case.

Sorry, I'm just not going to bother with your patches unless you start posting them in such a way that interested parties can test them without having to run around and pull random trees. In other words, you should have Cc'd interested parties on that devm_* change patch - especially myself as I was the one who introduced that code.

maintainer
#4 lore raw
Quoted 3 lines · Russell King - ARM Linux

having to run around and pull random trees. In other words, you should have Cc'd interested parties on that devm_* change patch - especially myself as I was the one who introduced that code.

That was me, sorry - Jean-Francios had nothing to do with the patch.

#6 lore raw
In reply to Russell King - ARM Linux
Quoted 4 lines · On Sat, 3 Aug 2013 13:46:52 +0100 Russell King - ARM Linux…
Quoted 1 line · Jean-Francois Moine

The function kirkwood_i2s_dev_remove() may be used when probe fails.

Looking at this deeper, I'm not happy with this.

	[snip]
Quoted 10 lines

What this means is that if snd_soc_register_component() fails, we end up calling snd_soc_unregister_component(). This may be fine with the way snd_soc_unregister_component() is currently implemented, but you're making the assumption that it's fine to call snd_soc_unregister_component() for a device which hasn't been registered. Technically, this is a layering violation, which makes this change fragile if the behaviour of snd_soc_unregister_component() changes in the future.

For the sake of two calls in the error path, I don't think the benefits of this patch outweigh the risk.

You are right, but if snd_soc_unregister_component() could be officially used safely with no previous call to snd_soc_register_component(), this would simplify error handling in other drivers too...

Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/