Skip to contentSkip to conversation

mac80211: fix time difference calculation for jiffy wrap

PATCH New Reiner Herrmann 1 participant 1 message Apr 30, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mac80211: fix time difference calculation for jiffy wrap

The previous calculation is wrong for jiffy wraps, because the result would be LONG_MAX/2 - (start - end), which is about LONG_MAX/2 for values near the wrap (e.g. start=LONG_MAX-1, end=1), though they should be very small.

Calculating the difference with signed values works also if there was a wrap.

---
 drivers/net/wireless/ipw2x00/libipw_wx.c | 8 ++------
 net/wireless/core.h                      | 8 ++------
 2 files changed, 4 insertions(+), 12 deletions(-)
drivers/net/wireless/ipw2x00/libipw_wx.c +2 -6
index 54aba47..1c61cfc 100644
@@ -47,12 +47,8 @@ static const char *libipw_modes[] = {
 
 static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
 {
-	unsigned long end = jiffies;
-
-	if (end >= start)
-		return jiffies_to_msecs(end - start);
-
-	return jiffies_to_msecs(end + (MAX_JIFFY_OFFSET - start) + 1);
+	unsigned long diff = (long)jiffies - (long)start;
+	return jiffies_to_msecs(diff);
 }
 
 #define MAX_CUSTOM_LEN 64
net/wireless/core.h +2 -6
index 5b1fdca..930fbbe 100644
@@ -432,12 +432,8 @@ cfg80211_can_use_chan(struct cfg80211_registered_device *rdev,
 
 static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
 {
-	unsigned long end = jiffies;
-
-	if (end >= start)
-		return jiffies_to_msecs(end - start);
-
-	return jiffies_to_msecs(end + (MAX_JIFFY_OFFSET - start) + 1);
+	unsigned long diff = (long)jiffies - (long)start;
+	return jiffies_to_msecs(diff);
 }
 
 void
Signature · 1 line
2.0.0.rc0