netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>, Heiner Kallweit <hkallweit1@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Jose Abreu <joabreu@synopsys.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-stm32@st-md-mailman.stormreply.com,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	netdev@vger.kernel.org, Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH net-next v2 11/17] net: stmmac: move priv->eee_enabled into stmmac_eee_init()
Date: Mon, 06 Jan 2025 12:25:39 +0000	[thread overview]
Message-ID: <E1tUmAt-007VXh-TZ@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <Z3vLbRQ9Ctl-Rpdg@shell.armlinux.org.uk>

All call sites for stmmac_eee_init() assign the return code to
priv->eee_enabled. Rather than having this coded at each call site,
move the assignment inside stmmac_eee_init().

Since stmmac_init_eee() takes priv->lock before checking the state of
priv->eee_enabled, move the assignment within the locked region. Also,
stmmac_suspend() checks the state of this member under the lock. While
two concurrent calls to stmmac_init_eee() aren't possible, there is
a possibility that stmmac_suspend() may run concurrently with a change
of priv->eee_enabled unless we modify it under the lock.

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

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 7cce2eb3d82e..cf294fe3f726 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -464,11 +464,13 @@ static void stmmac_eee_ctrl_timer(struct timer_list *t)
  *  can also manage EEE, this function enable the LPI state and start related
  *  timer.
  */
-static bool stmmac_eee_init(struct stmmac_priv *priv)
+static void stmmac_eee_init(struct stmmac_priv *priv)
 {
 	/* Check if MAC core supports the EEE feature. */
-	if (!priv->dma_cap.eee)
-		return false;
+	if (!priv->dma_cap.eee) {
+		priv->eee_enabled = false;
+		return;
+	}
 
 	mutex_lock(&priv->lock);
 
@@ -485,8 +487,9 @@ static bool stmmac_eee_init(struct stmmac_priv *priv)
 						priv->plat->mult_fact_100ns,
 						false);
 		}
+		priv->eee_enabled = false;
 		mutex_unlock(&priv->lock);
-		return false;
+		return;
 	}
 
 	if (priv->eee_active && !priv->eee_enabled) {
@@ -509,9 +512,10 @@ static bool stmmac_eee_init(struct stmmac_priv *priv)
 			  STMMAC_LPI_T(priv->tx_lpi_timer));
 	}
 
+	priv->eee_enabled = true;
+
 	mutex_unlock(&priv->lock);
 	netdev_dbg(priv->dev, "Energy-Efficient Ethernet initialized\n");
