All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mac80211: fix time difference calculation for jiffy wrap
@ 2014-04-30 16:09 Reiner Herrmann
  0 siblings, 0 replies; only message in thread
From: Reiner Herrmann @ 2014-04-30 16:09 UTC (permalink / raw)
  To: linux-wireless

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.

Signed-off-by: Reiner Herrmann <reiner@reiner-h.de>
---
 drivers/net/wireless/ipw2x00/libipw_wx.c | 8 ++------
 net/wireless/core.h                      | 8 ++------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/net/wireless/ipw2x00/libipw_wx.c b/drivers/net/wireless/ipw2x00/libipw_wx.c
index 54aba47..1c61cfc 100644
--- a/drivers/net/wireless/ipw2x00/libipw_wx.c
+++ b/drivers/net/wireless/ipw2x00/libipw_wx.c
@@ -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
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 5b1fdca..930fbbe 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -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
-- 
2.0.0.rc0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2014-04-30 16:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-30 16:09 [PATCH] mac80211: fix time difference calculation for jiffy wrap Reiner Herrmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.