cleanups in spi
Subsystems (4)
cover cleanups in spi
hi Mark,
Some cleanups in spi. Thanks!
1.spi: uniphier: Simplify clock handling with devm_clk_get_enabled() It might be that the previous unused variable caused it not to be merged.
2.spi: zynq-qspi: Simplify clock handling with devm_clk_get_enabled() It was not merged. Upon checking, runtime is not used.
3.spi: mtk-snfi: unregister ECC engine on probe failure and remove()
callback
'copy from' b0dc7e7c56573e7a52080f25f3179a45f3dd7e6f
spi: amlogic: spifc-a4: unregister ECC engine on probe failure and remove() callback
4.ch341
In Chinese, the pronunciation of this manufacturer includes an 'n' sound. It's a bit strange that the manufacturer's name was wrong, so I still want to correct it.
Pei Xiao (4):
spi: mtk-snfi: unregister ECC engine on probe failure and remove()
callback
spi: uniphier: Simplify clock handling with devm_clk_get_enabled()
spi: zynq-qspi: Simplify clock handling with devm_clk_get_enabled()
spi: ch341: Correct vendor name
drivers/spi/spi-ch341.c | 4 ++-- drivers/spi/spi-mtk-snfi.c | 14 ++++++++++++++ drivers/spi/spi-uniphier.c | 18 ++++-------------- drivers/spi/spi-zynq-qspi.c | 31 ++++++------------------------- 4 files changed, 26 insertions(+), 41 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/4 spi: mtk-snfi: unregister ECC engine on probe failure and remove() callback
mtk_snand_probe() registers the on-host NAND ECC engine, but teardown was missing from both probe unwind and remove-time cleanup. Add a devm cleanup action after successful registration so nand_ecc_unregister_on_host_hw_engine() runs automatically on probe failures and during device removal.
--- drivers/spi/spi-mtk-snfi.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/spi/spi-mtk-snfi.c +14 -0
@@ -1303,6 +1303,13 @@ static const struct spi_controller_mem_caps mtk_snand_mem_caps = { .ecc = true, }; +static void mtk_unregister_ecc_engine (void *data) +{ +struct nand_ecc_engine *eng = data; + +nand_ecc_unregister_on_host_hw_engine (eng); +} +static irqreturn_t mtk_snand_irq (int irq,void *id) {struct mtk_snand *snf = id;
@@ -1443,6 +1450,13 @@ static int mtk_snand_probe(struct platform_device *pdev) goto release_ecc; } + ret =devm_add_action_or_reset (&pdev->dev, mtk_unregister_ecc_engine, + &ms->ecc_eng); +if (ret) { +dev_err (&pdev->dev, ret,"failed to add ECC unregister action\n" ); + goto release_ecc; + } + ctlr->num_chipselect =1 ; ctlr->mem_ops = &mtk_snand_mem_ops; ctlr->mem_caps = &mtk_snand_mem_caps;
Signature · 1 line
2.25.1
Mark Brown
maintainerRe: [PATCH 1/4] spi: mtk-snfi: unregister ECC engine on probe failure and remove() callback
drivers/spi/spi-mtk-snfi.c static int mtk_snand_probe(struct platform_device *pdev) · line 1458
Quoted 6 lines · Pei Xiao
drivers/spi/spi-mtk-snfi.c +6
-0+ ret =devm_add_action_or_reset (&pdev->dev, mtk_unregister_ecc_engine, + &ms->ecc_eng); +if (ret) { +dev_err (&pdev->dev, ret,"failed to add ECC unregister action\n" ); + goto release_ecc; + }
This should either be dev_err(), in which case ret is not a format string and this is buggy (I'm surprised it compiles without warnings...) or it should be dev_err_probe() in which case the arguments are correct. The latter is a little better, though it's unlikely to make a practical difference here.
Re: [PATCH 1/4] spi: mtk-snfi: unregister ECC engine on probe failure and remove() callback
Quoted 12 lines · Mark Brown
drivers/spi/spi-mtk-snfi.c static int mtk_snand_probe(struct platform_device *pdev) · line 1458
Quoted 6 lines · Pei Xiao
drivers/spi/spi-mtk-snfi.c +6
-0+ ret =devm_add_action_or_reset (&pdev->dev, mtk_unregister_ecc_engine, + &ms->ecc_eng); +if (ret) { +dev_err (&pdev->dev, ret,"failed to add ECC unregister action\n" ); + goto release_ecc; + }This should either be
dev_err(), in which case ret is not a format string and this is buggy (I'm surprised it compiles without warnings...) or it should bedev_err_probe()in which case the arguments are correct.
ok, thanks a lot, from a person make bug.
I will send v2.
Pei.
Quoted 2 lines
The latter is a little better, though it's unlikely to make a practical difference here.
PATCH 2/4 spi: uniphier: Simplify clock handling with devm_clk_get_enabled()
In reply to Pei XiaoReplace devm_clk_get() followed by clk_prepare_enable() with devm_clk_get_enabled() for the clock. This removes the need for explicit clock enable and disable calls, as the managed API automatically handles clock disabling on device removal or probe failure.
Remove the now-unnecessary clk_disable_unprepare() calls from the probe error path and the remove callback. Adjust error labels accordingly.
--- drivers/spi/spi-uniphier.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/spi/spi-uniphier.c +4 -14
@@ -666,28 +666,24 @@ static int uniphier_spi_probe(struct platform_device *pdev) } priv->base_dma_addr = res->start; - priv->clk =devm_clk_get (&pdev->dev,NULL ); + priv->clk =devm_clk_get_enabled (&pdev->dev,NULL );if (IS_ERR (priv->clk)) {dev_err (&pdev->dev,"failed to get clock\n" ); ret =PTR_ERR (priv->clk); goto out_host_put; } - ret =clk_prepare_enable (priv->clk); -if (ret) - goto out_host_put; - irq =platform_get_irq (pdev,0 );if (irq <0 ) { ret = irq; - goto out_disable_clk; + goto out_host_put; } ret =devm_request_irq (&pdev->dev, irq, uniphier_spi_handler,0 ,"uniphier-spi" , priv);if (ret) {dev_err (&pdev->dev,"failed to request IRQ\n" ); - goto out_disable_clk; + goto out_host_put; }init_completion (&priv->xfer_done);
@@ -716,7 +712,7 @@ static int uniphier_spi_probe(struct platform_device *pdev)if (IS_ERR_OR_NULL (host->dma_tx)) {if (PTR_ERR (host->dma_tx) == -EPROBE_DEFER ) { ret = -EPROBE_DEFER ; - goto out_disable_clk; + goto out_host_put; } host->dma_tx =NULL ; dma_tx_burst =INT_MAX ;
@@ -766,9 +762,6 @@ static int uniphier_spi_probe(struct platform_device *pdev) host->dma_tx =NULL ; } -out_disable_clk: -clk_disable_unprepare (priv->clk); - out_host_put:spi_controller_put (host);return ret;
@@ -777,14 +770,11 @@ static int uniphier_spi_probe(struct platform_device *pdev)static void uniphier_spi_remove (struct platform_device *pdev) {struct spi_controller *host =platform_get_drvdata (pdev); -struct uniphier_spi_priv *priv =spi_controller_get_devdata (host);if (host->dma_tx)dma_release_channel (host->dma_tx);if (host->dma_rx)dma_release_channel (host->dma_rx); - -clk_disable_unprepare (priv->clk); }static const struct of_device_id uniphier_spi_match[] = {
Signature · 1 line
2.25.1
Mark Brown
maintainerRe: [PATCH 2/4] spi: uniphier: Simplify clock handling with devm_clk_get_enabled()
Quoted 4 lines · Pei Xiao
Replace
devm_clk_get()followed byclk_prepare_enable()withdevm_clk_get_enabled()for the clock. This removes the need for explicit clock enable and disable calls, as the managed API automatically handles clock disabling on device removal or probe failure.
Copying in the maintainers for the driver, you should generally copy maintainers when posting patches (and to avoid large CC lists it's often better to send patches per driver unless the series is actually related, this one isn't).
Quoted 81 lines
Remove the now-unnecessary
clk_disable_unprepare()calls from the probe error path and the remove callback. Adjust error labels accordingly.Signed-off-by Pei Xiao <[email protected]>--- drivers/spi/spi-uniphier.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)drivers/spi/spi-uniphier.c +4
-14@@ -666,28 +666,24 @@ static int uniphier_spi_probe(struct platform_device *pdev) } priv->base_dma_addr = res->start; - priv->clk =devm_clk_get (&pdev->dev,NULL ); + priv->clk =devm_clk_get_enabled (&pdev->dev,NULL );if (IS_ERR (priv->clk)) {dev_err (&pdev->dev,"failed to get clock\n" ); ret =PTR_ERR (priv->clk); goto out_host_put; } - ret =clk_prepare_enable (priv->clk); -if (ret) - goto out_host_put; - irq =platform_get_irq (pdev,0 );if (irq <0 ) { ret = irq; - goto out_disable_clk; + goto out_host_put; } ret =devm_request_irq (&pdev->dev, irq, uniphier_spi_handler,0 ,"uniphier-spi" , priv);if (ret) {dev_err (&pdev->dev,"failed to request IRQ\n" ); - goto out_disable_clk; + goto out_host_put; }init_completion (&priv->xfer_done);@@ -716,7 +712,7 @@ static int uniphier_spi_probe(struct platform_device *pdev)if (IS_ERR_OR_NULL (host->dma_tx)) {if (PTR_ERR (host->dma_tx) == -EPROBE_DEFER ) { ret = -EPROBE_DEFER ; - goto out_disable_clk; + goto out_host_put; } host->dma_tx =NULL ; dma_tx_burst =INT_MAX ;@@ -766,9 +762,6 @@ static int uniphier_spi_probe(struct platform_device *pdev) host->dma_tx =NULL ; } -out_disable_clk: -clk_disable_unprepare (priv->clk); - out_host_put:spi_controller_put (host);return ret;@@ -777,14 +770,11 @@ static int uniphier_spi_probe(struct platform_device *pdev)static void uniphier_spi_remove (struct platform_device *pdev) {struct spi_controller *host =platform_get_drvdata (pdev); -struct uniphier_spi_priv *priv =spi_controller_get_devdata (host);if (host->dma_tx)dma_release_channel (host->dma_tx);if (host->dma_rx)dma_release_channel (host->dma_rx); - -clk_disable_unprepare (priv->clk); }static const struct of_device_id uniphier_spi_match[] = {Signature · 1 line
2.25.1
Re: [PATCH 2/4] spi: uniphier: Simplify clock handling with devm_clk_get_enabled()
Quoted 11 lines · Mark Brown
Quoted 4 lines · Pei Xiao
Replace
devm_clk_get()followed byclk_prepare_enable()withdevm_clk_get_enabled()for the clock. This removes the need for explicit clock enable and disable calls, as the managed API automatically handles clock disabling on device removal or probe failure.Copying in the maintainers for the driver, you should generally copy maintainers when posting patches (and to avoid large CC lists it's often better to send patches per driver unless the series is actually related, this one isn't).
Yes, I only sent it to you to avoid CC'ing too many people. I will send these patches separately to the corresponding maintainers.
Thank you!
Pei.
Quoted 81 lines
Quoted 81 lines
Remove the now-unnecessary
clk_disable_unprepare()calls from the probe error path and the remove callback. Adjust error labels accordingly.Signed-off-by Pei Xiao <[email protected]>--- drivers/spi/spi-uniphier.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)drivers/spi/spi-uniphier.c +4
-14@@ -666,28 +666,24 @@ static int uniphier_spi_probe(struct platform_device *pdev) } priv->base_dma_addr = res->start; - priv->clk =devm_clk_get (&pdev->dev,NULL ); + priv->clk =devm_clk_get_enabled (&pdev->dev,NULL );if (IS_ERR (priv->clk)) {dev_err (&pdev->dev,"failed to get clock\n" ); ret =PTR_ERR (priv->clk); goto out_host_put; } - ret =clk_prepare_enable (priv->clk); -if (ret) - goto out_host_put; - irq =platform_get_irq (pdev,0 );if (irq <0 ) { ret = irq; - goto out_disable_clk; + goto out_host_put; } ret =devm_request_irq (&pdev->dev, irq, uniphier_spi_handler,0 ,"uniphier-spi" , priv);if (ret) {dev_err (&pdev->dev,"failed to request IRQ\n" ); - goto out_disable_clk; + goto out_host_put; }init_completion (&priv->xfer_done);@@ -716,7 +712,7 @@ static int uniphier_spi_probe(struct platform_device *pdev)if (IS_ERR_OR_NULL (host->dma_tx)) {if (PTR_ERR (host->dma_tx) == -EPROBE_DEFER ) { ret = -EPROBE_DEFER ; - goto out_disable_clk; + goto out_host_put; } host->dma_tx =NULL ; dma_tx_burst =INT_MAX ;@@ -766,9 +762,6 @@ static int uniphier_spi_probe(struct platform_device *pdev) host->dma_tx =NULL ; } -out_disable_clk: -clk_disable_unprepare (priv->clk); - out_host_put:spi_controller_put (host);return ret;@@ -777,14 +770,11 @@ static int uniphier_spi_probe(struct platform_device *pdev)static void uniphier_spi_remove (struct platform_device *pdev) {struct spi_controller *host =platform_get_drvdata (pdev); -struct uniphier_spi_priv *priv =spi_controller_get_devdata (host);if (host->dma_tx)dma_release_channel (host->dma_tx);if (host->dma_rx)dma_release_channel (host->dma_rx); - -clk_disable_unprepare (priv->clk); }static const struct of_device_id uniphier_spi_match[] = {Signature · 1 line
2.25.1
PATCH 3/4 spi: zynq-qspi: Simplify clock handling with devm_clk_get_enabled()
In reply to Pei XiaoReplace devm_clk_get() followed by clk_prepare_enable() with devm_clk_get_enabled() for both "pclk" and "ref_clk". This removes the need for explicit clock enable and disable calls, as the managed API automatically disables the clocks on device removal or probe failure.
Remove the now-unnecessary clk_disable_unprepare() calls from the probe error paths and the remove callback. Simplify error handling by jumping directly to the remove_ctlr label.
--- drivers/spi/spi-zynq-qspi.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-)
drivers/spi/spi-zynq-qspi.c +6 -25
@@ -661,7 +661,7 @@ static int zynq_qspi_probe(struct platform_device *pdev) goto remove_ctlr; } - xqspi->pclk =devm_clk_get (&pdev->dev,"pclk" ); + xqspi->pclk =devm_clk_get_enabled (&pdev->dev,"pclk" );if (IS_ERR (xqspi->pclk)) {dev_err (&pdev->dev,"pclk clock not found.\n" ); ret =PTR_ERR (xqspi->pclk);
@@ -670,36 +670,24 @@ static int zynq_qspi_probe(struct platform_device *pdev)init_completion (&xqspi->data_completion); - xqspi->refclk =devm_clk_get (&pdev->dev,"ref_clk" ); + xqspi->refclk =devm_clk_get_enabled (&pdev->dev,"ref_clk" );if (IS_ERR (xqspi->refclk)) {dev_err (&pdev->dev,"ref_clk clock not found.\n" ); ret =PTR_ERR (xqspi->refclk); goto remove_ctlr; } - ret =clk_prepare_enable (xqspi->pclk); -if (ret) { -dev_err (&pdev->dev,"Unable to enable APB clock.\n" ); - goto remove_ctlr; - } - - ret =clk_prepare_enable (xqspi->refclk); -if (ret) { -dev_err (&pdev->dev,"Unable to enable device clock.\n" ); - goto clk_dis_pclk; - } - xqspi->irq =platform_get_irq (pdev,0 );if (xqspi->irq <0 ) { ret = xqspi->irq; - goto clk_dis_all; + goto remove_ctlr; } ret =devm_request_irq (&pdev->dev, xqspi->irq, zynq_qspi_irq,0 , pdev->name, xqspi);if (ret !=0 ) { ret = -ENXIO ;dev_err (&pdev->dev,"request_irq failed\n" ); - goto clk_dis_all; + goto remove_ctlr; } ret = of_property_read_u32(np, "num-cs",
@@ -709,7 +697,7 @@ static int zynq_qspi_probe(struct platform_device *pdev) }else if (num_cs >ZYNQ_QSPI_MAX_NUM_CS ) { ret = -EINVAL ;dev_err (&pdev->dev,"only 2 chip selects are available\n" ); - goto clk_dis_all; + goto remove_ctlr; }else { ctlr->num_chipselect = num_cs; }
@@ -728,15 +716,11 @@ static int zynq_qspi_probe(struct platform_device *pdev) ret =devm_spi_register_controller (&pdev->dev, ctlr);if (ret) {dev_err (&pdev->dev,"devm_spi_register_controller failed\n" ); - goto clk_dis_all; + goto remove_ctlr; }return ret; -clk_dis_all: -clk_disable_unprepare (xqspi->refclk); -clk_dis_pclk: -clk_disable_unprepare (xqspi->pclk); remove_ctlr:spi_controller_put (ctlr);
@@ -758,9 +742,6 @@ static void zynq_qspi_remove(struct platform_device *pdev)struct zynq_qspi *xqspi =platform_get_drvdata (pdev);zynq_qspi_write (xqspi,ZYNQ_QSPI_ENABLE_OFFSET ,0 ); - -clk_disable_unprepare (xqspi->refclk); -clk_disable_unprepare (xqspi->pclk); }static const struct of_device_id zynq_qspi_of_match[] = {
Signature · 1 line
2.25.1
Mark Brown
maintainerRe: [PATCH 3/4] spi: zynq-qspi: Simplify clock handling with devm_clk_get_enabled()
Quoted 5 lines · Pei Xiao
Replace
devm_clk_get()followed byclk_prepare_enable()withdevm_clk_get_enabled()for both "pclk" and "ref_clk". This removes the need for explicit clock enable and disable calls, as the managed API automatically disables the clocks on device removal or probe failure.
Copying the driver maintainer.
Quoted 101 lines
Remove the now-unnecessary
clk_disable_unprepare()calls from the probe error paths and the remove callback. Simplify error handling by jumping directly to theremove_ctlrlabel.Signed-off-by Pei Xiao <[email protected]>--- drivers/spi/spi-zynq-qspi.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-)drivers/spi/spi-zynq-qspi.c +6
-25@@ -661,7 +661,7 @@ static int zynq_qspi_probe(struct platform_device *pdev) goto remove_ctlr; } - xqspi->pclk =devm_clk_get (&pdev->dev,"pclk" ); + xqspi->pclk =devm_clk_get_enabled (&pdev->dev,"pclk" );if (IS_ERR (xqspi->pclk)) {dev_err (&pdev->dev,"pclk clock not found.\n" ); ret =PTR_ERR (xqspi->pclk);@@ -670,36 +670,24 @@ static int zynq_qspi_probe(struct platform_device *pdev)init_completion (&xqspi->data_completion); - xqspi->refclk =devm_clk_get (&pdev->dev,"ref_clk" ); + xqspi->refclk =devm_clk_get_enabled (&pdev->dev,"ref_clk" );if (IS_ERR (xqspi->refclk)) {dev_err (&pdev->dev,"ref_clk clock not found.\n" ); ret =PTR_ERR (xqspi->refclk); goto remove_ctlr; } - ret =clk_prepare_enable (xqspi->pclk); -if (ret) { -dev_err (&pdev->dev,"Unable to enable APB clock.\n" ); - goto remove_ctlr; - } - - ret =clk_prepare_enable (xqspi->refclk); -if (ret) { -dev_err (&pdev->dev,"Unable to enable device clock.\n" ); - goto clk_dis_pclk; - } - xqspi->irq =platform_get_irq (pdev,0 );if (xqspi->irq <0 ) { ret = xqspi->irq; - goto clk_dis_all; + goto remove_ctlr; } ret =devm_request_irq (&pdev->dev, xqspi->irq, zynq_qspi_irq,0 , pdev->name, xqspi);if (ret !=0 ) { ret = -ENXIO ;dev_err (&pdev->dev,"request_irq failed\n" ); - goto clk_dis_all; + goto remove_ctlr; } ret = of_property_read_u32(np, "num-cs",@@ -709,7 +697,7 @@ static int zynq_qspi_probe(struct platform_device *pdev) }else if (num_cs >ZYNQ_QSPI_MAX_NUM_CS ) { ret = -EINVAL ;dev_err (&pdev->dev,"only 2 chip selects are available\n" ); - goto clk_dis_all; + goto remove_ctlr; }else { ctlr->num_chipselect = num_cs; }@@ -728,15 +716,11 @@ static int zynq_qspi_probe(struct platform_device *pdev) ret =devm_spi_register_controller (&pdev->dev, ctlr);if (ret) {dev_err (&pdev->dev,"devm_spi_register_controller failed\n" ); - goto clk_dis_all; + goto remove_ctlr; }return ret; -clk_dis_all: -clk_disable_unprepare (xqspi->refclk); -clk_dis_pclk: -clk_disable_unprepare (xqspi->pclk); remove_ctlr:spi_controller_put (ctlr);@@ -758,9 +742,6 @@ static void zynq_qspi_remove(struct platform_device *pdev)struct zynq_qspi *xqspi =platform_get_drvdata (pdev);zynq_qspi_write (xqspi,ZYNQ_QSPI_ENABLE_OFFSET ,0 ); - -clk_disable_unprepare (xqspi->refclk); -clk_disable_unprepare (xqspi->pclk); }static const struct of_device_id zynq_qspi_of_match[] = {Signature · 1 line
2.25.1
PATCH 4/4 spi: ch341: Correct vendor name
In reply to Pei XiaoThe usb2spi ch341a is manufactured by QinHeng Electronics, not QiHeng. Update the driver description and the initial comment to reflect the correct vendor name.
--- drivers/spi/spi-ch341.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-ch341.c +2 -2
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 // -// QiHeng Electronics ch341a USB-to-SPI adapter driver +// QinHeng Electronics ch341a USB-to-SPI adapter driver // // Copyright (C) 2024 Johannes Thumshirn <[email protected]> //
@@ -250,5 +250,5 @@ static struct usb_driver ch341a_usb_driver = {module_usb_driver (ch341a_usb_driver);MODULE_AUTHOR ("Johannes Thumshirn <[email protected]>" ); -MODULE_DESCRIPTION ("QiHeng Electronics ch341 USB2SPI" ); +MODULE_DESCRIPTION ("QinHeng Electronics ch341 USB2SPI" );MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.25.1