Skip to contentSkip to conversation

Use devm_spi_alloc_host() to simplfy code

PATCH In review Jinjie Ruan 3 participants 5 messages Aug 26, 2024 – Aug 30, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Use devm_spi_alloc_host() to simplfy code

Use devm_spi_alloc_host() and dev_err_probe() to simplfy code.

Jinjie Ruan (2):
spi: zynqmp-gqspi: Use devm_spi_alloc_host()
spi: zynqmp-gqspi: Simplify with dev_err_probe()

 drivers/spi/spi-zynqmp-gqspi.c | 32 +++++++++++---------------------
 1 file changed, 11 insertions(+), 21 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 spi: zynqmp-gqspi: Use devm_spi_alloc_host()

Use devm_spi_alloc_host() so that there's no need to call spi_controller_put() in the error path.

---
 drivers/spi/spi-zynqmp-gqspi.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +6 -12
index 558c466135a5..597fcc7fce82 100644
@@ -1242,7 +1242,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
 	u32 num_cs;
 	const struct qspi_platform_data *p_data;
 
-	ctlr = spi_alloc_host(&pdev->dev, sizeof(*xqspi));
+	ctlr = devm_spi_alloc_host(&pdev->dev, sizeof(*xqspi));
 	if (!ctlr)
 		return -ENOMEM;
 
@@ -1256,29 +1256,25 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
 		xqspi->has_tapdelay = true;
 
 	xqspi->regs = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(xqspi->regs)) {
-		ret = PTR_ERR(xqspi->regs);
-		goto remove_ctlr;
-	}
+	if (IS_ERR(xqspi->regs))
+		return PTR_ERR(xqspi->regs);
 
 	xqspi->pclk = devm_clk_get(&pdev->dev, "pclk");
 	if (IS_ERR(xqspi->pclk)) {
 		dev_err(dev, "pclk clock not found.\n");
-		ret = PTR_ERR(xqspi->pclk);
-		goto remove_ctlr;
+		return PTR_ERR(xqspi->pclk);
 	}
 
 	xqspi->refclk = devm_clk_get(&pdev->dev, "ref_clk");
 	if (IS_ERR(xqspi->refclk)) {
 		dev_err(dev, "ref_clk clock not found.\n");
-		ret = PTR_ERR(xqspi->refclk);
-		goto remove_ctlr;
+		return PTR_ERR(xqspi->refclk);
 	}
 
 	ret = clk_prepare_enable(xqspi->pclk);
 	if (ret) {
 		dev_err(dev, "Unable to enable APB clock.\n");
-		goto remove_ctlr;
+		return ret;
 	}
 
 	ret = clk_prepare_enable(xqspi->refclk);
@@ -1364,8 +1360,6 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
 	clk_disable_unprepare(xqspi->refclk);
 clk_dis_pclk:
 	clk_disable_unprepare(xqspi->pclk);
-remove_ctlr:
-	spi_controller_put(ctlr);
 
 	return ret;
 }
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/2 spi: zynqmp-gqspi: Simplify with dev_err_probe()

In reply to Jinjie Ruan

Use the dev_err_probe() helper to simplify error handling during probe. This also handle scenario, when EDEFER is returned and useless error is printed.

---
 drivers/spi/spi-zynqmp-gqspi.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +8 -12
index 597fcc7fce82..fcd0ca996684 100644
@@ -1260,22 +1260,18 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
 		return PTR_ERR(xqspi->regs);
 
 	xqspi->pclk = devm_clk_get(&pdev->dev, "pclk");
-	if (IS_ERR(xqspi->pclk)) {
-		dev_err(dev, "pclk clock not found.\n");
-		return PTR_ERR(xqspi->pclk);
-	}
+	if (IS_ERR(xqspi->pclk))
+		return dev_err_probe(dev, PTR_ERR(xqspi->pclk),
+				     "pclk clock not found.\n");
 
 	xqspi->refclk = devm_clk_get(&pdev->dev, "ref_clk");
-	if (IS_ERR(xqspi->refclk)) {
-		dev_err(dev, "ref_clk clock not found.\n");
-		return PTR_ERR(xqspi->refclk);
-	}
+	if (IS_ERR(xqspi->refclk))
+		return dev_err_probe(dev, PTR_ERR(xqspi->refclk),
+				     "ref_clk clock not found.\n");
 
 	ret = clk_prepare_enable(xqspi->pclk);
-	if (ret) {
-		dev_err(dev, "Unable to enable APB clock.\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "Unable to enable APB clock.\n");
 
 	ret = clk_prepare_enable(xqspi->refclk);
 	if (ret) {
Signature · 1 line
2.34.1
maintainer Acked-by on the v1 series
#3 lore raw
In reply to Jinjie Ruan
Quoted 9 lines · Jinjie Ruan

Use devm_spi_alloc_host() and dev_err_probe() to simplfy code.

Jinjie Ruan (2):
spi: zynqmp-gqspi: Use devm_spi_alloc_host()
spi: zynqmp-gqspi: Simplify with dev_err_probe()

  drivers/spi/spi-zynqmp-gqspi.c | 32 +++++++++++---------------------
  1 file changed, 11 insertions(+), 21 deletions(-)

Thanks,
Michal

maintainer
#4 lore raw
In reply to Jinjie Ruan
Quoted 10 lines · Jinjie Ruan

Use devm_spi_alloc_host() and dev_err_probe() to simplfy code.

Jinjie Ruan (2):
spi: zynqmp-gqspi: Use devm_spi_alloc_host()
spi: zynqmp-gqspi: Simplify with dev_err_probe()

drivers/spi/spi-zynqmp-gqspi.c | 32 +++++++++++---------------------

 1 file changed, 11 insertions(+), 21 deletions(-)

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/2] spi: zynqmp-gqspi: Use devm_spi_alloc_host()

      commit: 64640f6c972e80f52196416a8d4dc3c0ffcbc82d
[2/2] spi: zynqmp-gqspi: Simplify with dev_err_probe()
      commit: d814fd0f046c2a6b1a919e1a529550bdfe9f9f9b

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark