Skip to contentSkip to conversation

net: ksz884x: use time_before in netdev_open for compatibility and remove static variable

PATCH In review wudaemon 2 participants 2 messages Mar 1, 2022 – Mar 5, 2022

Subsystems (2)
lore
Share & tools
lore

wudaemon

author
#0 lore raw

PATCH v3 1/1 net: ksz884x: use time_before in netdev_open for compatibility and remove static variable

use time_before instead of direct compare for compatibility and remove the static next_jiffies variable

---
 drivers/net/ethernet/micrel/ksz884x.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/micrel/ksz884x.c +4 -2
index d024983815da..ce4f5c99c1ac 100644
@@ -5225,7 +5225,6 @@ static irqreturn_t netdev_intr(int irq, void *dev_id)
  * Linux network device functions
  */
 
-static unsigned long next_jiffies;
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
 static void netdev_netpoll(struct net_device *dev)
@@ -5411,10 +5410,12 @@ static int netdev_open(struct net_device *dev)
 	struct dev_info *hw_priv = priv->adapter;
 	struct ksz_hw *hw = &hw_priv->hw;
 	struct ksz_port *port = &priv->port;
+	unsigned long next_jiffies;
 	int i;
 	int p;
 	int rc = 0;
 
+	next_jiffies = jiffies;
 	priv->multicast = 0;
 	priv->promiscuous = 0;
 
@@ -5428,7 +5429,7 @@ static int netdev_open(struct net_device *dev)
 		if (rc)
 			return rc;
 		for (i = 0; i < hw->mib_port_cnt; i++) {
-			if (next_jiffies < jiffies)
+			if (time_before(next_jiffies, jiffies))
 				next_jiffies = jiffies + HZ * 2;
 			else
 				next_jiffies += HZ * 1;
@@ -6563,6 +6564,7 @@ static void mib_read_work(struct work_struct *work)
 	struct dev_info *hw_priv =
 		container_of(work, struct dev_info, mib_read);
 	struct ksz_hw *hw = &hw_priv->hw;
+	unsigned long next_jiffies;
 	struct ksz_port_mib *mib;
 	int i;
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 3 lines · On Tue, 1 Mar 2022 15:18:08 +0000 wudaemon wrote:

use time_before instead of direct compare for compatibility and remove the static next_jiffies variable

Oops, thought I replied to this one but apparently I haven't. Sorry for the delay.

Quoted 13 lines
drivers/net/ethernet/micrel/ksz884x.c +0 -1
index d024983815da..ce4f5c99c1ac 100644
@@ -5225,7 +5225,6 @@ static irqreturn_t netdev_intr(int irq, void *dev_id)
  * Linux network device functions
  */
 
-static unsigned long next_jiffies;
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
 static void netdev_netpoll(struct net_device *dev)

drivers/net/ethernet/micrel/ksz884x.c static int netdev_open(struct net_device *dev) · line 5418

Quoted 9 lines
drivers/net/ethernet/micrel/ksz884x.c +2 -0
@@ -5411,10 +5410,12 @@ static int netdev_open(struct net_device *dev)
 	struct dev_info *hw_priv = priv->adapter;
 	struct ksz_hw *hw = &hw_priv->hw;
 	struct ksz_port *port = &priv->port;
+	unsigned long next_jiffies;
 	int i;
 	int p;
 	int rc = 0;
 
+	next_jiffies = jiffies;

This should probably be:

	next_jiffies = jiffies + HZ * 2;

and then...

drivers/net/ethernet/micrel/ksz884x.c static int netdev_open(struct net_device *dev) · line 5432

Quoted 9 lines
drivers/net/ethernet/micrel/ksz884x.c +1 -1
 	priv->multicast = 0;
 	priv->promiscuous = 0;
 
@@ -5428,7 +5429,7 @@ static int netdev_open(struct net_device *dev)
 		if (rc)
 			return rc;
 		for (i = 0; i < hw->mib_port_cnt; i++) {
-			if (next_jiffies < jiffies)
+			if (time_before(next_jiffies, jiffies))

I don't think this check is needed at all any more. Since we initialize next_jiffies to jiffies earlier in the function it's got to be in the right ballpark.

drivers/net/ethernet/micrel/ksz884x.c static int netdev_open(struct net_device *dev) · line 5435

Quoted 3 lines
drivers/net/ethernet/micrel/ksz884x.c +0 -0
 				next_jiffies = jiffies + HZ * 2;
 			else
 				next_jiffies += HZ * 1;

Remove the if and just leave this line to move the time forward.

Thanks!