From patchwork Tue Jan 8 13:54:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 1946131 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by patchwork2.kernel.org (Postfix) with ESMTP id 51C29DF23A for ; Tue, 8 Jan 2013 13:58:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r08DtuFL002274; Tue, 8 Jan 2013 08:55:56 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r08DsZPs004714 for ; Tue, 8 Jan 2013 08:54:35 -0500 Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.17]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r08DsZHY028090 for ; Tue, 8 Jan 2013 08:54:35 -0500 Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r08DsXEU010053 for ; Tue, 8 Jan 2013 08:54:33 -0500 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 8BFD7A5212; Tue, 8 Jan 2013 14:54:29 +0100 (CET) From: Hannes Reinecke To: Christophe Varoqui Date: Tue, 8 Jan 2013 14:54:09 +0100 Message-Id: <1357653259-62650-32-git-send-email-hare@suse.de> In-Reply-To: <1357653259-62650-1-git-send-email-hare@suse.de> References: <1357653259-62650-1-git-send-email-hare@suse.de> X-RedHat-Spam-Score: -7.299 (BAYES_00, DCC_REPUT_00_12, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.17 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 31/42] Use VECTOR_SIZE() defines X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com The size of a vector slot might be larger than one, so we should be using the VECTOR_SIZE() define everywhere. Signed-off-by: Hannes Reinecke --- libmultipath/vector.c | 8 ++++---- libmultipath/vector.h | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libmultipath/vector.c b/libmultipath/vector.c index 652f118..74079a4 100644 --- a/libmultipath/vector.c +++ b/libmultipath/vector.c @@ -81,7 +81,7 @@ vector_insert_slot(vector v, int slot, void *value) if (!vector_alloc_slot(v)) return NULL; - for (i = (v->allocated /VECTOR_DEFAULT_SIZE) - 2; i >= slot; i--) + for (i = VECTOR_SIZE(v) - 2; i >= slot; i--) v->slot[i + 1] = v->slot[i]; v->slot[slot] = value; @@ -94,7 +94,7 @@ find_slot(vector v, void * addr) { int i; - for (i = 0; i < (v->allocated / VECTOR_DEFAULT_SIZE); i++) + for (i = 0; i < VECTOR_SIZE(v); i++) if (v->slot[i] == addr) return i; @@ -109,7 +109,7 @@ vector_del_slot(vector v, int slot) if (!v || !v->allocated || slot < 0 || slot > VECTOR_SIZE(v)) return; - for (i = slot + 1; i < (v->allocated / VECTOR_DEFAULT_SIZE); i++) + for (i = slot + 1; i < VECTOR_SIZE(v); i++) v->slot[i-1] = v->slot[i]; v->allocated -= VECTOR_DEFAULT_SIZE; @@ -137,7 +137,7 @@ vector_repack(vector v) if (!v || !v->allocated) return; - for (i = 0; i < (v->allocated / VECTOR_DEFAULT_SIZE); i++) + for (i = 0; i < VECTOR_SIZE(v); i++) if (i > 0 && v->slot[i] == NULL) vector_del_slot(v, i--); } diff --git a/libmultipath/vector.h b/libmultipath/vector.h index ca42be1..6779186 100644 --- a/libmultipath/vector.h +++ b/libmultipath/vector.h @@ -31,14 +31,14 @@ struct _vector { typedef struct _vector *vector; #define VECTOR_DEFAULT_SIZE 1 -#define VECTOR_SLOT(V,E) (((V) && (E) < (V)->allocated) ? (V)->slot[(E)] : NULL) -#define VECTOR_SIZE(V) ((V) ? (V)->allocated : 0) -#define VECTOR_LAST_SLOT(V) (((V) && (V)->allocated) ? (V)->slot[((V)->allocated - 1)] : NULL) +#define VECTOR_SIZE(V) ((V) ? ((V)->allocated) / VECTOR_DEFAULT_SIZE : 0) +#define VECTOR_SLOT(V,E) (((V) && (E) < VECTOR_SIZE(V)) ? (V)->slot[(E)] : NULL) +#define VECTOR_LAST_SLOT(V) (((V) && VECTOR_SIZE(V) > 0) ? (V)->slot[(VECTOR_SIZE(V) - 1)] : NULL) #define vector_foreach_slot(v,p,i) \ - for (i = 0; (v) && i < (v)->allocated && ((p) = (v)->slot[i]); i++) + for (i = 0; (v) && i < VECTOR_SIZE(v) && ((p) = (v)->slot[i]); i++) #define vector_foreach_slot_after(v,p,i) \ - for (; (v) && i < (v)->allocated && ((p) = (v)->slot[i]); i++) + for (; (v) && i < VECTOR_SIZE(v) && ((p) = (v)->slot[i]); i++) #define vector_foreach_slot_backwards(v,p,i) \ for (i = VECTOR_SIZE(v); i > 0 && ((p) = (v)->slot[i-1]); i--)