Re: [PATCH] mm/page-writeback.c: avoid potential division by zero

From: Qian Cai
Date: Wed Jan 01 2020 - 07:42:25 EST




> On Jan 1, 2020, at 4:32 AM, Wen Yang <wenyang@xxxxxxxxxxxxxxxxx> wrote:
>
> The variables 'min', 'max' and 'bw' are unsigned long and
> do_div truncates them to 32 bits, which means it can test
> non-zero and be truncated to zero for division.
> Fix this issue by using div64_ul() instead.

How did you find out the issue? If it is caught by compilers, can you paste the original warnings? Also, can you figure out which commit introduced the issue in the first place, so it could be backported to stable if needed?

>
> For the two variables 'numerator' and 'denominator',
> though they are declared as long, they should actually be
> unsigned long (according to the implementation of
> the fprop_fraction_percpu() function).