diff mbox series

macb: propagate errors when getting optional clocks

Message ID 20191018141143.24148-1-m.tretter@pengutronix.de
State Accepted
Delegated to: David Miller
Headers show
Series macb: propagate errors when getting optional clocks | expand

Commit Message

Michael Tretter Oct. 18, 2019, 2:11 p.m. UTC
The tx_clk, rx_clk, and tsu_clk are optional. Currently the macb driver
marks clock as not available if it receives an error when trying to get
a clock. This is wrong, because a clock controller might return
-EPROBE_DEFER if a clock is not available, but will eventually become
available.

In these cases, the driver would probe successfully but will never be
able to adjust the clocks, because the clocks were not available during
probe, but became available later.

For example, the clock controller for the ZynqMP is implemented in the
PMU firmware and the clocks are only available after the firmware driver
has been probed.

Use devm_clk_get_optional() in instead of devm_clk_get() to get the
optional clock and propagate all errors to the calling function.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
 drivers/net/ethernet/cadence/macb_main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Nicolas Ferre Oct. 18, 2019, 3:53 p.m. UTC | #1
On 18/10/2019 at 16:11, Michael Tretter wrote:
> The tx_clk, rx_clk, and tsu_clk are optional. Currently the macb driver
> marks clock as not available if it receives an error when trying to get
> a clock. This is wrong, because a clock controller might return
> -EPROBE_DEFER if a clock is not available, but will eventually become
> available.
> 
> In these cases, the driver would probe successfully but will never be
> able to adjust the clocks, because the clocks were not available during
> probe, but became available later.
> 
> For example, the clock controller for the ZynqMP is implemented in the
> PMU firmware and the clocks are only available after the firmware driver
> has been probed.
> 
> Use devm_clk_get_optional() in instead of devm_clk_get() to get the
> optional clock and propagate all errors to the calling function.
> 
> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>

Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Tested-by: Nicolas Ferre <nicolas.ferre@microchip.com>
(for the record: on sama5d3 xplained GMAC and MACB interfaces)

Thank you Michael. Best regards,
   Nicolas

> ---
>   drivers/net/ethernet/cadence/macb_main.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index 8e8d557901a9..1e1b774e1953 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -3405,17 +3405,17 @@ static int macb_clk_init(struct platform_device *pdev, struct clk **pclk,
>   		return err;
>   	}
>   
> -	*tx_clk = devm_clk_get(&pdev->dev, "tx_clk");
> +	*tx_clk = devm_clk_get_optional(&pdev->dev, "tx_clk");
>   	if (IS_ERR(*tx_clk))
> -		*tx_clk = NULL;
> +		return PTR_ERR(*tx_clk);
>   
> -	*rx_clk = devm_clk_get(&pdev->dev, "rx_clk");
> +	*rx_clk = devm_clk_get_optional(&pdev->dev, "rx_clk");
>   	if (IS_ERR(*rx_clk))
> -		*rx_clk = NULL;
> +		return PTR_ERR(*rx_clk);
>   
> -	*tsu_clk = devm_clk_get(&pdev->dev, "tsu_clk");
> +	*tsu_clk = devm_clk_get_optional(&pdev->dev, "tsu_clk");
>   	if (IS_ERR(*tsu_clk))
> -		*tsu_clk = NULL;
> +		return PTR_ERR(*tsu_clk);
>   
>   	err = clk_prepare_enable(*pclk);
>   	if (err) {
>
David Miller Oct. 19, 2019, 6:59 p.m. UTC | #2
From: Michael Tretter <m.tretter@pengutronix.de>
Date: Fri, 18 Oct 2019 16:11:43 +0200

> The tx_clk, rx_clk, and tsu_clk are optional. Currently the macb driver
> marks clock as not available if it receives an error when trying to get
> a clock. This is wrong, because a clock controller might return
> -EPROBE_DEFER if a clock is not available, but will eventually become
> available.
> 
> In these cases, the driver would probe successfully but will never be
> able to adjust the clocks, because the clocks were not available during
> probe, but became available later.
> 
> For example, the clock controller for the ZynqMP is implemented in the
> PMU firmware and the clocks are only available after the firmware driver
> has been probed.
> 
> Use devm_clk_get_optional() in instead of devm_clk_get() to get the
> optional clock and propagate all errors to the calling function.
> 
> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>

Applied, thanks.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 8e8d557901a9..1e1b774e1953 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -3405,17 +3405,17 @@  static int macb_clk_init(struct platform_device *pdev, struct clk **pclk,
 		return err;
 	}
 
-	*tx_clk = devm_clk_get(&pdev->dev, "tx_clk");
+	*tx_clk = devm_clk_get_optional(&pdev->dev, "tx_clk");
 	if (IS_ERR(*tx_clk))
-		*tx_clk = NULL;
+		return PTR_ERR(*tx_clk);
 
-	*rx_clk = devm_clk_get(&pdev->dev, "rx_clk");
+	*rx_clk = devm_clk_get_optional(&pdev->dev, "rx_clk");
 	if (IS_ERR(*rx_clk))
-		*rx_clk = NULL;
+		return PTR_ERR(*rx_clk);
 
-	*tsu_clk = devm_clk_get(&pdev->dev, "tsu_clk");
+	*tsu_clk = devm_clk_get_optional(&pdev->dev, "tsu_clk");
 	if (IS_ERR(*tsu_clk))
-		*tsu_clk = NULL;
+		return PTR_ERR(*tsu_clk);
 
 	err = clk_prepare_enable(*pclk);
 	if (err) {