Pull timer fix from Thomas Gleixner: "One more fix from the timer departement: - Handle division of negative nanosecond values proper on 32bit. A recent cleanup wrecked the sign handling of the dividend and dropped the check for negative divisors" * 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: ktime: Fix ktime_divns to do signed division
Showing the changes to kernel (1 of 2 files). Show all
Unified · Split
| @@ -266,21 +266,23 @@ lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags) · 265 unmodified lines | ||
| 266 | 266 | /* |
| 267 | 267 | * Divide a ktime value by a nanosecond value |
| 268 | 268 | */ |
| 269 | −u64 __ktime_divns(const ktime_t kt, s64 div) | |
| 269 | +s64 __ktime_divns(const ktime_t kt, s64 div) | |
| 270 | 270 | { |
| 271 | − u64 dclc; | |
| 272 | 271 | int sft = 0; |
| 272 | + s64 dclc; | |
| 273 | + u64 tmp; | |
| 273 | 274 | |
| 274 | 275 | dclc = ktime_to_ns(kt); |
| 276 | + tmp = dclc < 0 ? -dclc : dclc; | |
| 277 | + | |
| 275 | 278 | /* Make sure the divisor is less than 2^32: */ |
| 276 | 279 | while (div >> 32) { |
| 277 | 280 | sft++; |
| 278 | 281 | div >>= 1; |
| 279 | 282 | } |
| 280 | − dclc >>= sft; | |
| 281 | − do_div(dclc, (unsigned long) div); | |
| 282 | − | |
| 283 | − return dclc; | |
| 283 | + tmp >>= sft; | |
| 284 | + do_div(tmp, (unsigned long) div); | |
| 285 | + return dclc < 0 ? -tmp : tmp; | |
| 284 | 286 | } |
| 285 | 287 | EXPORT_SYMBOL_GPL(__ktime_divns); |
| 286 | 288 | #endif /* BITS_PER_LONG >= 64 */ |