Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3292973rwb; Sat, 3 Dec 2022 02:27:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf6GRA5AwTtaqw6kQ8jgFMdOHexF99CWAOy/NeGBY0amENW+/bSwnRrjo/PSc/sgStEvpBK4 X-Received: by 2002:a63:cd09:0:b0:476:d44d:355 with SMTP id i9-20020a63cd09000000b00476d44d0355mr48301521pgg.289.1670063220707; Sat, 03 Dec 2022 02:27:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670063220; cv=none; d=google.com; s=arc-20160816; b=OxDItqKaKY8bE0wf/QHW2GZ24+CILKbsXCKD9h1EV9SpubufkEKHjmBDpxDNsKiRHu Y9erRgm1GakOFCNCaxJHOow3CZiAstepYfnwxbP3jqfAPBwSDVzNw0gsT6OtHPKwaOhp GiT68dqnj3dCi13/nUZ3TJPrBpJDHIpfd4H/DhS+RelxtqTI5HAS+/bHGWnOdgmiiEfo iXQqnEnORg9cuNDjbitS8TvGGyiqS8Bu4Yb+K5BNHIr75lBytsXcU92HkM2kumQvMDyK XOmQEbijG9JCaP6GfpfSHpUXZ/hcRgCynVcUU5R/FnhBkjCW25JtOczDpjF7R3x5GMmN UOFg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a635645000000b0046e96b9ecfdsi9341201pgm.801.2022.12.03.02.26.50; Sat, 03 Dec 2022 02:27:00 -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 + 82 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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) -- 2.25.1