Re: + kernelh-make-abs-work-with-64-bit-types.patch added to -mm tree

From: Alexey Dobriyan
Date: Thu Sep 24 2015 - 10:27:06 EST

On Thu, Sep 24, 2015 at 4:32 PM, Michal Nazarewicz <mina86@xxxxxxxxxx> wrote:
> On Wed, Sep 23 2015, Alexey Dobriyan wrote:
>> I've sent kabs() before which didn't go in because it didn't work for
>> INT_MAX et al
>> (don't worry, this abs() doens't as well) but it is nicer that this
>> version in other aspects
>> (hopefully).
>> [PATCH v2] Add kabs()
> Perhaps:
> + (void)(_x))))))); \
> instead of:
> + _x)))))); \
> at the end. Since kabs makes no sense for unsigned types itâs best to
> fail with compile-time error than to let user think that the call is
> actually doing something.

I thought so, but the amount of uses like

unsigned int = abs(unsigned int - unsigned int)

is non trivial. With a few exceptions it is about 170 on
x86_64 allmodconfig. Most of them are correct because abs()
casts to signed first. So if you want to expose such uses,
then you are forced to write

unsigned int = kabs((int)(unsigned int - unsigned int));

Don't know if it's a good thing.

> Also, you donât need ({ â }) around the â_x < 0 ? -_x : _xâ expression,
> do you?

Seems so, thank you for noticing.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at