-	return true;
 }
 
 /* stmmac_get_tx_hwtstamp - get HW TX timestamps
@@ -969,7 +973,7 @@ static void stmmac_mac_link_down(struct phylink_config *config,
 
 	stmmac_mac_set(priv, priv->ioaddr, false);
 	priv->eee_active = false;
-	priv->eee_enabled = stmmac_eee_init(priv);
+	stmmac_eee_init(priv);
 	stmmac_set_eee_pls(priv, priv->hw, false);
 
 	if (stmmac_fpe_supported(priv))
@@ -1082,7 +1086,7 @@ static void stmmac_mac_link_up(struct phylink_config *config,
 					     STMMAC_FLAG_RX_CLK_RUNS_IN_LPI));
 		priv->tx_lpi_timer = phy->eee_cfg.tx_lpi_timer;
 		priv->eee_active = phy->enable_tx_lpi;
-		priv->eee_enabled = stmmac_eee_init(priv);
+		stmmac_eee_init(priv);
 		stmmac_set_eee_pls(priv, priv->hw, true);
 	}
 
-- 
2.30.2


  parent reply	other threads:[~2025-01-06 12:25 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-06 12:24 [PATCH net-next 00/17] net: stmmac: clean up and fix EEE implementation Russell King (Oracle)
2025-01-06 12:24 ` [PATCH net-next v2 01/17] net: phy: add configuration of rx clock stop mode Russell King (Oracle)
2025-01-06 12:24 ` [PATCH net-next v2 02/17] net: stmmac: move tx_lpi_timer tracking to phylib Russell King (Oracle)
2025-01-06 16:44   ` Andrew Lunn
2025-01-06 12:24 ` [PATCH net-next v2 03/17] net: stmmac: use correct type for tx_lpi_timer Russell King (Oracle)
2025-01-06 16:45   ` Andrew Lunn
2025-01-07 16:34     ` Russell King (Oracle)
2025-01-07 11:28   ` Simon Horman
2025-01-07 11:57     ` Russell King (Oracle)
2025-01-07 14:41       ` Simon Horman
2025-01-07 15:26         ` Russell King (Oracle)
2025-01-08  9:42           ` Simon Horman
2025-01-06 12:25 ` [PATCH net-next v2 04/17] net: stmmac: make EEE depend on phy->enable_tx_lpi Russell King (Oracle)
2025-01-06 16:48   ` Andrew Lunn
2025-01-06 12:25 ` [PATCH net-next v2 05/17] net: stmmac: remove redundant code from ethtool EEE ops Russell King (Oracle)
2025-01-06 16:49   ` Andrew Lunn
2025-01-06 12:25 ` [PATCH net-next v2 06/17] net: stmmac: clean up stmmac_disable_eee_mode() Russell King (Oracle)
2025-01-06 16:50   ` Andrew Lunn
2025-01-06 12:25 ` [PATCH net-next v2 07/17] net: stmmac: remove priv->tx_lpi_enabled Russell King (Oracle)
2025-01-06 16:50   ` Andrew Lunn
2025-01-06 12:25 ` [PATCH net-next v2 08/17] net: stmmac: report EEE error statistics if EEE is supported Russell King (Oracle)
2025-01-06 16:51   ` Andrew Lunn
2025-01-06 12:25 ` [PATCH net-next v2 09/17] net: stmmac: convert to use phy_eee_rx_clock_stop() Russell King (Oracle)
2025-01-06 17:02   ` Andrew Lunn
2025-01-06 12:25 ` [PATCH net-next v2 10/17] net: stmmac: remove priv->eee_tw_timer Russell King (Oracle)
2025-01-06 17:02   ` Andrew Lunn
2025-01-06 12:25 ` Russell King (Oracle) [this message]
2025-01-06 17:04   ` [PATCH net-next v2 11/17] net: stmmac: move priv->eee_enabled into stmmac_eee_init() Andrew Lunn
2025-01-06 12:25 ` [PATCH net-next v2 12/17] net: stmmac: move priv->eee_active " Russell King (Oracle)
2025-01-06 17:05   ` Andrew Lunn
2025-01-07  7:28   ` kernel test robot
2025-01-06 12:25 ` [PATCH net-next v2 13/17] net: stmmac: use boolean for eee_enabled and eee_active Russell King (Oracle)
2025-01-06 17:05   ` Andrew Lunn
2025-01-06 12:25 ` [PATCH net-next v2 14/17] net: stmmac: move setup of eee_ctrl_timer to stmmac_dvr_probe() Russell King (Oracle)
2025-01-06 17:05   ` Andrew Lunn
2025-01-06 12:26 ` [PATCH net-next v2 15/17] net: stmmac: remove unnecessary EEE handling in stmmac_release() Russell King (Oracle)
2025-01-06 17:06   ` Andrew Lunn
2025-01-06 12:26 ` [PATCH net-next v2 16/17] net: stmmac: split hardware LPI timer control Russell King (Oracle)
2025-01-06 17:07   ` Andrew Lunn
2025-01-06 12:26 ` [PATCH net-next v2 17/17] net: stmmac: remove stmmac_lpi_entry_timer_config() Russell King (Oracle)
2025-01-06 17:08   ` Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1tUmAt-007VXh-TZ@rmk-PC.armlinux.org.uk \
    --to=rmk+kernel@armlinux.org.uk \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=joabreu@synopsys.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).