From patchwork Fri Sep 1 00:29:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9933209 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 3C0696016C for ; Fri, 1 Sep 2017 00:36:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FACE27165 for ; Fri, 1 Sep 2017 00:36:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 243C427853; Fri, 1 Sep 2017 00:36:14 +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 BD56D27165 for ; Fri, 1 Sep 2017 00:36:13 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1FB7F21E49BD9; Thu, 31 Aug 2017 17:33:29 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 53E3020958BED for ; Thu, 31 Aug 2017 17:33:28 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Aug 2017 17:36:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,456,1498546800"; d="scan'208"; a="1213238952" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by fmsmga002.fm.intel.com with ESMTP; 31 Aug 2017 17:36:11 -0700 Subject: [PATCH] ndctl: make ndctl_namspace_set_sector_size() more verbose From: Dan Williams To: linux-nvdimm@lists.01.org Date: Thu, 31 Aug 2017 17:29:47 -0700 Message-ID: <150422578789.8329.15965986648705526561.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 Since we already walk all the supported sector sizes in the success case, move that loop to the start of the routine and use it for logging bad input parameters. Signed-off-by: Dan Williams --- ndctl/lib/libndctl.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index f52ecfe9d142..4361cd8f26c5 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -3549,8 +3549,15 @@ NDCTL_EXPORT int ndctl_namespace_set_sector_size(struct ndctl_namespace *ndns, char sector_str[40]; int i; - if (ndns->lbasize.num == 0) - return -ENXIO; + for (i = 0; i < ndns->lbasize.num; i++) + if (ndns->lbasize.supported[i] == sector_size) + break; + + if (i > ndns->lbasize.num) { + err(ctx, "%s: unsupported sector size %d\n", + ndctl_namespace_get_devname(ndns), sector_size); + return -EOPNOTSUPP; + } if (snprintf(path, len, "%s/sector_size", ndns->ndns_path) >= len) { err(ctx, "%s: buffer too small!\n", @@ -3563,9 +3570,8 @@ NDCTL_EXPORT int ndctl_namespace_set_sector_size(struct ndctl_namespace *ndns, if (rc != 0) return rc; - for (i = 0; i < ndns->lbasize.num; i++) - if (ndns->lbasize.supported[i] == sector_size) - ndns->lbasize.select = i; + ndns->lbasize.select = i; + return 0; }