Re: [PATCH] null_blk: use sector_div instead of do_div
From: Linus Torvalds
Date: Fri Nov 27 2015 - 13:08:00 EST
On Fri, Nov 27, 2015 at 5:49 AM, Arnd Bergmann <arnd@xxxxxxxx> wrote:
> - do_div(size, bs); /* convert size to pages */
> - do_div(size, 256); /* concert size to pgs pr blk */
> + sector_div(size, bs); /* convert size to pages */
> + sector_div(size, 256); /* concert size to pgs pr blk */
Ugh.
Dividing by 256 should never be done with do_div() *or* sector-div.
Same goes for this, which is just obnoxiously idiotic:
> - do_div(size, (1 << 16));
> + sector_div(size, (1 << 16));
WTF? It explicitly divides by a particular power-of-two?
Has nobody ever heard of expensive divide operations? Sure, for the
cases where we *don't* do this with inline asm etc because it's
already fairly cheap, the compiler will DTRT. But that "divide by (1
<< 16)" is just a sign of insanity.
Why is that not just
size >>= 16;
instead, which is certainly not any less legible, and won't generate
potentially crap code?
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/