e1000e: prevent division by zero if TIMINCA is zero
authorDenys Vlasenko <dvlasenk@redhat.com>
Fri, 6 May 2016 19:41:51 +0000 (21:41 +0200)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Wed, 29 Jun 2016 17:00:22 +0000 (10:00 -0700)
Users report that under VMWare, er32(TIMINCA) returns zero.
This causes division by zero at init time as follows:

 ==>       incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK;
           for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) {
                   /* latch SYSTIMH on read of SYSTIML */
                   systim_next = (cycle_t)er32(SYSTIML);
                   systim_next |= (cycle_t)er32(SYSTIMH) << 32;

                   time_delta = systim_next - systim;
                   temp = time_delta;
 ====>             rem = do_div(temp, incvalue);

This change makes kernel survive this, and users report that
NIC does work after this change.

Since on real hardware incvalue is never zero, this should not affect
real hardware use case.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/e1000e/netdev.c

index 75e6089..9d5bab8 100644 (file)
@@ -4352,7 +4352,8 @@ static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc)
 
                        time_delta = systim_next - systim;
                        temp = time_delta;
-                       rem = do_div(temp, incvalue);
+                       /* VMWare users have seen incvalue of zero, don't div / 0 */
+                       rem = incvalue ? do_div(temp, incvalue) : (time_delta != 0);
 
                        systim = systim_next;