From patchwork Thu Mar 17 00:54:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 8606311 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8B7199F6E1 for ; Thu, 17 Mar 2016 00:55:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BDD7120279 for ; Thu, 17 Mar 2016 00:55:08 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E888720268 for ; Thu, 17 Mar 2016 00:55:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 804751A1DF0; Wed, 16 Mar 2016 17:55:27 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ml01.01.org (Postfix) with ESMTP id 251D51A1DF0 for ; Wed, 16 Mar 2016 17:55:26 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 16 Mar 2016 17:55:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,347,1455004800"; d="scan'208";a="912547399" Received: from dwillia2-desk3.jf.intel.com ([10.54.39.14]) by orsmga001.jf.intel.com with ESMTP; 16 Mar 2016 17:55:06 -0700 Subject: [ndctl PATCH 2/5] ndctl: fix blk-ns test cleanup From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 16 Mar 2016 17:54:40 -0700 Message-ID: <20160317005440.3025.71496.stgit@dwillia2-desk3.jf.intel.com> In-Reply-To: <20160317005429.3025.395.stgit@dwillia2-desk3.jf.intel.com> References: <20160317005429.3025.395.stgit@dwillia2-desk3.jf.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ndctl_namespace_foreach_safe() needs to be used when a namespace is deleted while iterating. Otherwise, we can walk off into uninitialized memory and segfault. Reported-by: Ross Zwisler Signed-off-by: Dan Williams --- test/blk_namespaces.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c index 968af2797feb..41c5ce0b1bd7 100644 --- a/test/blk_namespaces.c +++ b/test/blk_namespaces.c @@ -214,7 +214,7 @@ int test_blk_namespaces(int log_level) char bdev[50]; struct ndctl_ctx *ctx; struct ndctl_bus *bus; - struct ndctl_namespace *ndns[2]; + struct ndctl_namespace *ndns[2], *_n; struct ndctl_region *region, *blk_region = NULL; struct ndctl_dimm *dimm; @@ -307,7 +307,7 @@ int test_blk_namespaces(int log_level) err_cleanup: if (blk_region) { - ndctl_namespace_foreach(blk_region, ndns[0]) + ndctl_namespace_foreach_safe(blk_region, ndns[0], _n) if (ndctl_namespace_get_size(ndns[0]) != 0) disable_blk_namespace(ndns[0]); }