Skip to contentSkip to conversation

mfd: Move error handling to the end of mc13xxx_probe

PATCH In review Axel Lin 2 participants 2 messages Jan 3, 2011 Multifunction devices (MFD)

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 mfd: Move error handling to the end of mc13xxx_probe

To improve readability, move error handling to the end of mc13xxx_probe.

---
 drivers/mfd/mc13xxx-core.c |   22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)
drivers/mfd/mc13xxx-core.c +10 -12
index b9fcaf0..18c29fc 100644
@@ -732,28 +732,21 @@ static int mc13xxx_probe(struct spi_device *spi)
 
 	ret = mc13xxx_identify(mc13xxx, &id);
 	if (ret || id == MC13XXX_ID_INVALID)
-		goto err_revision;
+		goto err;
 
 	/* mask all irqs */
 	ret = mc13xxx_reg_write(mc13xxx, MC13XXX_IRQMASK0, 0x00ffffff);
 	if (ret)
-		goto err_mask;
+		goto err;
 
 	ret = mc13xxx_reg_write(mc13xxx, MC13XXX_IRQMASK1, 0x00ffffff);
 	if (ret)
-		goto err_mask;
+		goto err;
 
 	ret = request_threaded_irq(spi->irq, NULL, mc13xxx_irq_thread,
 			IRQF_ONESHOT | IRQF_TRIGGER_HIGH, "mc13xxx", mc13xxx);
-
-	if (ret) {
-err_mask:
-err_revision:
-		mc13xxx_unlock(mc13xxx);
-		dev_set_drvdata(&spi->dev, NULL);
-		kfree(mc13xxx);
-		return ret;
-	}
+	if (ret)
+		goto err;
 
 	mc13xxx_unlock(mc13xxx);
 
@@ -785,6 +778,11 @@ err_revision:
 	}
 
 	return 0;
+err:
+	mc13xxx_unlock(mc13xxx);
+	dev_set_drvdata(&spi->dev, NULL);
+	kfree(mc13xxx);
+	return ret;
 }
 
 static int __devexit mc13xxx_remove(struct spi_device *spi)
Signature · 1 line
1.7.2
#1 lore raw
Quoted 1 line · Axel Lin

To improve readability, move error handling to the end of mc13xxx_probe.

I like the way it was done before (obviously as I wrote the code). Though I don't feel strongly against the move. Still I prefer the more explicit error labels.

On a scale between -1 and 1 it would get a -0 from me.

Best regards
Uwe

Quoted 61 lines
---
 drivers/mfd/mc13xxx-core.c |   22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)
drivers/mfd/mc13xxx-core.c +10 -12
index b9fcaf0..18c29fc 100644
@@ -732,28 +732,21 @@ static int mc13xxx_probe(struct spi_device *spi)
 
 	ret = mc13xxx_identify(mc13xxx, &id);
 	if (ret || id == MC13XXX_ID_INVALID)
-		goto err_revision;
+		goto err;
 
 	/* mask all irqs */
 	ret = mc13xxx_reg_write(mc13xxx, MC13XXX_IRQMASK0, 0x00ffffff);
 	if (ret)
-		goto err_mask;
+		goto err;
 
 	ret = mc13xxx_reg_write(mc13xxx, MC13XXX_IRQMASK1, 0x00ffffff);
 	if (ret)
-		goto err_mask;
+		goto err;
 
 	ret = request_threaded_irq(spi->irq, NULL, mc13xxx_irq_thread,
 			IRQF_ONESHOT | IRQF_TRIGGER_HIGH, "mc13xxx", mc13xxx);
-
-	if (ret) {
-err_mask:
-err_revision:
-		mc13xxx_unlock(mc13xxx);
-		dev_set_drvdata(&spi->dev, NULL);
-		kfree(mc13xxx);
-		return ret;
-	}
+	if (ret)
+		goto err;
 
 	mc13xxx_unlock(mc13xxx);
 
@@ -785,6 +778,11 @@ err_revision:
 	}
 
 	return 0;
+err:
+	mc13xxx_unlock(mc13xxx);
+	dev_set_drvdata(&spi->dev, NULL);
+	kfree(mc13xxx);
+	return ret;
 }
 
 static int __devexit mc13xxx_remove(struct spi_device *spi)
Signature · 1 line
1.7.2
Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |