diff mbox series

[net-next,v2,2/9] net: stmmac: platform: Convert to devm_clk_get_enabled() and devm_clk_get_optional_enabled()

Message ID 20240823072122.2053401-3-frank.li@vivo.com (mailing list archive)
State New, archived
Headers show
Series net: convert to devm_clk_get_enabled() and devm_clk_get_optional_enabled() | expand

Commit Message

Yangtao Li Aug. 23, 2024, 7:21 a.m. UTC
Use devm_clk_get_enabled() and devm_clk_get_optional_enabled()
to simplify code.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
v2:
-remove unused 'ret'
-fix incompatible-pointer-types

 .../ethernet/stmicro/stmmac/stmmac_platform.c | 35 +++++--------------
 1 file changed, 8 insertions(+), 27 deletions(-)

Comments

Serge Semin Aug. 23, 2024, 9:11 a.m. UTC | #1
Hi Yangtao

On Fri, Aug 23, 2024 at 01:21:14AM -0600, Yangtao Li wrote:
> Use devm_clk_get_enabled() and devm_clk_get_optional_enabled()
> to simplify code.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> ---
> v2:
> -remove unused 'ret'
> -fix incompatible-pointer-types
> 
>  .../ethernet/stmicro/stmmac/stmmac_platform.c | 35 +++++--------------
>  1 file changed, 8 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> index ad868e8d195d..1a66baaa4081 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> @@ -415,8 +415,6 @@ static int stmmac_of_get_mac_mode(struct device_node *np)
>  static void stmmac_remove_config_dt(struct platform_device *pdev,
>  				    struct plat_stmmacenet_data *plat)
>  {
> -	clk_disable_unprepare(plat->stmmac_clk);
> -	clk_disable_unprepare(plat->pclk);
>  	of_node_put(plat->phy_node);
>  	of_node_put(plat->mdio_node);
>  }
> @@ -436,7 +434,6 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
>  	struct plat_stmmacenet_data *plat;
>  	struct stmmac_dma_cfg *dma_cfg;
>  	int phy_mode;
> -	void *ret;
>  	int rc;
>  
>  	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
> @@ -615,21 +612,16 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
>  
>  	/* clock setup */
>  	if (!of_device_is_compatible(np, "snps,dwc-qos-ethernet-4.10")) {
> -		plat->stmmac_clk = devm_clk_get(&pdev->dev,
> -						STMMAC_RESOURCE_NAME);
> +		plat->stmmac_clk = devm_clk_get_enabled(&pdev->dev, STMMAC_RESOURCE_NAME);
>  		if (IS_ERR(plat->stmmac_clk)) {
>  			dev_warn(&pdev->dev, "Cannot get CSR clock\n");
>  			plat->stmmac_clk = NULL;
>  		}
> -		clk_prepare_enable(plat->stmmac_clk);
>  	}
>  
> -	plat->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
> -	if (IS_ERR(plat->pclk)) {
> -		ret = plat->pclk;
> -		goto error_pclk_get;
> -	}
> -	clk_prepare_enable(plat->pclk);
> +	plat->pclk = devm_clk_get_optional_enabled(&pdev->dev, "pclk");
> +	if (IS_ERR(plat->pclk))

> +		return (void *)plat->pclk;

Use the ERR_CAST() macro instead of the open coded void type cast.

>  
>  	/* Fall-back to main clock in case of no PTP ref is passed */
>  	plat->clk_ptp_ref = devm_clk_get(&pdev->dev, "ptp_ref");
> @@ -644,26 +636,15 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
>  
>  	plat->stmmac_rst = devm_reset_control_get_optional(&pdev->dev,
>  							   STMMAC_RESOURCE_NAME);
> -	if (IS_ERR(plat->stmmac_rst)) {
> -		ret = plat->stmmac_rst;
> -		goto error_hw_init;
> -	}
> +	if (IS_ERR(plat->stmmac_rst))

> +		return (void *)plat->stmmac_rst;

ditto

>  
>  	plat->stmmac_ahb_rst = devm_reset_control_get_optional_shared(
>  							&pdev->dev, "ahb");
> -	if (IS_ERR(plat->stmmac_ahb_rst)) {
> -		ret = plat->stmmac_ahb_rst;
> -		goto error_hw_init;
> -	}
> +	if (IS_ERR(plat->stmmac_ahb_rst))

> +		return (void *)plat->stmmac_ahb_rst;

ditto

-Serge(y)

>  
>  	return plat;
> -
> -error_hw_init:
> -	clk_disable_unprepare(plat->pclk);
> -error_pclk_get:
> -	clk_disable_unprepare(plat->stmmac_clk);
> -
> -	return ret;
>  }
>  
>  static void devm_stmmac_remove_config_dt(void *data)
> -- 
> 2.39.0
> 
>
Biju Das Aug. 23, 2024, 9:15 a.m. UTC | #2
Hi Serge Semin,

> -----Original Message-----
> From: Serge Semin <fancer.lancer@gmail.com>
> Sent: Friday, August 23, 2024 10:11 AM
> Subject: Re: [net-next v2 2/9] net: stmmac: platform: Convert to devm_clk_get_enabled() and
> devm_clk_get_optional_enabled()
> 
> Hi Yangtao
> 
> On Fri, Aug 23, 2024 at 01:21:14AM -0600, Yangtao Li wrote:
> > Use devm_clk_get_enabled() and devm_clk_get_optional_enabled() to
> > simplify code.
> >
> > Signed-off-by: Yangtao Li <frank.li@vivo.com>
> > Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> > ---
> > v2:
> > -remove unused 'ret'
> > -fix incompatible-pointer-types
> >
> >  .../ethernet/stmicro/stmmac/stmmac_platform.c | 35
> > +++++--------------
> >  1 file changed, 8 insertions(+), 27 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > index ad868e8d195d..1a66baaa4081 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > @@ -415,8 +415,6 @@ static int stmmac_of_get_mac_mode(struct
> > device_node *np)  static void stmmac_remove_config_dt(struct platform_device *pdev,
> >  				    struct plat_stmmacenet_data *plat)  {
> > -	clk_disable_unprepare(plat->stmmac_clk);
> > -	clk_disable_unprepare(plat->pclk);
> >  	of_node_put(plat->phy_node);
> >  	of_node_put(plat->mdio_node);
> >  }
> > @@ -436,7 +434,6 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
> >  	struct plat_stmmacenet_data *plat;
> >  	struct stmmac_dma_cfg *dma_cfg;
> >  	int phy_mode;
> > -	void *ret;
> >  	int rc;
> >
> >  	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL); @@
> > -615,21 +612,16 @@ stmmac_probe_config_dt(struct platform_device
> > *pdev, u8 *mac)
> >
> >  	/* clock setup */
> >  	if (!of_device_is_compatible(np, "snps,dwc-qos-ethernet-4.10")) {
> > -		plat->stmmac_clk = devm_clk_get(&pdev->dev,
> > -						STMMAC_RESOURCE_NAME);
> > +		plat->stmmac_clk = devm_clk_get_enabled(&pdev->dev,
> > +STMMAC_RESOURCE_NAME);
> >  		if (IS_ERR(plat->stmmac_clk)) {
> >  			dev_warn(&pdev->dev, "Cannot get CSR clock\n");
> >  			plat->stmmac_clk = NULL;
> >  		}
> > -		clk_prepare_enable(plat->stmmac_clk);
> >  	}
> >
> > -	plat->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
> > -	if (IS_ERR(plat->pclk)) {
> > -		ret = plat->pclk;
> > -		goto error_pclk_get;
> > -	}
> > -	clk_prepare_enable(plat->pclk);
> > +	plat->pclk = devm_clk_get_optional_enabled(&pdev->dev, "pclk");
> > +	if (IS_ERR(plat->pclk))
> 
> > +		return (void *)plat->pclk;
> 
> Use the ERR_CAST() macro instead of the open coded void type cast.

Which is better ERR_PTR or ERR_CAST in this case?

Cheers,
Biju

> 
> >
> >  	/* Fall-back to main clock in case of no PTP ref is passed */
> >  	plat->clk_ptp_ref = devm_clk_get(&pdev->dev, "ptp_ref"); @@ -644,26
> > +636,15 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8
> > *mac)
> >
> >  	plat->stmmac_rst = devm_reset_control_get_optional(&pdev->dev,
> >  							   STMMAC_RESOURCE_NAME);
> > -	if (IS_ERR(plat->stmmac_rst)) {
> > -		ret = plat->stmmac_rst;
> > -		goto error_hw_init;
> > -	}
> > +	if (IS_ERR(plat->stmmac_rst))
> 
> > +		return (void *)plat->stmmac_rst;
> 
> ditto
> 
> >
> >  	plat->stmmac_ahb_rst = devm_reset_control_get_optional_shared(
> >  							&pdev->dev, "ahb");
> > -	if (IS_ERR(plat->stmmac_ahb_rst)) {
> > -		ret = plat->stmmac_ahb_rst;
> > -		goto error_hw_init;
> > -	}
> > +	if (IS_ERR(plat->stmmac_ahb_rst))
> 
> > +		return (void *)plat->stmmac_ahb_rst;
> 
> ditto
> 
> -Serge(y)
> 
> >
> >  	return plat;
> > -
> > -error_hw_init:
> > -	clk_disable_unprepare(plat->pclk);
> > -error_pclk_get:
> > -	clk_disable_unprepare(plat->stmmac_clk);
> > -
> > -	return ret;
> >  }
> >
> >  static void devm_stmmac_remove_config_dt(void *data)
> > --
> > 2.39.0
> >
> >
Serge Semin Aug. 23, 2024, 9:37 a.m. UTC | #3
Hi Biju

On Fri, Aug 23, 2024 at 09:15:06AM +0000, Biju Das wrote:
> Hi Serge Semin,
> 
> > -----Original Message-----
> > From: Serge Semin <fancer.lancer@gmail.com>
> > Sent: Friday, August 23, 2024 10:11 AM
> > Subject: Re: [net-next v2 2/9] net: stmmac: platform: Convert to devm_clk_get_enabled() and
> > devm_clk_get_optional_enabled()
> > 
> > Hi Yangtao
> > 
> > On Fri, Aug 23, 2024 at 01:21:14AM -0600, Yangtao Li wrote:
> > > Use devm_clk_get_enabled() and devm_clk_get_optional_enabled() to
> > > simplify code.
> > >
> > > Signed-off-by: Yangtao Li <frank.li@vivo.com>
> > > Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> > > ---
> > > v2:
> > > -remove unused 'ret'
> > > -fix incompatible-pointer-types
> > >
> > >  .../ethernet/stmicro/stmmac/stmmac_platform.c | 35
> > > +++++--------------
> > >  1 file changed, 8 insertions(+), 27 deletions(-)
> > >
> > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > > b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > > index ad868e8d195d..1a66baaa4081 100644
> > > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > > @@ -415,8 +415,6 @@ static int stmmac_of_get_mac_mode(struct
> > > device_node *np)  static void stmmac_remove_config_dt(struct platform_device *pdev,
> > >  				    struct plat_stmmacenet_data *plat)  {
> > > -	clk_disable_unprepare(plat->stmmac_clk);
> > > -	clk_disable_unprepare(plat->pclk);
> > >  	of_node_put(plat->phy_node);
> > >  	of_node_put(plat->mdio_node);
> > >  }
> > > @@ -436,7 +434,6 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
> > >  	struct plat_stmmacenet_data *plat;
> > >  	struct stmmac_dma_cfg *dma_cfg;
> > >  	int phy_mode;
> > > -	void *ret;
> > >  	int rc;
> > >
> > >  	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL); @@
> > > -615,21 +612,16 @@ stmmac_probe_config_dt(struct platform_device
> > > *pdev, u8 *mac)
> > >
> > >  	/* clock setup */
> > >  	if (!of_device_is_compatible(np, "snps,dwc-qos-ethernet-4.10")) {
> > > -		plat->stmmac_clk = devm_clk_get(&pdev->dev,
> > > -						STMMAC_RESOURCE_NAME);
> > > +		plat->stmmac_clk = devm_clk_get_enabled(&pdev->dev,
> > > +STMMAC_RESOURCE_NAME);
> > >  		if (IS_ERR(plat->stmmac_clk)) {
> > >  			dev_warn(&pdev->dev, "Cannot get CSR clock\n");
> > >  			plat->stmmac_clk = NULL;
> > >  		}
> > > -		clk_prepare_enable(plat->stmmac_clk);
> > >  	}
> > >
> > > -	plat->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
> > > -	if (IS_ERR(plat->pclk)) {
> > > -		ret = plat->pclk;
> > > -		goto error_pclk_get;
> > > -	}
> > > -	clk_prepare_enable(plat->pclk);
> > > +	plat->pclk = devm_clk_get_optional_enabled(&pdev->dev, "pclk");
> > > +	if (IS_ERR(plat->pclk))
> > 
> > > +		return (void *)plat->pclk;
> > 
> > Use the ERR_CAST() macro instead of the open coded void type cast.
> 

> Which is better ERR_PTR or ERR_CAST in this case?

The only correct macro in this case is ERR_CAST() which implies one
error-pointer cast to another. Open-coding the pointers cast is
discouraged.

The ERR_PTR() macro is utilized to cast an _integer-error_ to an
error-pointer.

-Serge(y)

> 
> Cheers,
> Biju
> 
> > 
> > >
> > >  	/* Fall-back to main clock in case of no PTP ref is passed */
> > >  	plat->clk_ptp_ref = devm_clk_get(&pdev->dev, "ptp_ref"); @@ -644,26
> > > +636,15 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8
> > > *mac)
> > >
> > >  	plat->stmmac_rst = devm_reset_control_get_optional(&pdev->dev,
> > >  							   STMMAC_RESOURCE_NAME);
> > > -	if (IS_ERR(plat->stmmac_rst)) {
> > > -		ret = plat->stmmac_rst;
> > > -		goto error_hw_init;
> > > -	}
> > > +	if (IS_ERR(plat->stmmac_rst))
> > 
> > > +		return (void *)plat->stmmac_rst;
> > 
> > ditto
> > 
> > >
> > >  	plat->stmmac_ahb_rst = devm_reset_control_get_optional_shared(
> > >  							&pdev->dev, "ahb");
> > > -	if (IS_ERR(plat->stmmac_ahb_rst)) {
> > > -		ret = plat->stmmac_ahb_rst;
> > > -		goto error_hw_init;
> > > -	}
> > > +	if (IS_ERR(plat->stmmac_ahb_rst))
> > 
> > > +		return (void *)plat->stmmac_ahb_rst;
> > 
> > ditto
> > 
> > -Serge(y)
> > 
> > >
> > >  	return plat;
> > > -
> > > -error_hw_init:
> > > -	clk_disable_unprepare(plat->pclk);
> > > -error_pclk_get:
> > > -	clk_disable_unprepare(plat->stmmac_clk);
> > > -
> > > -	return ret;
> > >  }
> > >
> > >  static void devm_stmmac_remove_config_dt(void *data)
> > > --
> > > 2.39.0
> > >
> > >
>
Biju Das Aug. 23, 2024, 9:41 a.m. UTC | #4
> -----Original Message-----
> From: Serge Semin <fancer.lancer@gmail.com>
> Sent: Friday, August 23, 2024 10:37 AM
> To: Biju Das <biju.das.jz@bp.renesas.com>
> Cc: Yangtao Li <frank.li@vivo.com>; clement.leger@bootlin.com; andrew@lunn.ch; f.fainelli@gmail.com;
> olteanv@gmail.com; davem@davemloft.net; edumazet@google.com; kuba@kernel.org; pabeni@redhat.com;
> ulli.kroll@googlemail.com; linus.walleij@linaro.org; marcin.s.wojtas@gmail.com; linux@armlinux.org.uk;
> alexandre.torgue@foss.st.com; joabreu@synopsys.com; mcoquelin.stm32@gmail.com; hkallweit1@gmail.com;
> kees@kernel.org; justinstitt@google.com; u.kleine-koenig@pengutronix.de; horms@kernel.org;
> sd@queasysnail.net; linux-renesas-soc@vger.kernel.org; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org; linux-arm-kernel@lists.infradead.org; linux-stm32@st-md-
> mailman.stormreply.com; Maxime Chevallier <maxime.chevallier@bootlin.com>
> Subject: Re: [net-next v2 2/9] net: stmmac: platform: Convert to devm_clk_get_enabled() and
> devm_clk_get_optional_enabled()
> 
> Hi Biju
> 
> On Fri, Aug 23, 2024 at 09:15:06AM +0000, Biju Das wrote:
> > Hi Serge Semin,
> >
> > > -----Original Message-----
> > > From: Serge Semin <fancer.lancer@gmail.com>
> > > Sent: Friday, August 23, 2024 10:11 AM
> > > Subject: Re: [net-next v2 2/9] net: stmmac: platform: Convert to
> > > devm_clk_get_enabled() and
> > > devm_clk_get_optional_enabled()
> > >
> > > Hi Yangtao
> > >
> > > On Fri, Aug 23, 2024 at 01:21:14AM -0600, Yangtao Li wrote:
> > > > Use devm_clk_get_enabled() and devm_clk_get_optional_enabled() to
> > > > simplify code.
> > > >
> > > > Signed-off-by: Yangtao Li <frank.li@vivo.com>
> > > > Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> > > > ---
> > > > v2:
> > > > -remove unused 'ret'
> > > > -fix incompatible-pointer-types
> > > >
> > > >  .../ethernet/stmicro/stmmac/stmmac_platform.c | 35
> > > > +++++--------------
> > > >  1 file changed, 8 insertions(+), 27 deletions(-)
> > > >
> > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > > > b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > > > index ad868e8d195d..1a66baaa4081 100644
> > > > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > > > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > > > @@ -415,8 +415,6 @@ static int stmmac_of_get_mac_mode(struct
> > > > device_node *np)  static void stmmac_remove_config_dt(struct platform_device *pdev,
> > > >  				    struct plat_stmmacenet_data *plat)  {
> > > > -	clk_disable_unprepare(plat->stmmac_clk);
> > > > -	clk_disable_unprepare(plat->pclk);
> > > >  	of_node_put(plat->phy_node);
> > > >  	of_node_put(plat->mdio_node);
> > > >  }
> > > > @@ -436,7 +434,6 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
> > > >  	struct plat_stmmacenet_data *plat;
> > > >  	struct stmmac_dma_cfg *dma_cfg;
> > > >  	int phy_mode;
> > > > -	void *ret;
> > > >  	int rc;
> > > >
> > > >  	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL); @@
> > > > -615,21 +612,16 @@ stmmac_probe_config_dt(struct platform_device
> > > > *pdev, u8 *mac)
> > > >
> > > >  	/* clock setup */
> > > >  	if (!of_device_is_compatible(np, "snps,dwc-qos-ethernet-4.10")) {
> > > > -		plat->stmmac_clk = devm_clk_get(&pdev->dev,
> > > > -						STMMAC_RESOURCE_NAME);
> > > > +		plat->stmmac_clk = devm_clk_get_enabled(&pdev->dev,
> > > > +STMMAC_RESOURCE_NAME);
> > > >  		if (IS_ERR(plat->stmmac_clk)) {
> > > >  			dev_warn(&pdev->dev, "Cannot get CSR clock\n");
> > > >  			plat->stmmac_clk = NULL;
> > > >  		}
> > > > -		clk_prepare_enable(plat->stmmac_clk);
> > > >  	}
> > > >
> > > > -	plat->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
> > > > -	if (IS_ERR(plat->pclk)) {
> > > > -		ret = plat->pclk;
> > > > -		goto error_pclk_get;
> > > > -	}
> > > > -	clk_prepare_enable(plat->pclk);
> > > > +	plat->pclk = devm_clk_get_optional_enabled(&pdev->dev, "pclk");
> > > > +	if (IS_ERR(plat->pclk))
> > >
> > > > +		return (void *)plat->pclk;
> > >
> > > Use the ERR_CAST() macro instead of the open coded void type cast.
> >
> 
> > Which is better ERR_PTR or ERR_CAST in this case?
> 
> The only correct macro in this case is ERR_CAST() which implies one error-pointer cast to another.
> Open-coding the pointers cast is discouraged.
> 
> The ERR_PTR() macro is utilized to cast an _integer-error_ to an error-pointer.

