From 6e14ac55a7b40804cf69de560f38561214129b07 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 11 Jul 2016 05:33:34 +0200 Subject: [PATCH 1/7] util: introduce MIN_NON_ZERO RH-Author: Fam Zheng Message-id: <1468215219-30793-2-git-send-email-famz@redhat.com> Patchwork-id: 71105 O-Subject: [RHEL-7.3 qemu-kvm PATCH 1/6] util: introduce MIN_NON_ZERO Bugzilla: 1318199 RH-Acked-by: Stefan Hajnoczi RH-Acked-by: John Snow RH-Acked-by: Paolo Bonzini From: Peter Lieven 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 Reviewed-by: Max Reitz Signed-off-by: Stefan Hajnoczi (cherry picked from commit ac3a8726644d4783eacf54212d23db01d1d30044) Signed-off-by: Fam Zheng Signed-off-by: Miroslav Rezanina --- include/qemu/osdep.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 8984da0..c47a600 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)) +#endif + #ifndef ROUND_UP #define ROUND_UP(n,d) (((n) + (d) - 1) & -(d)) #endif -- 1.8.3.1