diff mbox series

[net-next,v3,7/8] net: ethernet: fs_enet: simplify clock handling with devm accessors

Message ID 20240904171822.64652-8-maxime.chevallier@bootlin.com (mailing list archive)
State Accepted
Commit c614acf6e8e175694db7ea21f3ddca6e075680fd
Delegated to: Netdev Maintainers
Headers show
Series net: ethernet: fs_enet: Cleanup and phylink conversion | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 7 this patch: 7
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 48 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-09-07--06-00 (tests: 722)

Commit Message

Maxime Chevallier Sept. 4, 2024, 5:18 p.m. UTC
devm_clock_get_enabled() can be used to simplify clock handling for the
PER register clock.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 .../ethernet/freescale/fs_enet/fs_enet-main.c    | 16 ++++------------
 drivers/net/ethernet/freescale/fs_enet/fs_enet.h |  2 --
 2 files changed, 4 insertions(+), 14 deletions(-)

Comments

Christophe JAILLET Sept. 13, 2024, 8:24 p.m. UTC | #1
Le 04/09/2024 à 19:18, Maxime Chevallier a écrit :
> devm_clock_get_enabled() can be used to simplify clock handling for the
> PER register clock.
> 
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> ---
>   .../ethernet/freescale/fs_enet/fs_enet-main.c    | 16 ++++------------
>   drivers/net/ethernet/freescale/fs_enet/fs_enet.h |  2 --
>   2 files changed, 4 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> index c96a6b9e1445..ec43b71c0eba 100644
> --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> @@ -900,14 +900,9 @@ static int fs_enet_probe(struct platform_device *ofdev)
>   	 * but require enable to succeed when a clock was specified/found,
>   	 * keep a reference to the clock upon successful acquisition
>   	 */
> -	clk = devm_clk_get(&ofdev->dev, "per");
> -	if (!IS_ERR(clk)) {
> -		ret = clk_prepare_enable(clk);
> -		if (ret)
> -			goto out_deregister_fixed_link;
> -
> -		fpi->clk_per = clk;
> -	}
> +	clk = devm_clk_get_enabled(&ofdev->dev, "per");
> +	if (IS_ERR(clk))
> +		goto out_deregister_fixed_link;

Hi,

I don't know if this can lead to the same issue, but a similar change 
broke a use case in another driver. See the discussion at[1].

It ended to using devm_clk_get_optional_enabled() to keep the same 
behavior as before.

CJ

[1]: 
https://lore.kernel.org/all/20240912104630.1868285-2-ardb+git@google.com/

>   
>   	privsize = sizeof(*fep) +
>   		   sizeof(struct sk_buff **) *
> @@ -917,7 +912,7 @@ static int fs_enet_probe(struct platform_device *ofdev)
>   	ndev = alloc_etherdev(privsize);
>   	if (!ndev) {
>   		ret = -ENOMEM;
> -		goto out_put;
> +		goto out_deregister_fixed_link;
>   	}
>   
>   	SET_NETDEV_DEV(ndev, &ofdev->dev);
> @@ -979,8 +974,6 @@ static int fs_enet_probe(struct platform_device *ofdev)
>   	fep->ops->cleanup_data(ndev);
>   out_free_dev:
>   	free_netdev(ndev);
> -out_put:
> -	clk_disable_unprepare(fpi->clk_per);
>   out_deregister_fixed_link:
>   	of_node_put(fpi->phy_node);
>   	if (of_phy_is_fixed_link(ofdev->dev.of_node))
> @@ -1001,7 +994,6 @@ static void fs_enet_remove(struct platform_device *ofdev)
>   	fep->ops->cleanup_data(ndev);
>   	dev_set_drvdata(fep->dev, NULL);
>   	of_node_put(fep->fpi->phy_node);
> -	clk_disable_unprepare(fep->fpi->clk_per);
>   	if (of_phy_is_fixed_link(ofdev->dev.of_node))
>   		of_phy_deregister_fixed_link(ofdev->dev.of_node);
>   	free_netdev(ndev);
> diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet.h b/drivers/net/ethernet/freescale/fs_enet/fs_enet.h
> index ee49749a3202..6ebb1b4404c7 100644
> --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet.h
> +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet.h
> @@ -119,8 +119,6 @@ struct fs_platform_info {
>   	int napi_weight;	/* NAPI weight			*/
>   
>   	int use_rmii;		/* use RMII mode		*/
> -
> -	struct clk *clk_per;	/* 'per' clock for register access */
>   };
>   
>   struct fs_enet_private {
Maxime Chevallier Sept. 14, 2024, 8:01 a.m. UTC | #2
Hello Christophe,

On Fri, 13 Sep 2024 22:24:28 +0200
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:

> Le 04/09/2024 à 19:18, Maxime Chevallier a écrit :
> > devm_clock_get_enabled() can be used to simplify clock handling for the
> > PER register clock.
> > 
> > Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> > Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> > ---
> >   .../ethernet/freescale/fs_enet/fs_enet-main.c    | 16 ++++------------
> >   drivers/net/ethernet/freescale/fs_enet/fs_enet.h |  2 --
> >   2 files changed, 4 insertions(+), 14 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> > index c96a6b9e1445..ec43b71c0eba 100644
> > --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> > +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
> > @@ -900,14 +900,9 @@ static int fs_enet_probe(struct platform_device *ofdev)
> >   	 * but require enable to succeed when a clock was specified/found,
> >   	 * keep a reference to the clock upon successful acquisition
> >   	 */
> > -	clk = devm_clk_get(&ofdev->dev, "per");
> > -	if (!IS_ERR(clk)) {
> > -		ret = clk_prepare_enable(clk);
> > -		if (ret)
> > -			goto out_deregister_fixed_link;
> > -
> > -		fpi->clk_per = clk;
> > -	}
> > +	clk = devm_clk_get_enabled(&ofdev->dev, "per");
> > +	if (IS_ERR(clk))
> > +		goto out_deregister_fixed_link;  
> 
> Hi,
> 
> I don't know if this can lead to the same issue, but a similar change 
> broke a use case in another driver. See the discussion at[1].
> 
> It ended to using devm_clk_get_optional_enabled() to keep the same 
> behavior as before.

After digging around, there appears to be some platforms that don't
have this clock indeed. Thanks for catching this, the optional is the
way to go.

Thanks,

Maxime
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
index c96a6b9e1445..ec43b71c0eba 100644
--- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
+++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
@@ -900,14 +900,9 @@  static int fs_enet_probe(struct platform_device *ofdev)
 	 * but require enable to succeed when a clock was specified/found,
 	 * keep a reference to the clock upon successful acquisition
 	 */
-	clk = devm_clk_get(&ofdev->dev, "per");
-	if (!IS_ERR(clk)) {
-		ret = clk_prepare_enable(clk);
-		if (ret)
-			goto out_deregister_fixed_link;
-
-		fpi->clk_per = clk;
-	}
+	clk = devm_clk_get_enabled(&ofdev->dev, "per");
+	if (IS_ERR(clk))
+		goto out_deregister_fixed_link;
 
 	privsize = sizeof(*fep) +
 		   sizeof(struct sk_buff **) *
@@ -917,7 +912,7 @@  static int fs_enet_probe(struct platform_device *ofdev)
 	ndev = alloc_etherdev(privsize);
 	if (!ndev) {
 		ret = -ENOMEM;
-		goto out_put;
+		goto out_deregister_fixed_link;
 	}
 
 	SET_NETDEV_DEV(ndev, &ofdev->dev);
@@ -979,8 +974,6 @@  static int fs_enet_probe(struct platform_device *ofdev)
 	fep->ops->cleanup_data(ndev);
 out_free_dev:
 	free_netdev(ndev);
-out_put:
-	clk_disable_unprepare(fpi->clk_per);
 out_deregister_fixed_link:
 	of_node_put(fpi->phy_node);
 	if (of_phy_is_fixed_link(ofdev->dev.of_node))
@@ -1001,7 +994,6 @@  static void fs_enet_remove(struct platform_device *ofdev)
 	fep->ops->cleanup_data(ndev);
 	dev_set_drvdata(fep->dev, NULL);
 	of_node_put(fep->fpi->phy_node);
-	clk_disable_unprepare(fep->fpi->clk_per);
 	if (of_phy_is_fixed_link(ofdev->dev.of_node))
 		of_phy_deregister_fixed_link(ofdev->dev.of_node);
 	free_netdev(ndev);
diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet.h b/drivers/net/ethernet/freescale/fs_enet/fs_enet.h
index ee49749a3202..6ebb1b4404c7 100644
--- a/drivers/net/ethernet/freescale/fs_enet/fs_enet.h
+++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet.h
@@ -119,8 +119,6 @@  struct fs_platform_info {
 	int napi_weight;	/* NAPI weight			*/
 
 	int use_rmii;		/* use RMII mode		*/
-
-	struct clk *clk_per;	/* 'per' clock for register access */
 };
 
 struct fs_enet_private {