Re: [PATCH 1/2] Consolidate min_not_zero

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

 



> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -636,6 +636,12 @@ static inline void ftrace_dump(enum ftrace_dump_mode
> oops_dump_mode) { } (void) (&_max1 == &_max2);		\
>  	_max1 > _max2 ? _max1 : _max2; })
> 
> +/*
> + * 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)); })
> +
>  /**
>   * clamp - return a value clamped to a given range with strict
> typechecking * @val: current value

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