Re: [PATCH v4 1/3] math.h: add DIV_ROUND_UP_NO_OVERFLOW

From: Sebastian Reichel
Date: Wed Oct 25 2023 - 13:36:20 EST


Hi,

On Tue, Oct 24, 2023 at 12:53:03PM -1000, Linus Torvalds wrote:
> On Tue, 24 Oct 2023 at 09:32, Linus Torvalds
> <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> >
> > I would really prefer to just make our regular DIV_ROUND_UP() DTRT. But:
> >
> > - people do use it with complex first arguments (ie function calls
> > etc) that we don't want to evaluate twice
> >
> > - we can't make it an inline function, because the types aren't fixed
> >
> > - we can't even use a statement expression and __auto_type, because
> > these things are used in type definitions etc and need to be constant
> > expressions
>
> Ok. I have a potential beginning of a solution.
>
> It is unbelievably disgustingly complicated. But it might approach
> being correct.
>
> And by that "it might approach being correct" I obviously mean "this
> is untested, but builds at least some kernel code".
>
> I'm almost certain it will fail on more complex cases, because I
> already found a lot of questionable stuff that was simply hidden by
> the old macro just silently doing the C arithmetic type conversions,
> and this thing does type handling manually.
>
> I'm hoping that somebody will go "Linus, you're just being
> *completely* silly, it's much easier to do XYZ".

I think your new __div_round_up_ull() should also be used by
DIV_ROUND_UP_ULL, which is defined in linux/math.h.

-- Sebastian

Attachment: signature.asc
Description: PGP signature