Thanks for the clarification. Make sense.

Cheers,
Biju
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index ad868e8d195d..1a66baaa4081 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -415,8 +415,6 @@  static int stmmac_of_get_mac_mode(struct device_node *np)
 static void stmmac_remove_config_dt(struct platform_device *pdev,
 				    struct plat_stmmacenet_data *plat)
 {
-	clk_disable_unprepare(plat->stmmac_clk);
-	clk_disable_unprepare(plat->pclk);
 	of_node_put(plat->phy_node);
 	of_node_put(plat->mdio_node);
 }
@@ -436,7 +434,6 @@  stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
 	struct plat_stmmacenet_data *plat;
 	struct stmmac_dma_cfg *dma_cfg;
 	int phy_mode;
-	void *ret;
 	int rc;
 
 	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
@@ -615,21 +612,16 @@  stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
 
 	/* clock setup */
 	if (!of_device_is_compatible(np, "snps,dwc-qos-ethernet-4.10")) {
-		plat->stmmac_clk = devm_clk_get(&pdev->dev,
-						STMMAC_RESOURCE_NAME);
+		plat->stmmac_clk = devm_clk_get_enabled(&pdev->dev, STMMAC_RESOURCE_NAME);
 		if (IS_ERR(plat->stmmac_clk)) {
 			dev_warn(&pdev->dev, "Cannot get CSR clock\n");
 			plat->stmmac_clk = NULL;
 		}
-		clk_prepare_enable(plat->stmmac_clk);
 	}
 
