From patchwork Tue Aug 16 17:09:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9284293 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 42CA460839 for ; Tue, 16 Aug 2016 17:13:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32760286C1 for ; Tue, 16 Aug 2016 17:13:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 264DD286C3; Tue, 16 Aug 2016 17:13:22 +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 D0173286C1 for ; Tue, 16 Aug 2016 17:13:21 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B30ED1A1E14; Tue, 16 Aug 2016 10:13:21 -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 DCDCF1A1E14 for ; Tue, 16 Aug 2016 10:13:20 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 16 Aug 2016 10:12:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,529,1464678000"; d="scan'208"; a="1036594405" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.14]) by orsmga002.jf.intel.com with ESMTP; 16 Aug 2016 10:12:07 -0700 Subject: [PATCH 3/4] dax: convert devm_create_dax_dev to PTR_ERR From: Dan Williams To: linux-nvdimm@lists.01.org Date: Tue, 16 Aug 2016 10:09:43 -0700 Message-ID: <147136738382.26813.15989459067594066962.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <147136736786.26813.5042217541564666020.stgit@dwillia2-desk3.amr.corp.intel.com> References: <147136736786.26813.5042217541564666020.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.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP For sub-division support we need access to the dax_dev created by devm_create_dax_dev(). Signed-off-by: Dan Williams --- drivers/dax/dax.c | 16 ++++++++++------ drivers/dax/dax.h | 5 +++-- drivers/dax/pmem.c | 5 +++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/dax/dax.c b/drivers/dax/dax.c index 257cad62bd1d..cbc765c81600 100644 --- a/drivers/dax/dax.c +++ b/drivers/dax/dax.c @@ -644,8 +644,8 @@ static void unregister_dax_dev(void *dev) device_unregister(dev); } -int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res, - int count) +struct dax_dev *devm_create_dax_dev(struct dax_region *dax_region, + struct resource *res, int count) { struct device *parent = dax_region->dev; struct dax_dev *dax_dev; @@ -656,7 +656,7 @@ int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res, dax_dev = kzalloc(sizeof(*dax_dev), GFP_KERNEL); if (!dax_dev) - return -ENOMEM; + return ERR_PTR(-ENOMEM); dax_dev->res = kzalloc(sizeof(res) * count, GFP_KERNEL); if (!dax_dev->res) @@ -736,10 +736,14 @@ int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res, rc = device_add(dev); if (rc) { put_device(dev); - return rc; + return ERR_PTR(rc); } - return devm_add_action_or_reset(dax_region->dev, unregister_dax_dev, dev); + rc = devm_add_action_or_reset(dax_region->dev, unregister_dax_dev, dev); + if (rc) + return ERR_PTR(rc); + + return dax_dev; err_cdev: iput(dax_dev->inode); @@ -757,7 +761,7 @@ int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res, err_res: kfree(dax_dev); - return rc; + return ERR_PTR(rc); } EXPORT_SYMBOL_GPL(devm_create_dax_dev); diff --git a/drivers/dax/dax.h b/drivers/dax/dax.h index d8b8f1f25054..ddd829ab58c0 100644 --- a/drivers/dax/dax.h +++ b/drivers/dax/dax.h @@ -13,12 +13,13 @@ #ifndef __DAX_H__ #define __DAX_H__ struct device; +struct dax_dev; struct resource; struct dax_region; void dax_region_put(struct dax_region *dax_region); struct dax_region *alloc_dax_region(struct device *parent, int region_id, struct resource *res, unsigned int align, void *addr, unsigned long flags); -int devm_create_dax_dev(struct dax_region *dax_region, struct resource *res, - int count); +struct dax_dev *devm_create_dax_dev(struct dax_region *dax_region, + struct resource *res, int count); #endif /* __DAX_H__ */ diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c index 59b75c5972bb..c24d32ec9ce6 100644 --- a/drivers/dax/pmem.c +++ b/drivers/dax/pmem.c @@ -61,6 +61,7 @@ static int dax_pmem_probe(struct device *dev) int rc; void *addr; struct resource res; + struct dax_dev *dax_dev; struct nd_pfn_sb *pfn_sb; struct dax_pmem *dax_pmem; struct nd_region *nd_region; @@ -123,12 +124,12 @@ static int dax_pmem_probe(struct device *dev) return -ENOMEM; /* TODO: support for subdividing a dax region... */ - rc = devm_create_dax_dev(dax_region, &res, 1); + dax_dev = devm_create_dax_dev(dax_region, &res, 1); /* child dax_dev instances now own the lifetime of the dax_region */ dax_region_put(dax_region); - return rc; + return PTR_ERR_OR_ZERO(dax_dev); } static struct nd_device_driver dax_pmem_driver = {