Messages in this thread | | | Date | Wed, 25 Oct 2023 19:36:06 +0200 | From | Sebastian Reichel <> | Subject | Re: [PATCH v4 1/3] math.h: add DIV_ROUND_UP_NO_OVERFLOW |
| |
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@linux-foundation.org> 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 [unhandled content-type:application/pgp-signature] | |