From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xifbr-000404-KH for qemu-devel@nongnu.org; Mon, 27 Oct 2014 04:25:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xifbm-0004V3-4a for qemu-devel@nongnu.org; Mon, 27 Oct 2014 04:25:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43363) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xifbl-0004Ur-Rs for qemu-devel@nongnu.org; Mon, 27 Oct 2014 04:24:58 -0400 Message-ID: <544E014D.5070802@redhat.com> Date: Mon, 27 Oct 2014 09:24:45 +0100 From: Max Reitz MIME-Version: 1.0 References: <1414253919-3044-1-git-send-email-pl@kamp.de> <1414253919-3044-2-git-send-email-pl@kamp.de> In-Reply-To: <1414253919-3044-2-git-send-email-pl@kamp.de> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCHv5 1/6] util: introduce MIN_NON_ZERO List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Lieven , qemu-devel@nongnu.org Cc: kwolf@redhat.com, famz@redhat.com, benoit@irqsave.net, ronniesahlberg@gmail.com, armbru@redhat.com, stefanha@redhat.com On 2014-10-25 at 18:18, Peter Lieven wrote: > at least in block layer we have the case of limits being defined for a > BlockDriverState. However, in this context often zero (0) has the special > meanining of undefined which means no limit. If two of those limits are > combined and the minimum is needed the minimum function should only return > zero if both parameters are zero. > > Signed-off-by: Peter Lieven > --- > include/qemu/osdep.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h > index 1565404..bcdf088 100644 > --- a/include/qemu/osdep.h > +++ b/include/qemu/osdep.h > @@ -68,6 +68,12 @@ typedef signed int int_fast16_t; > #define MAX(a, b) (((a) > (b)) ? (a) : (b)) > #endif > > +/* Minimum function that returns zero only iff both values are zero. > + * Intended for use with unsigned values only. */ > +#ifndef MIN_NON_ZERO > +#define MIN_NON_ZERO(a, b) (((a != 0) && (a) < (b)) ? (a) : (b)) *cough* This should be (((a) != 0 && (a) < (b)) ? (a) : (b)), so the parentheses need to enclose the "a", not the "a != 0". I guess the maintainer could fix that up, though. And with that fixed, of course, Reviewed-by: Max Reitz > +#endif > + > #ifndef ROUND_UP > #define ROUND_UP(n,d) (((n) + (d) - 1) & -(d)) > #endif