From patchwork Wed Sep 25 18:48:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 11161231 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9DB3713B1 for ; Wed, 25 Sep 2019 18:49:13 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 85B0221D7C for ; Wed, 25 Sep 2019 18:49:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85B0221D7C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E189E202F73BC; Wed, 25 Sep 2019 11:51:25 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=ira.weiny@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 438CD2021EBC7 for ; Wed, 25 Sep 2019 11:51:25 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2019 11:48:54 -0700 X-IronPort-AV: E=Sophos;i="5.64,549,1559545200"; d="scan'208";a="390319159" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.157]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2019 11:48:54 -0700 From: ira.weiny@intel.com To: Dan Williams , Vishal Verma Subject: [PATCH V2] bnvdimm/namsepace: Don't set claim_class on error Date: Wed, 25 Sep 2019 11:48:52 -0700 Message-Id: <20190925184852.11707-1-ira.weiny@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel-janitors@vger.kernel.org, linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" From: Ira Weiny Don't leave claim_class set to an invalid value if an error occurs in btt_claim_class(). While we are here change the return type of __holder_class_store() to be clear about the values it is returning. This was found via code inspection. Reviewed-by: Vishal Verma Signed-off-by: Ira Weiny --- V1->V2 Add space after variable declaration... drivers/nvdimm/namespace_devs.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index 5b22cecefc99..eef885c59f47 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -1510,16 +1510,20 @@ static ssize_t holder_show(struct device *dev, } static DEVICE_ATTR_RO(holder); -static ssize_t __holder_class_store(struct device *dev, const char *buf) +static int __holder_class_store(struct device *dev, const char *buf) { struct nd_namespace_common *ndns = to_ndns(dev); if (dev->driver || ndns->claim) return -EBUSY; - if (sysfs_streq(buf, "btt")) - ndns->claim_class = btt_claim_class(dev); - else if (sysfs_streq(buf, "pfn")) + if (sysfs_streq(buf, "btt")) { + int rc = btt_claim_class(dev); + + if (rc < NVDIMM_CCLASS_NONE) + return rc; + ndns->claim_class = rc; + } else if (sysfs_streq(buf, "pfn")) ndns->claim_class = NVDIMM_CCLASS_PFN; else if (sysfs_streq(buf, "dax")) ndns->claim_class = NVDIMM_CCLASS_DAX; @@ -1528,10 +1532,6 @@ static ssize_t __holder_class_store(struct device *dev, const char *buf) else return -EINVAL; - /* btt_claim_class() could've returned an error */ - if ((int)ndns->claim_class < 0) - return ndns->claim_class; - return 0; } @@ -1539,7 +1539,7 @@ static ssize_t holder_class_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct nd_region *nd_region = to_nd_region(dev->parent); - ssize_t rc; + int rc; nd_device_lock(dev); nvdimm_bus_lock(dev); @@ -1547,7 +1547,7 @@ static ssize_t holder_class_store(struct device *dev, rc = __holder_class_store(dev, buf); if (rc >= 0) rc = nd_namespace_label_update(nd_region, dev); - dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail " : "", rc); + dev_dbg(dev, "%s(%d)\n", rc < 0 ? "fail " : "", rc); nvdimm_bus_unlock(dev); nd_device_unlock(dev);