Commit 0f9a2a9c authored by Asaf Vertz's avatar Asaf Vertz Committed by David S. Miller

cirrus: cs89x0: fix time comparison

To be future-proof and for better readability the time comparisons are
modified to use time_before, time_after, and time_after_eq instead of
plain, error-prone math.
Signed-off-by: default avatarAsaf Vertz <asaf.vertz@tandemg.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c5e44b69
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/in.h> #include <linux/in.h>
#include <linux/jiffies.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/string.h> #include <linux/string.h>
...@@ -238,13 +239,13 @@ writereg(struct net_device *dev, u16 regno, u16 value) ...@@ -238,13 +239,13 @@ writereg(struct net_device *dev, u16 regno, u16 value)
static int __init static int __init
wait_eeprom_ready(struct net_device *dev) wait_eeprom_ready(struct net_device *dev)
{ {
int timeout = jiffies; unsigned long timeout = jiffies;
/* check to see if the EEPROM is ready, /* check to see if the EEPROM is ready,
* a timeout is used just in case EEPROM is ready when * a timeout is used just in case EEPROM is ready when
* SI_BUSY in the PP_SelfST is clear * SI_BUSY in the PP_SelfST is clear
*/ */
while (readreg(dev, PP_SelfST) & SI_BUSY) while (readreg(dev, PP_SelfST) & SI_BUSY)
if (jiffies - timeout >= 40) if (time_after_eq(jiffies, timeout + 40))
return -1; return -1;
return 0; return 0;
} }
...@@ -485,7 +486,7 @@ control_dc_dc(struct net_device *dev, int on_not_off) ...@@ -485,7 +486,7 @@ control_dc_dc(struct net_device *dev, int on_not_off)
{ {
struct net_local *lp = netdev_priv(dev); struct net_local *lp = netdev_priv(dev);
unsigned int selfcontrol; unsigned int selfcontrol;
int timenow = jiffies; unsigned long timenow = jiffies;
/* control the DC to DC convertor in the SelfControl register. /* control the DC to DC convertor in the SelfControl register.
* Note: This is hooked up to a general purpose pin, might not * Note: This is hooked up to a general purpose pin, might not
* always be a DC to DC convertor. * always be a DC to DC convertor.
...@@ -499,7 +500,7 @@ control_dc_dc(struct net_device *dev, int on_not_off) ...@@ -499,7 +500,7 @@ control_dc_dc(struct net_device *dev, int on_not_off)
writereg(dev, PP_SelfCTL, selfcontrol); writereg(dev, PP_SelfCTL, selfcontrol);
/* Wait for the DC/DC converter to power up - 500ms */ /* Wait for the DC/DC converter to power up - 500ms */
while (jiffies - timenow < HZ) while (time_before(jiffies, timenow + HZ))
; ;
} }
...@@ -514,7 +515,7 @@ send_test_pkt(struct net_device *dev) ...@@ -514,7 +515,7 @@ send_test_pkt(struct net_device *dev)
0, 0, /* DSAP=0 & SSAP=0 fields */ 0, 0, /* DSAP=0 & SSAP=0 fields */
0xf3, 0 /* Control (Test Req + P bit set) */ 0xf3, 0 /* Control (Test Req + P bit set) */
}; };
long timenow = jiffies; unsigned long timenow = jiffies;
writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_TX_ON); writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_TX_ON);
...@@ -525,10 +526,10 @@ send_test_pkt(struct net_device *dev) ...@@ -525,10 +526,10 @@ send_test_pkt(struct net_device *dev)
iowrite16(ETH_ZLEN, lp->virt_addr + TX_LEN_PORT); iowrite16(ETH_ZLEN, lp->virt_addr + TX_LEN_PORT);
/* Test to see if the chip has allocated memory for the packet */ /* Test to see if the chip has allocated memory for the packet */
while (jiffies - timenow < 5) while (time_before(jiffies, timenow + 5))
if (readreg(dev, PP_BusST) & READY_FOR_TX_NOW) if (readreg(dev, PP_BusST) & READY_FOR_TX_NOW)
break; break;
if (jiffies - timenow >= 5) if (time_after_eq(jiffies, timenow + 5))
return 0; /* this shouldn't happen */ return 0; /* this shouldn't happen */
/* Write the contents of the packet */ /* Write the contents of the packet */
...@@ -536,7 +537,7 @@ send_test_pkt(struct net_device *dev) ...@@ -536,7 +537,7 @@ send_test_pkt(struct net_device *dev)
cs89_dbg(1, debug, "Sending test packet "); cs89_dbg(1, debug, "Sending test packet ");
/* wait a couple of jiffies for packet to be received */ /* wait a couple of jiffies for packet to be received */
for (timenow = jiffies; jiffies - timenow < 3;) for (timenow = jiffies; time_before(jiffies, timenow + 3);)
; ;
if ((readreg(dev, PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK) { if ((readreg(dev, PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK) {
cs89_dbg(1, cont, "succeeded\n"); cs89_dbg(1, cont, "succeeded\n");
...@@ -556,7 +557,7 @@ static int ...@@ -556,7 +557,7 @@ static int
detect_tp(struct net_device *dev) detect_tp(struct net_device *dev)
{ {
struct net_local *lp = netdev_priv(dev); struct net_local *lp = netdev_priv(dev);
int timenow = jiffies; unsigned long timenow = jiffies;
int fdx; int fdx;
cs89_dbg(1, debug, "%s: Attempting TP\n", dev->name); cs89_dbg(1, debug, "%s: Attempting TP\n", dev->name);
...@@ -574,7 +575,7 @@ detect_tp(struct net_device *dev) ...@@ -574,7 +575,7 @@ detect_tp(struct net_device *dev)
/* Delay for the hardware to work out if the TP cable is present /* Delay for the hardware to work out if the TP cable is present
* - 150ms * - 150ms
*/ */
for (timenow = jiffies; jiffies - timenow < 15;) for (timenow = jiffies; time_before(jiffies, timenow + 15);)
; ;
if ((readreg(dev, PP_LineST) & LINK_OK) == 0) if ((readreg(dev, PP_LineST) & LINK_OK) == 0)
return DETECTED_NONE; return DETECTED_NONE;
...@@ -618,7 +619,7 @@ detect_tp(struct net_device *dev) ...@@ -618,7 +619,7 @@ detect_tp(struct net_device *dev)
if ((lp->auto_neg_cnf & AUTO_NEG_BITS) == AUTO_NEG_ENABLE) { if ((lp->auto_neg_cnf & AUTO_NEG_BITS) == AUTO_NEG_ENABLE) {
pr_info("%s: negotiating duplex...\n", dev->name); pr_info("%s: negotiating duplex...\n", dev->name);
while (readreg(dev, PP_AutoNegST) & AUTO_NEG_BUSY) { while (readreg(dev, PP_AutoNegST) & AUTO_NEG_BUSY) {
if (jiffies - timenow > 4000) { if (time_after(jiffies, timenow + 4000)) {
pr_err("**** Full / half duplex auto-negotiation timed out ****\n"); pr_err("**** Full / half duplex auto-negotiation timed out ****\n");
break; break;
} }
...@@ -1271,7 +1272,7 @@ static void __init reset_chip(struct net_device *dev) ...@@ -1271,7 +1272,7 @@ static void __init reset_chip(struct net_device *dev)
{ {
#if !defined(CONFIG_MACH_MX31ADS) #if !defined(CONFIG_MACH_MX31ADS)
struct net_local *lp = netdev_priv(dev); struct net_local *lp = netdev_priv(dev);
int reset_start_time; unsigned long reset_start_time;
writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET); writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET);
...@@ -1294,7 +1295,7 @@ static void __init reset_chip(struct net_device *dev) ...@@ -1294,7 +1295,7 @@ static void __init reset_chip(struct net_device *dev)
/* Wait until the chip is reset */ /* Wait until the chip is reset */
reset_start_time = jiffies; reset_start_time = jiffies;
while ((readreg(dev, PP_SelfST) & INIT_DONE) == 0 && while ((readreg(dev, PP_SelfST) & INIT_DONE) == 0 &&
jiffies - reset_start_time < 2) time_before(jiffies, reset_start_time + 2))
; ;
#endif /* !CONFIG_MACH_MX31ADS */ #endif /* !CONFIG_MACH_MX31ADS */
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment