From patchwork Thu Jan 17 14:59:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 1996841 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by patchwork2.kernel.org (Postfix) with ESMTP id 62DA6DF2E1 for ; Thu, 17 Jan 2013 15:02:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r0HF0daI013989; Thu, 17 Jan 2013 10:00:39 -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 r0HExc1Z004614 for ; Thu, 17 Jan 2013 09:59:39 -0500 Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.19]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0HExciA024341 for ; Thu, 17 Jan 2013 09:59:38 -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 r0HExblc006096 for ; Thu, 17 Jan 2013 09:59:38 -0500 Received: from relay1.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 CE167A51C9; Thu, 17 Jan 2013 15:59:36 +0100 (CET) From: Hannes Reinecke To: Christophe Varoqui Date: Thu, 17 Jan 2013 15:59:28 +0100 Message-Id: <1358434773-2002-7-git-send-email-hare@suse.de> In-Reply-To: <1358434773-2002-1-git-send-email-hare@suse.de> References: <1358434773-2002-1-git-send-email-hare@suse.de> X-RedHat-Spam-Score: -7.301 (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.19 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 06/11] Break out loop in factorize_hwtable() 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 We need to break out of the loop in factorize_hwtable() as soon as we have removed a duplicate. Otherwise we might run onto an deleted element in the outer loop. Also we should declare factorize_hwtable() as 'void' as it doesn't return anything. Signed-off-by: Hannes Reinecke --- libmultipath/config.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libmultipath/config.c b/libmultipath/config.c index 2d88226..25d3e3d 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -418,12 +418,13 @@ out: return 1; } -static int +static void factorize_hwtable (vector hw, int n) { struct hwentry *hwe1, *hwe2; int i, j; +restart: vector_foreach_slot(hw, hwe1, i) { if (i == n) break; @@ -435,14 +436,17 @@ factorize_hwtable (vector hw, int n) merge_hwe(hwe2, hwe1); if (hwe_strmatch(hwe2, hwe1) == 0) { vector_del_slot(hw, i); - free_hwe(hwe1); - n -= 1; - i -= 1; - break; + /* + * Play safe here; we have modified + * the original vector so the outer + * vector_foreach_slot() might + * become confused. + */ + goto restart; } } } - return 0; + return; } struct config *