netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: stmmac: minor cleanups to stmmac_bus_clks_config()
@ 2025-08-27  8:54 Russell King (Oracle)
  2025-08-27 22:27 ` Jacob Keller
  2025-08-29  0:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Russell King (Oracle) @ 2025-08-27  8:54 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
	netdev, Paolo Abeni

stmmac_bus_clks_config() doesn't need to repeatedly on dereference
priv->plat as this remains the same throughout this function. Not only
does this detract from the function's readability, but it could cause
the value to be reloaded each time. Use a local variable.

Also, the final return can simply return zero, and we can dispense
with the initialiser for 'ret'.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 27 ++++++++++---------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 429a871d7378..88f5d637f033 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -149,33 +149,34 @@ static void stmmac_exit_fs(struct net_device *dev);
 
 int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled)
 {
-	int ret = 0;
+	struct plat_stmmacenet_data *plat_dat = priv->plat;
+	int ret;
 
 	if (enabled) {
-		ret = clk_prepare_enable(priv->plat->stmmac_clk);
+		ret = clk_prepare_enable(plat_dat->stmmac_clk);
 		if (ret)
 			return ret;
-		ret = clk_prepare_enable(priv->plat->pclk);
+		ret = clk_prepare_enable(plat_dat->pclk);
 		if (ret) {
-			clk_disable_unprepare(priv->plat->stmmac_clk);
+			clk_disable_unprepare(plat_dat->stmmac_clk);
 			return ret;
 		}
-		if (priv->plat->clks_config) {
-			ret = priv->plat->clks_config(priv->plat->bsp_priv, enabled);
+		if (plat_dat->clks_config) {
+			ret = plat_dat->clks_config(plat_dat->bsp_priv, enabled);
 			if (ret) {
-				clk_disable_unprepare(priv->plat->stmmac_clk);
-				clk_disable_unprepare(priv->plat->pclk);
+				clk_disable_unprepare(plat_dat->stmmac_clk);
+				clk_disable_unprepare(plat_dat->pclk);
 				return ret;
 			}
 		}
 	} else {
-		clk_disable_unprepare(priv->plat->stmmac_clk);
-		clk_disable_unprepare(priv->plat->pclk);
-		if (priv->plat->clks_config)
-			priv->plat->clks_config(priv->plat->bsp_priv, enabled);
+		clk_disable_unprepare(plat_dat->stmmac_clk);
+		clk_disable_unprepare(plat_dat->pclk);
+		if (plat_dat->clks_config)
+			plat_dat->clks_config(plat_dat->bsp_priv, enabled);
 	}
 
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(stmmac_bus_clks_config);
 
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] net: stmmac: minor cleanups to stmmac_bus_clks_config()
  2025-08-27  8:54 [PATCH net-next] net: stmmac: minor cleanups to stmmac_bus_clks_config() Russell King (Oracle)
@ 2025-08-27 22:27 ` Jacob Keller
  2025-08-29  0:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Jacob Keller @ 2025-08-27 22:27 UTC (permalink / raw)
  To: Russell King (Oracle), Andrew Lunn, Heiner Kallweit
  Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
	netdev, Paolo Abeni


[-- Attachment #1.1: Type: text/plain, Size: 3025 bytes --]



On 8/27/2025 1:54 AM, Russell King (Oracle) wrote:
> stmmac_bus_clks_config() doesn't need to repeatedly on dereference
> priv->plat as this remains the same throughout this function. Not only
> does this detract from the function's readability, but it could cause
> the value to be reloaded each time. Use a local variable.
> 

Even if the compiler figures out its safe to store the access and reuse
it, its much more readable to use the local variable.

> Also, the final return can simply return zero, and we can dispense
> with the initialiser for 'ret'.

Also good cleanup.

> 
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> ---

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

>  .../net/ethernet/stmicro/stmmac/stmmac_main.c | 27 ++++++++++---------
>  1 file changed, 14 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 429a871d7378..88f5d637f033 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -149,33 +149,34 @@ static void stmmac_exit_fs(struct net_device *dev);
>  
>  int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled)
>  {
> -	int ret = 0;
> +	struct plat_stmmacenet_data *plat_dat = priv->plat;

I did notice the driver was inconsistent in whether it refers to this as
*plat or *plat_dat... Its slightly shorter to use *plat, but I do think
*plat_dat is a bit nicer to read.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

> +	int ret;
>  
>  	if (enabled) {
> -		ret = clk_prepare_enable(priv->plat->stmmac_clk);
> +		ret = clk_prepare_enable(plat_dat->stmmac_clk);
>  		if (ret)
>  			return ret;
> -		ret = clk_prepare_enable(priv->plat->pclk);
> +		ret = clk_prepare_enable(plat_dat->pclk);
>  		if (ret) {
> -			clk_disable_unprepare(priv->plat->stmmac_clk);
> +			clk_disable_unprepare(plat_dat->stmmac_clk);
>  			return ret;
>  		}
> -		if (priv->plat->clks_config) {
> -			ret = priv->plat->clks_config(priv->plat->bsp_priv, enabled);
> +		if (plat_dat->clks_config) {
> +			ret = plat_dat->clks_config(plat_dat->bsp_priv, enabled);
>  			if (ret) {
> -				clk_disable_unprepare(priv->plat->stmmac_clk);
> -				clk_disable_unprepare(priv->plat->pclk);
> +				clk_disable_unprepare(plat_dat->stmmac_clk);
> +				clk_disable_unprepare(plat_dat->pclk);
>  				return ret;
>  			}
>  		}
>  	} else {
> -		clk_disable_unprepare(priv->plat->stmmac_clk);
> -		clk_disable_unprepare(priv->plat->pclk);
> -		if (priv->plat->clks_config)
> -			priv->plat->clks_config(priv->plat->bsp_priv, enabled);
> +		clk_disable_unprepare(plat_dat->stmmac_clk);
> +		clk_disable_unprepare(plat_dat->pclk);
> +		if (plat_dat->clks_config)
> +			plat_dat->clks_config(plat_dat->bsp_priv, enabled);
>  	}
>  
> -	return ret;
> +	return 0;
>  }
>  EXPORT_SYMBOL_GPL(stmmac_bus_clks_config);
>  


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] net: stmmac: minor cleanups to stmmac_bus_clks_config()
  2025-08-27  8:54 [PATCH net-next] net: stmmac: minor cleanups to stmmac_bus_clks_config() Russell King (Oracle)
  2025-08-27 22:27 ` Jacob Keller
@ 2025-08-29  0:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-29  0:00 UTC (permalink / raw)
  To: Russell King
  Cc: andrew, hkallweit1, alexandre.torgue, andrew+netdev, davem,
	edumazet, kuba, linux-arm-kernel, linux-stm32, mcoquelin.stm32,
	netdev, pabeni

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 27 Aug 2025 09:54:51 +0100 you wrote:
> stmmac_bus_clks_config() doesn't need to repeatedly on dereference
> priv->plat as this remains the same throughout this function. Not only
> does this detract from the function's readability, but it could cause
> the value to be reloaded each time. Use a local variable.
> 
> Also, the final return can simply return zero, and we can dispense
> with the initialiser for 'ret'.
> 
> [...]

Here is the summary with links:
  - [net-next] net: stmmac: minor cleanups to stmmac_bus_clks_config()
    https://git.kernel.org/netdev/net-next/c/2584ed250a37

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-29  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27  8:54 [PATCH net-next] net: stmmac: minor cleanups to stmmac_bus_clks_config() Russell King (Oracle)
2025-08-27 22:27 ` Jacob Keller
2025-08-29  0:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).