Re: regression in ktime.h circa 3.16.0-rc5+ breaks lirc irsend, bad commit 166afb64511

From: John Stultz
Date: Fri May 01 2015 - 14:51:56 EST


On Fri, May 1, 2015 at 11:29 AM, Nicolas Pitre <nicolas.pitre@xxxxxxxxxx> wrote:
> On Fri, 1 May 2015, John Stultz wrote:
>
>> So yea. I see the issue now. The ktime_divns() function uses do_div
>> which is an unsigned divide. So negative numbers look like large
>> numbers, and it doesn't do sign-extension, so when it divides we lose
>> the sign bit.
>
> That doesn't stop there. On 32-bit systems, if the divisor is not
> constant or too large, then __ktime_divns() is used. If you look at the
> code for __ktime_divns(), you'll notice it would get into an infinite
> loop if you pass it a negative divisor.

True. Though while negative ktime intervals are mostly rare, I suspect
we probably don't have any negative divisors for now. Even so, it
seems like something that could easily get someones foot shot.

Is there any sort of compiler magic to generate warnings if folks are
passing signed types to the divisor?

I'll be sending my first rfc of the fix here shortly. Additional
feedback there would be appreciated!

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