diff options
author | Asaf Vertz <asaf.vertz@tandemg.com> | 2014-12-14 03:34:18 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-12-15 11:44:21 -0500 |
commit | 0f9a2a9c08ad3579822503d5cfa1f6b128c28a99 (patch) | |
tree | 9197bd487bda147a824debdce1bfae1861daedf5 | |
parent | c5e44b69854294df7234a4f898b2d05adee1a0d5 (diff) |
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: Asaf Vertz <asaf.vertz@tandemg.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/ethernet/cirrus/cs89x0.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/drivers/net/ethernet/cirrus/cs89x0.c b/drivers/net/ethernet/cirrus/cs89x0.c index b2427928eb11..d1c025fd9726 100644 --- a/drivers/net/ethernet/cirrus/cs89x0.c +++ b/drivers/net/ethernet/cirrus/cs89x0.c | |||
@@ -60,6 +60,7 @@ | |||
60 | #include <linux/interrupt.h> | 60 | #include <linux/interrupt.h> |
61 | #include <linux/ioport.h> | 61 | #include <linux/ioport.h> |
62 | #include <linux/in.h> | 62 | #include <linux/in.h> |
63 | #include <linux/jiffies.h> | ||
63 | #include <linux/skbuff.h> | 64 | #include <linux/skbuff.h> |
64 | #include <linux/spinlock.h> | 65 | #include <linux/spinlock.h> |
65 | #include <linux/string.h> | 66 | #include <linux/string.h> |
@@ -238,13 +239,13 @@ writereg(struct net_device *dev, u16 regno, u16 value) | |||
238 | static int __init | 239 | static int __init |
239 | wait_eeprom_ready(struct net_device *dev) | 240 | wait_eeprom_ready(struct net_device *dev) |
240 | { | 241 | { |
241 | int timeout = jiffies; | 242 | unsigned long timeout = jiffies; |
242 | /* check to see if the EEPROM is ready, | 243 | /* check to see if the EEPROM is ready, |
243 | * a timeout is used just in case EEPROM is ready when | 244 | * a timeout is used just in case EEPROM is ready when |
244 | * SI_BUSY in the PP_SelfST is clear | 245 | * SI_BUSY in the PP_SelfST is clear |
245 | */ | 246 | */ |
246 | while (readreg(dev, PP_SelfST) & SI_BUSY) | 247 | while (readreg(dev, PP_SelfST) & SI_BUSY) |
247 | if (jiffies - timeout >= 40) | 248 | if (time_after_eq(jiffies, timeout + 40)) |
248 | return -1; | 249 | return -1; |
249 | return 0; | 250 | return 0; |
250 | } | 251 | } |
@@ -485,7 +486,7 @@ control_dc_dc(struct net_device *dev, int on_not_off) | |||
485 | { | 486 | { |
486 | struct net_local *lp = netdev_priv(dev); | 487 | struct net_local *lp = netdev_priv(dev); |
487 | unsigned int selfcontrol; | 488 | unsigned int selfcontrol; |
488 | int timenow = jiffies; | 489 | unsigned long timenow = jiffies; |
489 | /* control the DC to DC convertor in the SelfControl register. | 490 | /* control the DC to DC convertor in the SelfControl register. |
490 | * Note: This is hooked up to a general purpose pin, might not | 491 | * Note: This is hooked up to a general purpose pin, might not |
491 | * always be a DC to DC convertor. | 492 | * always be a DC to DC convertor. |
@@ -499,7 +500,7 @@ control_dc_dc(struct net_device *dev, int on_not_off) | |||
499 | writereg(dev, PP_SelfCTL, selfcontrol); | 500 | writereg(dev, PP_SelfCTL, selfcontrol); |
500 | 501 | ||
501 | /* Wait for the DC/DC converter to power up - 500ms */ | 502 | /* Wait for the DC/DC converter to power up - 500ms */ |
502 | while (jiffies - timenow < HZ) | 503 | while (time_before(jiffies, timenow + HZ)) |
503 | ; | 504 | ; |
504 | } | 505 | } |
505 | 506 | ||
@@ -514,7 +515,7 @@ send_test_pkt(struct net_device *dev) | |||
514 | 0, 0, /* DSAP=0 & SSAP=0 fields */ | 515 | 0, 0, /* DSAP=0 & SSAP=0 fields */ |
515 | 0xf3, 0 /* Control (Test Req + P bit set) */ | 516 | 0xf3, 0 /* Control (Test Req + P bit set) */ |
516 | }; | 517 | }; |
517 | long timenow = jiffies; | 518 | unsigned long timenow = jiffies; |
518 | 519 | ||
519 | writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_TX_ON); | 520 | writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_TX_ON); |
520 | 521 | ||
@@ -525,10 +526,10 @@ send_test_pkt(struct net_device *dev) | |||
525 | iowrite16(ETH_ZLEN, lp->virt_addr + TX_LEN_PORT); | 526 | iowrite16(ETH_ZLEN, lp->virt_addr + TX_LEN_PORT); |
526 | 527 | ||
527 | /* Test to see if the chip has allocated memory for the packet */ | 528 | /* Test to see if the chip has allocated memory for the packet */ |
528 | while (jiffies - timenow < 5) | 529 | while (time_before(jiffies, timenow + 5)) |
529 | if (readreg(dev, PP_BusST) & READY_FOR_TX_NOW) | 530 | if (readreg(dev, PP_BusST) & READY_FOR_TX_NOW) |
530 | break; | 531 | break; |
531 | if (jiffies - timenow >= 5) | 532 | if (time_after_eq(jiffies, timenow + 5)) |
532 | return 0; /* this shouldn't happen */ | 533 | return 0; /* this shouldn't happen */ |
533 | 534 | ||
534 | /* Write the contents of the packet */ | 535 | /* Write the contents of the packet */ |
@@ -536,7 +537,7 @@ send_test_pkt(struct net_device *dev) | |||
536 | 537 | ||
537 | cs89_dbg(1, debug, "Sending test packet "); | 538 | cs89_dbg(1, debug, "Sending test packet "); |
538 | /* wait a couple of jiffies for packet to be received */ | 539 | /* wait a couple of jiffies for packet to be received */ |
539 | for (timenow = jiffies; jiffies - timenow < 3;) | 540 | for (timenow = jiffies; time_before(jiffies, timenow + 3);) |
540 | ; | 541 | ; |
541 | if ((readreg(dev, PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK) { | 542 | if ((readreg(dev, PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK) { |
542 | cs89_dbg(1, cont, "succeeded\n"); | 543 | cs89_dbg(1, cont, "succeeded\n"); |
@@ -556,7 +557,7 @@ static int | |||
556 | detect_tp(struct net_device *dev) | 557 | detect_tp(struct net_device *dev) |
557 | { | 558 | { |
558 | struct net_local *lp = netdev_priv(dev); | 559 | struct net_local *lp = netdev_priv(dev); |
559 | int timenow = jiffies; | 560 | unsigned long timenow = jiffies; |
560 | int fdx; | 561 | int fdx; |
561 | 562 | ||
562 | cs89_dbg(1, debug, "%s: Attempting TP\n", dev->name); | 563 | cs89_dbg(1, debug, "%s: Attempting TP\n", dev->name); |
@@ -574,7 +575,7 @@ detect_tp(struct net_device *dev) | |||
574 | /* Delay for the hardware to work out if the TP cable is present | 575 | /* Delay for the hardware to work out if the TP cable is present |
575 | * - 150ms | 576 | * - 150ms |
576 | */ | 577 | */ |
577 | for (timenow = jiffies; jiffies - timenow < 15;) | 578 | for (timenow = jiffies; time_before(jiffies, timenow + 15);) |
578 | ; | 579 | ; |
579 | if ((readreg(dev, PP_LineST) & LINK_OK) == 0) | 580 | if ((readreg(dev, PP_LineST) & LINK_OK) == 0) |
580 | return DETECTED_NONE; | 581 | return DETECTED_NONE; |
@@ -618,7 +619,7 @@ detect_tp(struct net_device *dev) | |||
618 | if ((lp->auto_neg_cnf & AUTO_NEG_BITS) == AUTO_NEG_ENABLE) { | 619 | if ((lp->auto_neg_cnf & AUTO_NEG_BITS) == AUTO_NEG_ENABLE) { |
619 | pr_info("%s: negotiating duplex...\n", dev->name); | 620 | pr_info("%s: negotiating duplex...\n", dev->name); |
620 | while (readreg(dev, PP_AutoNegST) & AUTO_NEG_BUSY) { | 621 | while (readreg(dev, PP_AutoNegST) & AUTO_NEG_BUSY) { |
621 | if (jiffies - timenow > 4000) { | 622 | if (time_after(jiffies, timenow + 4000)) { |
622 | pr_err("**** Full / half duplex auto-negotiation timed out ****\n"); | 623 | pr_err("**** Full / half duplex auto-negotiation timed out ****\n"); |
623 | break; | 624 | break; |
624 | } | 625 | } |
@@ -1271,7 +1272,7 @@ static void __init reset_chip(struct net_device *dev) | |||
1271 | { | 1272 | { |
1272 | #if !defined(CONFIG_MACH_MX31ADS) | 1273 | #if !defined(CONFIG_MACH_MX31ADS) |
1273 | struct net_local *lp = netdev_priv(dev); | 1274 | struct net_local *lp = netdev_priv(dev); |
1274 | int reset_start_time; | 1275 | unsigned long reset_start_time; |
1275 | 1276 | ||
1276 | writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET); | 1277 | writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET); |
1277 | 1278 | ||
@@ -1294,7 +1295,7 @@ static void __init reset_chip(struct net_device *dev) | |||
1294 | /* Wait until the chip is reset */ | 1295 | /* Wait until the chip is reset */ |
1295 | reset_start_time = jiffies; | 1296 | reset_start_time = jiffies; |
1296 | while ((readreg(dev, PP_SelfST) & INIT_DONE) == 0 && | 1297 | while ((readreg(dev, PP_SelfST) & INIT_DONE) == 0 && |
1297 | jiffies - reset_start_time < 2) | 1298 | time_before(jiffies, reset_start_time + 2)) |
1298 | ; | 1299 | ; |
1299 | #endif /* !CONFIG_MACH_MX31ADS */ | 1300 | #endif /* !CONFIG_MACH_MX31ADS */ |
1300 | } | 1301 | } |