diff mbox series

[4/5] spi: rockchip: Use dev_err_probe() in the probe path

Message ID 8bc905ff3c47ed458d8c65a031822ba6b9df8a07.1727337732.git.dsimic@manjaro.org (mailing list archive)
State New
Headers show
Series Improve error handling in Rockchip SPI drivers | expand

Commit Message

Dragan Simic Sept. 26, 2024, 8:38 a.m. UTC
Use function dev_err_probe() in the probe path instead of dev_err() where
appropriate, to make the code a bit more uniform and compact, and to improve
error handling for the TX and RX DMA channel requests.

Previously, deferred requests for the TX and RX DMA channels produced no
debug messages, and the final error messages didn't include the error codes,
which are all highly useful when debugging permanently failed DMA channel
requests, such as when the required drivers aren't enabled.

Suggested-by: Hélene Vulquin <oss@helene.moe>
Signed-off-by: Dragan Simic <dsimic@manjaro.org>
---
 drivers/spi/spi-rockchip.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

Comments

Heiko Stuebner Sept. 26, 2024, 9 a.m. UTC | #1
Am Donnerstag, 26. September 2024, 10:38:15 CEST schrieb Dragan Simic:
> Use function dev_err_probe() in the probe path instead of dev_err() where
> appropriate, to make the code a bit more uniform and compact, and to improve
> error handling for the TX and RX DMA channel requests.
> 
> Previously, deferred requests for the TX and RX DMA channels produced no
> debug messages, and the final error messages didn't include the error codes,
> which are all highly useful when debugging permanently failed DMA channel
> requests, such as when the required drivers aren't enabled.
> 
> Suggested-by: Hélene Vulquin <oss@helene.moe>
> Signed-off-by: Dragan Simic <dsimic@manjaro.org>
> ---
>  drivers/spi/spi-rockchip.c | 25 ++++++++++++-------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
> index 28879fed03f8..6b5c67a357bb 100644
> --- a/drivers/spi/spi-rockchip.c
> +++ b/drivers/spi/spi-rockchip.c
> @@ -853,22 +853,21 @@ static int rockchip_spi_probe(struct platform_device *pdev)
>  
>  	ctlr->dma_tx = dma_request_chan(rs->dev, "tx");
>  	if (IS_ERR(ctlr->dma_tx)) {
> -		/* Check tx to see if we need defer probing driver */
> -		if (PTR_ERR(ctlr->dma_tx) == -EPROBE_DEFER) {
> -			ret = -EPROBE_DEFER;
> +		/* Check tx to see if we need to defer driver probing */
> +		ret = dev_err_probe(rs->dev, PTR_ERR(ctlr->dma_tx),
> +				    "Failed to request TX DMA channel\n");

you're upgrading here from a warning to an error log level.
As it seems the controller may actually provide some level of functionality
even without dma, is this approriate?

Same for rx below.

Heiko

> +		if (ret == -EPROBE_DEFER)
>  			goto err_disable_pm_runtime;
> -		}
> -		dev_warn(rs->dev, "Failed to request TX DMA channel\n");
>  		ctlr->dma_tx = NULL;
>  	}
>  
>  	ctlr->dma_rx = dma_request_chan(rs->dev, "rx");
>  	if (IS_ERR(ctlr->dma_rx)) {
> -		if (PTR_ERR(ctlr->dma_rx) == -EPROBE_DEFER) {
> -			ret = -EPROBE_DEFER;
> +		/* Check rx to see if we need to defer driver probing */
> +		ret = dev_err_probe(rs->dev, PTR_ERR(ctlr->dma_rx),
> +				    "Failed to request RX DMA channel\n");
> +		if (ret == -EPROBE_DEFER)
>  			goto err_free_dma_tx;
> -		}
> -		dev_warn(rs->dev, "Failed to request RX DMA channel\n");
>  		ctlr->dma_rx = NULL;
>  	}
>  
>
Dragan Simic Sept. 26, 2024, 9:21 a.m. UTC | #2
Hello Heiko,

On 2024-09-26 11:00, Heiko Stuebner wrote:
> Am Donnerstag, 26. September 2024, 10:38:15 CEST schrieb Dragan Simic:
>> Use function dev_err_probe() in the probe path instead of dev_err() 
>> where
>> appropriate, to make the code a bit more uniform and compact, and to 
>> improve
>> error handling for the TX and RX DMA channel requests.
>> 
>> Previously, deferred requests for the TX and RX DMA channels produced 
>> no
>> debug messages, and the final error messages didn't include the error 
>> codes,
>> which are all highly useful when debugging permanently failed DMA 
>> channel
>> requests, such as when the required drivers aren't enabled.
>> 
>> Suggested-by: Hélene Vulquin <oss@helene.moe>
>> Signed-off-by: Dragan Simic <dsimic@manjaro.org>
>> ---
>>  drivers/spi/spi-rockchip.c | 25 ++++++++++++-------------
>>  1 file changed, 12 insertions(+), 13 deletions(-)
>> 
>> diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
>> index 28879fed03f8..6b5c67a357bb 100644
>> --- a/drivers/spi/spi-rockchip.c
>> +++ b/drivers/spi/spi-rockchip.c
>> @@ -853,22 +853,21 @@ static int rockchip_spi_probe(struct 
>> platform_device *pdev)
>> 
>>  	ctlr->dma_tx = dma_request_chan(rs->dev, "tx");
>>  	if (IS_ERR(ctlr->dma_tx)) {
>> -		/* Check tx to see if we need defer probing driver */
>> -		if (PTR_ERR(ctlr->dma_tx) == -EPROBE_DEFER) {
>> -			ret = -EPROBE_DEFER;
>> +		/* Check tx to see if we need to defer driver probing */
>> +		ret = dev_err_probe(rs->dev, PTR_ERR(ctlr->dma_tx),
>> +				    "Failed to request TX DMA channel\n");
> 
> you're upgrading here from a warning to an error log level.
> As it seems the controller may actually provide some level of 
> functionality
> even without dma, is this approriate?
> 
> Same for rx below.

Thanks for your quick responses.

You're right about the driver still working without the DMA channels,
so emitting warnings would be much more appropriate.

We'd basically need dev_warn_probe() as a new function to cover these
two cases, but I'm not really sure how to proceed?  I could go ahead
and implement dev_warn_probe() in a good way, but I wonder what would
be the chances to have that accepted upstream?  Perhaps there would
be other users for dev_warn_probe().

>> +		if (ret == -EPROBE_DEFER)
>>  			goto err_disable_pm_runtime;
>> -		}
>> -		dev_warn(rs->dev, "Failed to request TX DMA channel\n");
>>  		ctlr->dma_tx = NULL;
>>  	}
>> 
>>  	ctlr->dma_rx = dma_request_chan(rs->dev, "rx");
>>  	if (IS_ERR(ctlr->dma_rx)) {
>> -		if (PTR_ERR(ctlr->dma_rx) == -EPROBE_DEFER) {
>> -			ret = -EPROBE_DEFER;
>> +		/* Check rx to see if we need to defer driver probing */
>> +		ret = dev_err_probe(rs->dev, PTR_ERR(ctlr->dma_rx),
>> +				    "Failed to request RX DMA channel\n");
>> +		if (ret == -EPROBE_DEFER)
>>  			goto err_free_dma_tx;
>> -		}
>> -		dev_warn(rs->dev, "Failed to request RX DMA channel\n");
>>  		ctlr->dma_rx = NULL;
>>  	}
diff mbox series

Patch

diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
index 28879fed03f8..6b5c67a357bb 100644
--- a/drivers/spi/spi-rockchip.c
+++ b/drivers/spi/spi-rockchip.c
@@ -773,15 +773,15 @@  static int rockchip_spi_probe(struct platform_device *pdev)
 
 	rs->apb_pclk = devm_clk_get_enabled(&pdev->dev, "apb_pclk");
 	if (IS_ERR(rs->apb_pclk)) {
-		dev_err(&pdev->dev, "Failed to get apb_pclk\n");
-		ret = PTR_ERR(rs->apb_pclk);
+		ret = dev_err_probe(&pdev->dev, PTR_ERR(rs->apb_pclk),
+				    "Failed to get apb_pclk\n");
 		goto err_put_ctlr;
 	}
 
 	rs->spiclk = devm_clk_get_enabled(&pdev->dev, "spiclk");
 	if (IS_ERR(rs->spiclk)) {
-		dev_err(&pdev->dev, "Failed to get spi_pclk\n");
-		ret = PTR_ERR(rs->spiclk);
+		ret = dev_err_probe(&pdev->dev, PTR_ERR(rs->spiclk),
+				    "Failed to get spi_pclk\n");
 		goto err_put_ctlr;
 	}
 
@@ -853,22 +853,21 @@  static int rockchip_spi_probe(struct platform_device *pdev)
 
 	ctlr->dma_tx = dma_request_chan(rs->dev, "tx");
 	if (IS_ERR(ctlr->dma_tx)) {
-		/* Check tx to see if we need defer probing driver */
-		if (PTR_ERR(ctlr->dma_tx) == -EPROBE_DEFER) {
-			ret = -EPROBE_DEFER;
+		/* Check tx to see if we need to defer driver probing */
+		ret = dev_err_probe(rs->dev, PTR_ERR(ctlr->dma_tx),
+				    "Failed to request TX DMA channel\n");
+		if (ret == -EPROBE_DEFER)
 			goto err_disable_pm_runtime;
-		}
-		dev_warn(rs->dev, "Failed to request TX DMA channel\n");
 		ctlr->dma_tx = NULL;
 	}
 
 	ctlr->dma_rx = dma_request_chan(rs->dev, "rx");
 	if (IS_ERR(ctlr->dma_rx)) {
-		if (PTR_ERR(ctlr->dma_rx) == -EPROBE_DEFER) {
-			ret = -EPROBE_DEFER;
+		/* Check rx to see if we need to defer driver probing */
+		ret = dev_err_probe(rs->dev, PTR_ERR(ctlr->dma_rx),
+				    "Failed to request RX DMA channel\n");
+		if (ret == -EPROBE_DEFER)
 			goto err_free_dma_tx;
-		}
-		dev_warn(rs->dev, "Failed to request RX DMA channel\n");
 		ctlr->dma_rx = NULL;
 	}