From patchwork Sat Jun 3 02:09:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 13265998 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1B41C77B7A for ; Sat, 3 Jun 2023 02:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229802AbjFCCJc (ORCPT ); Fri, 2 Jun 2023 22:09:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236889AbjFCCJb (ORCPT ); Fri, 2 Jun 2023 22:09:31 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4561E4D; Fri, 2 Jun 2023 19:09:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685758170; x=1717294170; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=+pAIGJKvRh7qS+esVik2IqS8poW9McX9jF5Ma8+7Pj8=; b=lqTinRtQ8ULE/4OTkxE070wSlpolX5BGls5WXUaysCuKp5AiKdYMm9gH STxV/jipZA8o8Yv//1k/VdLVkVf0kMUBtRC756VrNc9F08l52gsL9rbb6 1Iq4fHeoR2vIHHnbMK1fjD3iF0liRJM7casYUx/MayejAySnpHSYU1e+p h4Gy5ktzcVARJ2WK9+4Dw6s3G8YyI4Txt+pXxEpWbp1nFyvcs3OfvDULk ADl6R/ptNsT9S0C6O6+vuA+H8UmKvq5nq6F4QvvgIhiwGyvoeZJjBWUK3 5CYNPyoveJKusDamtY0GApOMlkNoKqHRAnUrTetppWLg8h3DWCZUbpaGm w==; X-IronPort-AV: E=McAfee;i="6600,9927,10729"; a="340649435" X-IronPort-AV: E=Sophos;i="6.00,214,1681196400"; d="scan'208";a="340649435" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 19:09:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10729"; a="852354411" X-IronPort-AV: E=Sophos;i="6.00,214,1681196400"; d="scan'208";a="852354411" Received: from iweiny-mobl.amr.corp.intel.com (HELO localhost) ([10.212.97.230]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 19:09:29 -0700 From: Ira Weiny Date: Fri, 02 Jun 2023 19:09:21 -0700 Subject: [PATCH RFC 1/4] dax/bus: Fix leaked reference in alloc_dax_region() MIME-Version: 1.0 Message-Id: <20230602-dax-region-put-v1-1-d8668f335d45@intel.com> References: <20230602-dax-region-put-v1-0-d8668f335d45@intel.com> In-Reply-To: <20230602-dax-region-put-v1-0-d8668f335d45@intel.com> To: Dan Williams , Vishal Verma , Dave Jiang , Andrew Morton , Joao Martins , Jonathan Cameron Cc: Yongqiang Liu , Paul Cassella , linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Ira Weiny X-Mailer: b4 0.13-dev-9a8cd X-Developer-Signature: v=1; a=ed25519-sha256; t=1685758165; l=1545; i=ira.weiny@intel.com; s=20221211; h=from:subject:message-id; bh=+pAIGJKvRh7qS+esVik2IqS8poW9McX9jF5Ma8+7Pj8=; b=23++xNTRjcMP4T5vDFqSFZUyo1YkZSoemfUGTjIUMhcqbFSXmYr5cAd6MW2Wr6cszXEqh1tkf NkYUKeFaToRARLPp8vO6Zk8hwWlXeXg+vJ7nCwlHcCYJKPsUiD/qPNW X-Developer-Key: i=ira.weiny@intel.com; a=ed25519; pk=noldbkG+Wp1qXRrrkfY1QJpDf7QsOEthbOT7vm0PqsE= Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org kref_init() initializes the ref count to 1. An extra kref is taken on the dax_region to be used by the caller. If devm_add_action_or_reset() fails this extra reference is leaked. Drop the extra reference on error. Fixes: d7fe1a67f658 ("dax: add region 'id', 'size', and 'align' attributes") Cc: Dan Williams Signed-off-by: Ira Weiny --- drivers/dax/bus.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 227800053309..899e29d107b4 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -583,6 +583,7 @@ static void dax_region_unregister(void *region) dax_region_put(dax_region); } +/* The dax_region reference returned should be dropped with dax_region_put() */ struct dax_region *alloc_dax_region(struct device *parent, int region_id, struct range *range, int target_node, unsigned int align, unsigned long flags) @@ -625,9 +626,13 @@ struct dax_region *alloc_dax_region(struct device *parent, int region_id, return NULL; } + /* Hold a reference to return to the caller */ kref_get(&dax_region->kref); - if (devm_add_action_or_reset(parent, dax_region_unregister, dax_region)) + if (devm_add_action_or_reset(parent, dax_region_unregister, + dax_region)) { + kref_put(&dax_region->kref, dax_region_free); return NULL; + } return dax_region; } EXPORT_SYMBOL_GPL(alloc_dax_region); From patchwork Sat Jun 3 02:09:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 13265999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FAE4C7EE2A for ; Sat, 3 Jun 2023 02:09:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237152AbjFCCJm (ORCPT ); Fri, 2 Jun 2023 22:09:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237110AbjFCCJe (ORCPT ); Fri, 2 Jun 2023 22:09:34 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3657BE4D; Fri, 2 Jun 2023 19:09:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685758173; x=1717294173; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=cuZ67ek2FPqXnrXVq3JWOFTKzohvfRqyJT4xFD/V2X8=; b=MuNXJEWaWSV8P5vCtckTBHJ+RBXmXGYaZ04kGI9d+rvTJW1ldxgN7pLZ atV/An42IQvDA3r4jESEory3Hg76kVRoJpjy1zyrT7ykFW+Se7LTJdh6R dztzbuCWpIZfAY4gTUReu3NaaSetRLU2uVMZPwSjCyg1HZxkD52Nls1YB 0NACcnMBAuMXsBXWYqR7bDE3qP2FJKVVdQGuxuoqSuonnVdRgMM6KJ/NC +/hgMjz5y6R7IvEyHEHNY8l/FXgbhiq5x1+edsfws+2htu1LjV4qqbTJE FbzeBJMYWF/NQrneyvZYjzeyw8ECV49puJHMRtoMppk+qshcAetP4Q7Vo g==; X-IronPort-AV: E=McAfee;i="6600,9927,10729"; a="340649443" X-IronPort-AV: E=Sophos;i="6.00,214,1681196400"; d="scan'208";a="340649443" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 19:09:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10729"; a="852354415" X-IronPort-AV: E=Sophos;i="6.00,214,1681196400"; d="scan'208";a="852354415" Received: from iweiny-mobl.amr.corp.intel.com (HELO localhost) ([10.212.97.230]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 19:09:31 -0700 From: ira.weiny@intel.com Date: Fri, 02 Jun 2023 19:09:22 -0700 Subject: [PATCH RFC 2/4] dax/hmem: Fix refcount leak in dax_hmem_probe() MIME-Version: 1.0 Message-Id: <20230602-dax-region-put-v1-2-d8668f335d45@intel.com> References: <20230602-dax-region-put-v1-0-d8668f335d45@intel.com> In-Reply-To: <20230602-dax-region-put-v1-0-d8668f335d45@intel.com> To: Dan Williams , Vishal Verma , Dave Jiang , Andrew Morton , Joao Martins , Jonathan Cameron Cc: Yongqiang Liu , Paul Cassella , linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Ira Weiny X-Mailer: b4 0.13-dev-9a8cd X-Developer-Signature: v=1; a=ed25519-sha256; t=1685758165; l=1143; i=ira.weiny@intel.com; s=20221211; h=from:subject:message-id; bh=DCqwnNEGFbx08b+rkmwCRZ6p+PTcrb6DH1GrUdGBQJw=; b=73GEgZX9DU492Absc9d47SZD0IZXPG6TVtym9JbpPpRp8e8AKDyh40CCLSstWwAR9weXLPqDe K4ncPMKuN7SChr2G5H3jltokrfSfIaJsppaVjuzBFdzMU06Pf7YkWTb X-Developer-Key: i=ira.weiny@intel.com; a=ed25519; pk=noldbkG+Wp1qXRrrkfY1QJpDf7QsOEthbOT7vm0PqsE= Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Yongqiang Liu We should always call dax_region_put() whenever devm_create_dev_dax() succeed or fail to avoid refcount leak of dax_region. Move the return value check after dax_region_put(). Cc: nvdimm@lists.linux.dev Fixes: c01044cc8191 ("ACPI: HMAT: refactor hmat_register_target_device to hmem_register_device") Reviewed-by: Ira Weiny Signed-off-by: Yongqiang Liu --- drivers/dax/hmem/hmem.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c index e5fe8b39fb94..b4831a3d3934 100644 --- a/drivers/dax/hmem/hmem.c +++ b/drivers/dax/hmem/hmem.c @@ -39,12 +39,10 @@ static int dax_hmem_probe(struct platform_device *pdev) .size = region_idle ? 0 : range_len(&mri->range), }; dev_dax = devm_create_dev_dax(&data); - if (IS_ERR(dev_dax)) - return PTR_ERR(dev_dax); /* child dev_dax instances now own the lifetime of the dax_region */ dax_region_put(dax_region); - return 0; + return IS_ERR(dev_dax) ? PTR_ERR(dev_dax) : 0; } static struct platform_driver dax_hmem_driver = { From patchwork Sat Jun 3 02:09:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 13266000 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8087C77B7A for ; Sat, 3 Jun 2023 02:09:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236970AbjFCCJo (ORCPT ); Fri, 2 Jun 2023 22:09:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237128AbjFCCJl (ORCPT ); Fri, 2 Jun 2023 22:09:41 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB5FBE54; Fri, 2 Jun 2023 19:09:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685758175; x=1717294175; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=5MB3BKWckl+By6dAOaDRIYtbC3hmRt8XrTwn1/3TCYE=; b=XIcEUnKhE9G9wr3c+mHq2Xp/EXSWXH4RBAR3laSKxIm4scmEdfzWng4u e+cJ1+sGt6p8JIs2YRM3A7Acu5vMD/sTuC0hlZY9RS5DakHpG4MDKYP1G w0x+FZXltoe2oIStt0eMLlB8KhqWaLU7pE5WKDiterZBPvBJaoA94tTGv MqIVnT0acRlmDWWuK8hmHbY9RCNG928D+7BeuvzWMbsr3lu4lXPbqf/sL AfW7QagmtdbxUqfyomIh394kmyOFIklzf1dsLhg0mT/swpbQMtV7Mg+Lw zm8Xz8NsxHb5uPh9hJefHIye8AAb+JNL5KdRk16SOgtAGWS4dDTQMm8sD g==; X-IronPort-AV: E=McAfee;i="6600,9927,10729"; a="340649449" X-IronPort-AV: E=Sophos;i="6.00,214,1681196400"; d="scan'208";a="340649449" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 19:09:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10729"; a="852354418" X-IronPort-AV: E=Sophos;i="6.00,214,1681196400"; d="scan'208";a="852354418" Received: from iweiny-mobl.amr.corp.intel.com (HELO localhost) ([10.212.97.230]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 19:09:33 -0700 From: Ira Weiny Date: Fri, 02 Jun 2023 19:09:23 -0700 Subject: [PATCH RFC 3/4] dax/cxl: Fix refcount leak in cxl_dax_region_probe() MIME-Version: 1.0 Message-Id: <20230602-dax-region-put-v1-3-d8668f335d45@intel.com> References: <20230602-dax-region-put-v1-0-d8668f335d45@intel.com> In-Reply-To: <20230602-dax-region-put-v1-0-d8668f335d45@intel.com> To: Dan Williams , Vishal Verma , Dave Jiang , Andrew Morton , Joao Martins , Jonathan Cameron Cc: Yongqiang Liu , Paul Cassella , linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Ira Weiny X-Mailer: b4 0.13-dev-9a8cd X-Developer-Signature: v=1; a=ed25519-sha256; t=1685758165; l=1320; i=ira.weiny@intel.com; s=20221211; h=from:subject:message-id; bh=5MB3BKWckl+By6dAOaDRIYtbC3hmRt8XrTwn1/3TCYE=; b=k5/U4wkR3Cb4EoT4bw2Hlb0zJYm/GlDWxKX1NPtJA+QIb7WIyxP9oweVP1LvxCBhDYX9UpvRE lYDzxPnnzypCpx7kifOzdjSQ9VerVqMdNuihxC1zPm9rKcO0zeMM94U X-Developer-Key: i=ira.weiny@intel.com; a=ed25519; pk=noldbkG+Wp1qXRrrkfY1QJpDf7QsOEthbOT7vm0PqsE= Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org alloc_dax_region() returns a reference protected dax_region. Regardless of the success of the devm_create_dev_dax() the reference returned from alloc_dax_region() needs to be released. Drop the dax_region reference regardless of the success of dev_dax creation. Clean up comments. Fixes: 09d09e04d2fc ("cxl/dax: Create dax devices for CXL RAM regions") Cc: Dan Williams Cc: linux-cxl@vger.kernel.org Signed-off-by: Ira Weiny --- This work was inspired by Yongqiang Liu here: https://lore.kernel.org/all/20221203095858.612027-1-liuyongqiang13@huawei.com/ --- drivers/dax/cxl.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/dax/cxl.c b/drivers/dax/cxl.c index ccdf8de85bd5..bbfe71cf4325 100644 --- a/drivers/dax/cxl.c +++ b/drivers/dax/cxl.c @@ -29,12 +29,11 @@ static int cxl_dax_region_probe(struct device *dev) .size = range_len(&cxlr_dax->hpa_range), }; dev_dax = devm_create_dev_dax(&data); - if (IS_ERR(dev_dax)) - return PTR_ERR(dev_dax); /* child dev_dax instances now own the lifetime of the dax_region */ dax_region_put(dax_region); - return 0; + + return IS_ERR(dev_dax) ? PTR_ERR(dev_dax) : 0; } static struct cxl_driver cxl_dax_region_driver = { From patchwork Sat Jun 3 02:09:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 13266001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40F2EC7EE2A for ; Sat, 3 Jun 2023 02:09:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237158AbjFCCJp (ORCPT ); Fri, 2 Jun 2023 22:09:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237164AbjFCCJn (ORCPT ); Fri, 2 Jun 2023 22:09:43 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F734E63; Fri, 2 Jun 2023 19:09:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685758178; x=1717294178; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=0hJMjkHkP89rfwhPu6kPTDLYbVJWhkUm9t7eLmXGvlc=; b=gTnsQsfrDhHK+u61fuRVfWkt7DSFABgpPsCiZbjOfuyrAT5uWfZXjUBs 57xEMK/UoDKjzT1M0pWR65IJwvYJzmwEX+5aSR46CbW64cdiNxZCDXz5u Ea0RZUw+kXC8mso7phyxEPRJ4sfJo89ztaUgM2E8kEodnJXua9+rkT9uG J6YAx/RZDyTRN7AWdjkt4yZlvOTbuQdPiun/XxE+9slL4ZujuV3DCg4UG 3ZJaeAEfDpV0NZatN6gZSRxpjdMTCrJxOMAcwdsPT6hMn31EB4Qxm0wUS KyLuD1U5nlB1tmDl1yhJXkOEs/43CZ5DJ723wychtKwWy5WlT7YsZzsmy w==; X-IronPort-AV: E=McAfee;i="6600,9927,10729"; a="340649457" X-IronPort-AV: E=Sophos;i="6.00,214,1681196400"; d="scan'208";a="340649457" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 19:09:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10729"; a="852354422" X-IronPort-AV: E=Sophos;i="6.00,214,1681196400"; d="scan'208";a="852354422" Received: from iweiny-mobl.amr.corp.intel.com (HELO localhost) ([10.212.97.230]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 19:09:36 -0700 From: Ira Weiny Date: Fri, 02 Jun 2023 19:09:24 -0700 Subject: [PATCH RFC 4/4] dax/bus: Remove unnecessary reference in alloc_dax_region() MIME-Version: 1.0 Message-Id: <20230602-dax-region-put-v1-4-d8668f335d45@intel.com> References: <20230602-dax-region-put-v1-0-d8668f335d45@intel.com> In-Reply-To: <20230602-dax-region-put-v1-0-d8668f335d45@intel.com> To: Dan Williams , Vishal Verma , Dave Jiang , Andrew Morton , Joao Martins , Jonathan Cameron Cc: Yongqiang Liu , Paul Cassella , linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Ira Weiny X-Mailer: b4 0.13-dev-9a8cd X-Developer-Signature: v=1; a=ed25519-sha256; t=1685758165; l=3727; i=ira.weiny@intel.com; s=20221211; h=from:subject:message-id; bh=0hJMjkHkP89rfwhPu6kPTDLYbVJWhkUm9t7eLmXGvlc=; b=h+bWgJ3qSIdj/EAGT1xs+38BAs20p/pFFmvnjS5xGpX1ZfEYrwqiL/b98IYQKtcO0Pyp94reN TH2URAb3gZBAYVKG0d2P5cvNhWCAN5Z7GnIaqBSgYazRlbKWajzaBFp X-Developer-Key: i=ira.weiny@intel.com; a=ed25519; pk=noldbkG+Wp1qXRrrkfY1QJpDf7QsOEthbOT7vm0PqsE= Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org All the callers to alloc_dax_region() maintain the device associated with the dax_region until the dax_region is referenced by the dax_dev they are creating. Remove the extra kref that alloc_dax_region() takes. Add a comment to clarify the reference counting should additional callers be grown later. Cc: Yongqiang Liu Cc: Dan Williams Cc: Paul Cassella Signed-off-by: Ira Weiny --- drivers/dax/bus.c | 13 ++++++------- drivers/dax/cxl.c | 4 ---- drivers/dax/hmem/hmem.c | 3 --- drivers/dax/pmem.c | 8 +------- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 899e29d107b4..ed34d8aa6b26 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -583,7 +583,11 @@ static void dax_region_unregister(void *region) dax_region_put(dax_region); } -/* The dax_region reference returned should be dropped with dax_region_put() */ +/* + * Caller is responsible to ensure the parent device stays live while the + * returned dax_region is in use. Or as is typically the case, a separate + * reference should be taken. + */ struct dax_region *alloc_dax_region(struct device *parent, int region_id, struct range *range, int target_node, unsigned int align, unsigned long flags) @@ -626,13 +630,8 @@ struct dax_region *alloc_dax_region(struct device *parent, int region_id, return NULL; } - /* Hold a reference to return to the caller */ - kref_get(&dax_region->kref); - if (devm_add_action_or_reset(parent, dax_region_unregister, - dax_region)) { - kref_put(&dax_region->kref, dax_region_free); + if (devm_add_action_or_reset(parent, dax_region_unregister, dax_region)) return NULL; - } return dax_region; } EXPORT_SYMBOL_GPL(alloc_dax_region); diff --git a/drivers/dax/cxl.c b/drivers/dax/cxl.c index bbfe71cf4325..5ad600ee68b3 100644 --- a/drivers/dax/cxl.c +++ b/drivers/dax/cxl.c @@ -29,10 +29,6 @@ static int cxl_dax_region_probe(struct device *dev) .size = range_len(&cxlr_dax->hpa_range), }; dev_dax = devm_create_dev_dax(&data); - - /* child dev_dax instances now own the lifetime of the dax_region */ - dax_region_put(dax_region); - return IS_ERR(dev_dax) ? PTR_ERR(dev_dax) : 0; } diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c index b4831a3d3934..46e1b343f26e 100644 --- a/drivers/dax/hmem/hmem.c +++ b/drivers/dax/hmem/hmem.c @@ -39,9 +39,6 @@ static int dax_hmem_probe(struct platform_device *pdev) .size = region_idle ? 0 : range_len(&mri->range), }; dev_dax = devm_create_dev_dax(&data); - - /* child dev_dax instances now own the lifetime of the dax_region */ - dax_region_put(dax_region); return IS_ERR(dev_dax) ? PTR_ERR(dev_dax) : 0; } diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c index f050ea78bb83..a4f016d7f4f5 100644 --- a/drivers/dax/pmem.c +++ b/drivers/dax/pmem.c @@ -13,7 +13,6 @@ static struct dev_dax *__dax_pmem_probe(struct device *dev) int rc, id, region_id; resource_size_t offset; struct nd_pfn_sb *pfn_sb; - struct dev_dax *dev_dax; struct dev_dax_data data; struct nd_namespace_io *nsio; struct dax_region *dax_region; @@ -65,12 +64,7 @@ static struct dev_dax *__dax_pmem_probe(struct device *dev) .pgmap = &pgmap, .size = range_len(&range), }; - dev_dax = devm_create_dev_dax(&data); - - /* child dev_dax instances now own the lifetime of the dax_region */ - dax_region_put(dax_region); - - return dev_dax; + return devm_create_dev_dax(&data); } static int dax_pmem_probe(struct device *dev)