lkml.org 
[lkml]   [2015]   [May]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] ktime: Fix ktime_divns to do signed division
From
On Fri, May 1, 2015 at 4:54 PM, Nicolas Pitre <nicolas.pitre@linaro.org> wrote:
> On Fri, 1 May 2015, John Stultz wrote:
>
>> It was noted that the 32bit implementation of ktime_divns
>> was doing unsgined division adn didn't properly handle
>> negative values.
>>
>> This patch fixes the problem by checking and preserving
>> the sign bit, and then reapplying it if appropriate
>> after the division.
>>
>> Unfortunately there is some duplication since we have
>> the optimized version for constant 32bit divider. I
>> was considering reworkign the __ktime_divns helper
>> to simplify the sign-handling logic, but then it
>> would likely just be a s64/s64 divide, and probably
>> should be more generic.
>>
>> Thoughts?
>
> Wouldn't it be better to simply forbid negative time altogether? Given
> it's been broken for quite a while, there must not be that many
> instances of such usage and fixing them would avoid the useless sign
> handling overhead to 99.9% of the cases.

Well, ktime is basically an s64 and timespecs can be negative as well.
So I'm not sure its reasonable to disqualify negative time intervals
from using this function. Especially since on 64bit systems,
ktime_divns handles negative intervals just fine.


>> Nicolas also notes that the ktime_divns() function
>> breaks if someone passes in a negative divisor as
>> well. This patch doesn't yet address that issue.
>
> GRanted, a negative divisor here would be even weirder and should
> definitely be rejected. Maybe the infinite loop is a good thing in that
> case, probably better than producing wrong numbers.

Yea. I'm thinking a WARN_ON or a BUG would be good to have in both
32bit and 64bit cases so we avoid folks testing on 64bit and thinking
it works generally.

thanks
-john


\
 
 \ /
  Last update: 2015-05-02 02:41    [W:0.052 / U:1.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site