Re: [PATCH 1/2] Consolidate min_not_zero

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Martin K. Petersen wrote:
> We have several users of min_not_zero, each of them using their own
> definition.  Move the define to kernel.h.

For whatever reason this one hit my inbox way later than the previous one. 
Anyone, the same concern:

> +/*
> + * Returns the minimum that is _not_ zero, unless both are zero.
> + */
> +#define min_not_zero(__x, __y) ({		\
> +	__x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
> +

This will evaluate the value of __x and __y multiple times. Something like 
this should be better (untested):

define min_not_zero(__x, __y) ({                \
        typeof(__x) _minz1 = (__x);                     \
        typeof(__y) _minz2 = (__y);                     \
        _minz1 == 0 ? _minz2 : ((_minz2 == 0) ? _minz1 : min(_minz1, _minz2)); 
})

Eike

Attachment: signature.asc
Description: This is a digitally signed message part.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux