diff mbox series

[-next,5/6] spi: sh-sci: Switch to use devm_spi_alloc_master()

Message ID 20220920134819.2981033-6-yangyingliang@huawei.com
State New
Headers show
Series spi: Switch to use devm_spi_alloc_master() in some drivers | expand

Commit Message

Yang Yingliang Sept. 20, 2022, 1:48 p.m. UTC
Switch to use devm_spi_alloc_master() to simpify error path.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/spi/spi-sh-sci.c | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)
diff mbox series

Patch

diff --git a/drivers/spi/spi-sh-sci.c b/drivers/spi/spi-sh-sci.c
index 8f30531e1418..2cd5cd23e37c 100644
--- a/drivers/spi/spi-sh-sci.c
+++ b/drivers/spi/spi-sh-sci.c
@@ -118,11 +118,10 @@  static int sh_sci_spi_probe(struct platform_device *dev)
 	struct sh_sci_spi *sp;
 	int ret;
 
-	master = spi_alloc_master(&dev->dev, sizeof(struct sh_sci_spi));
+	master = devm_spi_alloc_master(&dev->dev, sizeof(struct sh_sci_spi));
 	if (master == NULL) {
 		dev_err(&dev->dev, "failed to allocate spi master\n");
-		ret = -ENOMEM;
-		goto err0;
+		return -ENOMEM;
 	}
 
 	sp = spi_master_get_devdata(master);
@@ -131,8 +130,7 @@  static int sh_sci_spi_probe(struct platform_device *dev)
 	sp->info = dev_get_platdata(&dev->dev);
 	if (!sp->info) {
 		dev_err(&dev->dev, "platform data is missing\n");
-		ret = -ENOENT;
-		goto err1;
+		return -ENOENT;
 	}
 
 	/* setup spi bitbang adaptor */
@@ -147,28 +145,22 @@  static int sh_sci_spi_probe(struct platform_device *dev)
 	sp->bitbang.txrx_word[SPI_MODE_3] = sh_sci_spi_txrx_mode3;
 
 	r = platform_get_resource(dev, IORESOURCE_MEM, 0);
-	if (r == NULL) {
-		ret = -ENOENT;
-		goto err1;
-	}
+	if (r == NULL)
+		return -ENOENT;
 	sp->membase = ioremap(r->start, resource_size(r));
-	if (!sp->membase) {
-		ret = -ENXIO;
-		goto err1;
-	}
+	if (!sp->membase)
+		return -ENXIO;
 	sp->val = ioread8(SCSPTR(sp));
 	setbits(sp, PIN_INIT, 1);
 
 	ret = spi_bitbang_start(&sp->bitbang);
-	if (!ret)
-		return 0;
+	if (ret) {
+		setbits(sp, PIN_INIT, 0);
+		iounmap(sp->membase);
+		return ret;
+	}
 
-	setbits(sp, PIN_INIT, 0);
-	iounmap(sp->membase);
- err1:
-	spi_master_put(sp->bitbang.master);
- err0:
-	return ret;
+	return 0;
 }
 
 static int sh_sci_spi_remove(struct platform_device *dev)