All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rolf Eike Beer <eike-kernel@sf-tec.de>
To: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: jens.axboe@oracle.com, James.Bottomley@hansenpartnership.com,
	christof.schmitt@de.ibm.com, linux-scsi@vger.kernel.org
Subject: Re: [PATCH 1/2] Consolidate min_not_zero
Date: Fri, 10 Sep 2010 10:13:51 +0200	[thread overview]
Message-ID: <201009101014.00667.eike-kernel@sf-tec.de> (raw)
In-Reply-To: <1284095925-12841-2-git-send-email-martin.petersen@oracle.com>

[-- Attachment #1: Type: Text/Plain, Size: 846 bytes --]

> --- 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 #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2010-09-10  8:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-10  5:18 (unknown), Martin K. Petersen
2010-09-10  5:18 ` [PATCH 1/2] Consolidate min_not_zero Martin K. Petersen
2010-09-10  8:13   ` Rolf Eike Beer [this message]
2010-09-10 16:13     ` Martin K. Petersen
2010-09-10  5:18 ` [PATCH 2/2] block/scsi: Provide a limit on the number of integrity segments Martin K. Petersen
2010-09-10  5:32 Limit " Martin K. Petersen
2010-09-10  5:32 ` [PATCH 1/2] Consolidate min_not_zero Martin K. Petersen
2010-09-10 13:20   ` Rolf Eike Beer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201009101014.00667.eike-kernel@sf-tec.de \
    --to=eike-kernel@sf-tec.de \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=christof.schmitt@de.ibm.com \
    --cc=jens.axboe@oracle.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.