From patchwork Sat Dec 3 09:58:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongqiang Liu X-Patchwork-Id: 29253 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1297586wrr; Sat, 3 Dec 2022 02:17:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf5AlYLpZxWVHNKsIEcASJ+yMUr8CHcdXyof1bDrRsp9a1DP2TC4ROJ46vlVOYAmw1Y3Pl4d X-Received: by 2002:a17:90b:2686:b0:218:bb0a:e295 with SMTP id pl6-20020a17090b268600b00218bb0ae295mr63411432pjb.80.1670062638898; Sat, 03 Dec 2022 02:17:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670062638; cv=none; d=google.com; s=arc-20160816; b=niBmklhut4fvEG4Gf7yfj3foQ4bNoqRjo99bf5n7AJVOZLzxyc6s4W1WpDpoWbBGaM wrc8lZNcG77JDY8PRlyxBMaq4L1e5/ISQnZf+lue2KRrHH/EFqkeJF/EoKNblYkrgF5Q J90Ds1PTyag0I6ML2lUfvce55DenRDla19tkYAYxHntAfoUG8mcmb8IyzXGyKWjgFssK WBxaURO9aNOVUBgHBVOh60AFirVUayBdFc333FhJECAyfH8LGp+b0jhbHXvSa8fQWV9v 9+3jS9aptIjN0cqR9rzYkiXx+DC/V/1isnskRTRdaiTVg6RqUT60SWInUOq7Ex/eB+x6 yXJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=oFg00KuOTSwhDW7kJBE1uIGg27+gjxsFj7JlkN/0YA0=; b=lK5jqb6h1mmSPcVGmGhMaNn9ueMYgf256yXQW/KNELDz4ojZrQ4r/iu8PGkDSlBb6s 6Q8nm+NvUk6QmgPbNqPms2FpluSWB/IGGc+CWCYzYjW4ygSwEj7DBfD3RrQ+bISyTLxh yGjL5z6uhqYeEXUBrGc/igI+oBwmTwoDIE7Dl2xEeuTDwn/+UkkG27z4E0YU+c9dQCL8 nzbTqlTnGImgEYzAwVDYOU/JgDXEnIgNDMGRb/Bb8xSJ1f4tfiQNmO3TD0U4YHTs15h0 qGBLzXYXQQ4gIHrvhNiRD1a0VMMeZcz8v5ujt6yHVTM80Sl84oBZaLF6CIXyAOIkvzJF pQWw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c8-20020a17090aa60800b00213120e0c85si11875726pjq.156.2022.12.03.02.17.05; Sat, 03 Dec 2022 02:17:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229606AbiLCJ7L (ORCPT + 99 others); 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 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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751187601713395365?= X-GMAIL-MSGID: =?utf-8?q?1751187601713395365?= 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 hmem_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 = region_idle ? 0 : resource_size(res), }; 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 int dax_hmem_remove(struct platform_device *pdev)