diff mbox series

[1/3] wilc1000: use goto labels on error path

Message ID 20210806081229.721731-2-claudiu.beznea@microchip.com (mailing list archive)
State Accepted
Commit dc8b338f3bcd9be35a24d14104a2a28144232633
Delegated to: Kalle Valo
Headers show
Series wilc1000: minor cleanups | expand

Commit Message

Claudiu Beznea Aug. 6, 2021, 8:12 a.m. UTC
Use goto labels on error path for probe functions. This makes code easier
to read. With this introduce also netdev_cleanup and call it where
necessary.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/net/wireless/microchip/wilc1000/sdio.c | 16 ++++++++++------
 drivers/net/wireless/microchip/wilc1000/spi.c  | 16 ++++++++++------
 2 files changed, 20 insertions(+), 12 deletions(-)

Comments

Kalle Valo Aug. 21, 2021, 5:46 p.m. UTC | #1
Claudiu Beznea <claudiu.beznea@microchip.com> wrote:

> Use goto labels on error path for probe functions. This makes code easier
> to read. With this introduce also netdev_cleanup and call it where
> necessary.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>

3 patches applied to wireless-drivers-next.git, thanks.

dc8b338f3bcd wilc1000: use goto labels on error path
f36a0ee599c9 wilc1000: dispose irq on failure path
1d89fd1a39d1 wilc1000: use devm_clk_get_optional()
diff mbox series

Patch

diff --git a/drivers/net/wireless/microchip/wilc1000/sdio.c b/drivers/net/wireless/microchip/wilc1000/sdio.c
index e14b9fc2c67a..d11f245542e7 100644
--- a/drivers/net/wireless/microchip/wilc1000/sdio.c
+++ b/drivers/net/wireless/microchip/wilc1000/sdio.c
@@ -129,10 +129,8 @@  static int wilc_sdio_probe(struct sdio_func *func,
 
 	ret = wilc_cfg80211_init(&wilc, &func->dev, WILC_HIF_SDIO,
 				 &wilc_hif_sdio);
-	if (ret) {
-		kfree(sdio_priv);
-		return ret;
-	}
+	if (ret)
+		goto free;
 
 	if (IS_ENABLED(CONFIG_WILC1000_HW_OOB_INTR)) {
 		struct device_node *np = func->card->dev.of_node;
@@ -150,13 +148,19 @@  static int wilc_sdio_probe(struct sdio_func *func,
 
 	wilc->rtc_clk = devm_clk_get(&func->card->dev, "rtc");
 	if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) {
-		kfree(sdio_priv);
-		return -EPROBE_DEFER;
+		ret = -EPROBE_DEFER;
+		goto netdev_cleanup;
 	} else if (!IS_ERR(wilc->rtc_clk))
 		clk_prepare_enable(wilc->rtc_clk);
 
 	dev_info(&func->dev, "Driver Initializing success\n");
 	return 0;
+
+netdev_cleanup:
+	wilc_netdev_cleanup(wilc);
+free:
+	kfree(sdio_priv);
+	return ret;
 }
 
 static void wilc_sdio_remove(struct sdio_func *func)
diff --git a/drivers/net/wireless/microchip/wilc1000/spi.c b/drivers/net/wireless/microchip/wilc1000/spi.c
index 8e9aaf03a6fa..23d811b2b925 100644
--- a/drivers/net/wireless/microchip/wilc1000/spi.c
+++ b/drivers/net/wireless/microchip/wilc1000/spi.c
@@ -154,10 +154,8 @@  static int wilc_bus_probe(struct spi_device *spi)
 		return -ENOMEM;
 
 	ret = wilc_cfg80211_init(&wilc, &spi->dev, WILC_HIF_SPI, &wilc_hif_spi);
-	if (ret) {
-		kfree(spi_priv);
-		return ret;
-	}
+	if (ret)
+		goto free;
 
 	spi_set_drvdata(spi, wilc);
 	wilc->dev = &spi->dev;
@@ -166,12 +164,18 @@  static int wilc_bus_probe(struct spi_device *spi)
 
 	wilc->rtc_clk = devm_clk_get(&spi->dev, "rtc");
 	if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) {
-		kfree(spi_priv);
-		return -EPROBE_DEFER;
+		ret = -EPROBE_DEFER;
+		goto netdev_cleanup;
 	} else if (!IS_ERR(wilc->rtc_clk))
 		clk_prepare_enable(wilc->rtc_clk);
 
 	return 0;
+
+netdev_cleanup:
+	wilc_netdev_cleanup(wilc);
+free:
+	kfree(spi_priv);
+	return ret;
 }
 
 static int wilc_bus_remove(struct spi_device *spi)