From patchwork Sat Aug 12 19:25:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9897469 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8444C603B4 for ; Sat, 12 Aug 2017 19:31:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 740682892E for ; Sat, 12 Aug 2017 19:31:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68EF0289A6; Sat, 12 Aug 2017 19:31:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 5A9672892E for ; Sat, 12 Aug 2017 19:31:32 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8676B21D4911F; Sat, 12 Aug 2017 12:29:10 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D065D2095DE48 for ; Sat, 12 Aug 2017 12:29:08 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Aug 2017 12:31:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,364,1498546800"; d="scan'208"; a="1162013701" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by orsmga001.jf.intel.com with ESMTP; 12 Aug 2017 12:31:29 -0700 Subject: [ndctl PATCH 1/2] ndctl, util: cleanup filter-by-dimm helpers From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 12 Aug 2017 12:25:06 -0700 Message-ID: <150256590603.13073.16819489053604962816.stgit@dwillia2-desk3.amr.corp.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.22 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-Virus-Scanned: ClamAV using ClamSMTP Use util_dimm_filter() as a helper for these 'filter_by' routines. Signed-off-by: Dan Williams --- util/filter.c | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/util/filter.c b/util/filter.c index 93d56928a3dc..400c11a3a80a 100644 --- a/util/filter.c +++ b/util/filter.c @@ -119,57 +119,28 @@ struct ndctl_dimm *util_dimm_filter(struct ndctl_dimm *dimm, const char *ident) struct ndctl_bus *util_bus_filter_by_dimm(struct ndctl_bus *bus, const char *ident) { - char *end = NULL; - const char *name; struct ndctl_dimm *dimm; - unsigned long dimm_id, id; if (!ident || strcmp(ident, "all") == 0) return bus; - dimm_id = strtoul(ident, &end, 0); - if (end == ident || end[0]) - dimm_id = ULONG_MAX; - - ndctl_dimm_foreach(bus, dimm) { - id = ndctl_dimm_get_id(dimm); - name = ndctl_dimm_get_devname(dimm); - - if (dimm_id < ULONG_MAX && dimm_id == id) + ndctl_dimm_foreach(bus, dimm) + if (util_dimm_filter(dimm, ident)) return bus; - - if (dimm_id == ULONG_MAX && strcmp(ident, name) == 0) - return bus; - } - return NULL; } struct ndctl_region *util_region_filter_by_dimm(struct ndctl_region *region, const char *ident) { - char *end = NULL; - const char *name; struct ndctl_dimm *dimm; - unsigned long dimm_id, id; if (!ident || strcmp(ident, "all") == 0) return region; - dimm_id = strtoul(ident, &end, 0); - if (end == ident || end[0]) - dimm_id = ULONG_MAX; - - ndctl_dimm_foreach_in_region(region, dimm) { - id = ndctl_dimm_get_id(dimm); - name = ndctl_dimm_get_devname(dimm); - - if (dimm_id < ULONG_MAX && dimm_id == id) - return region; - - if (dimm_id == ULONG_MAX && strcmp(ident, name) == 0) + ndctl_dimm_foreach_in_region(region, dimm) + if (util_dimm_filter(dimm, ident)) return region; - } return NULL; }