lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 15 May 2009 13:55:25 -0500
From:	Jon Hunter <jon-hunter@...com>
To:	John Stultz <johnstul@...ibm.com>
CC:	Ingo Molnar <mingo@...e.hu>, Thomas Gleixner <tglx@...utronix.de>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [RFC][PATCH] Dynamic Tick: Allow 32-bit machines to sleep   
 formorethan2.15 seconds


Jon Hunter wrote:
> +	/*
> +	 * If the result overflows, return the max value we can.
> +	 */
> +	if (overflow)
> +		ret = LONG_MAX;
> +	else
> +		ret = (s64)((upper << 32) + lower);
> +
>   	return ret;
>   }

Correction. Should have been LLONG_MAX and not LONG_MAX in the above. 
See below.

Jon


diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 5a40d14..647f228 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -316,8 +316,32 @@ static inline void clocksource_disable(struct 
clocksource *cs)
   */
  static inline s64 cyc2ns(struct clocksource *cs, cycle_t cycles)
  {
-       u64 ret = (u64)cycles;
-       ret = (ret * cs->mult) >> cs->shift;
+       s64 ret;
+       u64 upper, lower, overflow;
+
+       /*
+        * Split the calculation into two halves to ensure
+        * that we can catch any overflow that may occur.
+        */
+       upper = ((cycles >> 32) * cs->mult) >> cs->shift;
+       lower = ((cycles & 0xFFFFFFFF) * cs->mult) >> cs->shift;
+
+       /*
+        * Check to see if the result will overflow. If
+        * overflow is non-zero then the result is greater
+        * than 63-bits which is the max positive value
+        * for a signed result.
+        */
+       overflow = (upper + (lower >> 32)) >> 31;
+
+       /*
+        * If the result overflows, return the max value we can.
+        */
+       if (overflow)
+               ret = LLONG_MAX;
+       else
+               ret = (s64)((upper << 32) + lower);
+
         return ret;
  }

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