Re: [PATCH v4] workaround regression in ina2xx introduced by cb47755725da("time: Prevent undefined behaviour in timespec64_to_ns()")

From: Arnd Bergmann
Date: Thu Sep 30 2021 - 07:04:31 EST


On Thu, Sep 30, 2021 at 10:10 AM Iain Hunter <drhunter95@xxxxxxxxx> wrote:
>
> From: Iain Hunter <iain@xxxxxxxxxxxxxxxxxxxx>
>
> That change adds an error check to avoid saturation during multiplication
> to calculate nano seconds in timespec64_to_ns().
> In ina2xx_capture_thread() a timespec64 structure is used to calculate
> the delta time until the next sample time. This delta can be negative if
> the next sample time was in the past. In the -1 case timespec64_to_ns()
> now clamps the -1 second value to KTIME_MAX. This essentially puts ina2xx
> thread to sleep forever.
> Proposed patch is to:
> 1 change from timespec64_XXX() to standard raw ktime_XXX() APIs to remove
> non-standard timespec64 calls.
> 2 split the functionality in the loop into two parts:
> - do while loop only does the test to see if the next sample time is in the
> future or in the past and so will be skipped and the sample time
> incremented until it is in the future. This test is done with a simple
> signed comparison as we are only interested in the sign being positive or
> negative.
> - after do while loop we know that next is later than now and so delay is
> positive and ksub_sub() can be used to get the delay which is positive.
>
> Signed-off-by: Iain Hunter <iain@xxxxxxxxxxxxxxxxxxxx>
>
> Fixes: cb47755725da("time: Prevent undef$

The changelog text could be improved to more closely follow the
style described in Documentation/process/submitting-patches.rst,
but the important information is here and the changes look good
to me.

Reviewed-by: Arnd Bergmann <arnd@xxxxxxxx>