From nobody Thu Sep 18 17:18:26 2025 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 430B8C4332F for ; Sat, 3 Dec 2022 09:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbiLCJ7L (ORCPT ); Sat, 3 Dec 2022 04:59:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbiLCJ7I (ORCPT ); Sat, 3 Dec 2022 04:59:08 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE1B219001 for ; Sat, 3 Dec 2022 01:59:07 -0800 (PST) Received: from dggpeml500005.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NPQCS03vBzqScY; Sat, 3 Dec 2022 17:55:00 +0800 (CST) Received: from huawei.com (10.175.112.125) by dggpeml500005.china.huawei.com (7.185.36.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 3 Dec 2022 17:59:05 +0800 From: Yongqiang Liu To: , CC: , , , , , , Subject: [PATCH] dax/hmem: Fix refcount leak in dax_hmem_probe() Date: Sat, 3 Dec 2022 09:58:58 +0000 Message-ID: <20221203095858.612027-1-liuyongqiang13@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500005.china.huawei.com (7.185.36.59) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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(). Fixes: c01044cc8191 ("ACPI: HMAT: refactor hmat_register_target_device to h= mem_register_device") Signed-off-by: Yongqiang Liu --- drivers/dax/hmem/hmem.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c index 1bf040dbc834..09f5cd7b6c8e 100644 --- a/drivers/dax/hmem/hmem.c +++ b/drivers/dax/hmem/hmem.c @@ -36,12 +36,11 @@ static int dax_hmem_probe(struct platform_device *pdev) .size =3D region_idle ? 0 : resource_size(res), }; dev_dax =3D devm_create_dev_dax(&data); - if (IS_ERR(dev_dax)) - return PTR_ERR(dev_dax); =20 /* 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; } =20 static int dax_hmem_remove(struct platform_device *pdev) --=20 2.25.1