-	plat->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
-	if (IS_ERR(plat->pclk)) {
-		ret = plat->pclk;
-		goto error_pclk_get;
-	}
-	clk_prepare_enable(plat->pclk);
+	plat->pclk = devm_clk_get_optional_enabled(&pdev->dev, "pclk");
+	if (IS_ERR(plat->pclk))
+		return (void *)plat->pclk;
 
 	/* Fall-back to main clock in case of no PTP ref is passed */
 	plat->clk_ptp_ref = devm_clk_get(&pdev->dev, "ptp_ref");
@@ -644,26 +636,15 @@  stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
 
 	plat->stmmac_rst = devm_reset_control_get_optional(&pdev->dev,
 							   STMMAC_RESOURCE_NAME);
-	if (IS_ERR(plat->stmmac_rst)) {
-		ret = plat->stmmac_rst;
-		goto error_hw_init;
-	}
+	if (IS_ERR(plat->stmmac_rst))
+		return (void *)plat->stmmac_rst;
 
 	plat->stmmac_ahb_rst = devm_reset_control_get_optional_shared(
 							&pdev->dev, "ahb");
-	if (IS_ERR(plat->stmmac_ahb_rst)) {
-		ret = plat->stmmac_ahb_rst;
-		goto error_hw_init;
-	}
+	if (IS_ERR(plat->stmmac_ahb_rst))
+		return (void *)plat->stmmac_ahb_rst;
 
 	return plat;
-
-error_hw_init:
-	clk_disable_unprepare(plat->pclk);
-error_pclk_get:
-	clk_disable_unprepare(plat->stmmac_clk);
-
-	return ret;
 }
 
 static void devm_stmmac_remove_config_dt(void *data)