Re: [Cake] [PATCH] sch_cake: avoid possible divide by zero in cake_enqueue()

From: Jonathan Morton
Date: Thu Jan 02 2020 - 16:58:11 EST


> On 2 Jan, 2020, at 11:21 am, Wen Yang <wenyang@xxxxxxxxxxxxxxxxx> wrote:
>
> The variables 'window_interval' is u64 and do_div()
> truncates it to 32 bits, which means it can test
> non-zero and be truncated to zero for division.
> The unit of window_interval is nanoseconds,
> so its lower 32-bit is relatively easy to exceed.
> Fix this issue by using div64_u64() instead.

That might actually explain a few things. I approve.

Honestly the *correct* fix is for the compiler to implement division in a way that doesn't require substituting it with function calls. As this shows, it's error-prone to do this manually.

- Jonathan Morton