Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5752194rwb; Tue, 22 Nov 2022 04:36:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf7gkun+p66WWPIGZ6hXILkELw5JMVo9rufuMboX4VvXxtlcQezRmQp6WX4u0rGAyoR6Jow9 X-Received: by 2002:a17:902:bd83:b0:17d:6603:8e45 with SMTP id q3-20020a170902bd8300b0017d66038e45mr7091126pls.173.1669120579793; Tue, 22 Nov 2022 04:36:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669120579; cv=none; d=google.com; s=arc-20160816; b=ZxnZ3A9AVUqPnPOVzl51ytCzLeDfTx1Moj9Ili283mfIhnsbZhJe+ZOKRLCTCicnS4 alviBjrz8/whQN7n4AQWbuwTqTW+b/mVjP0TIQ90R4Cx11dUlTEXDDcc5EdaBqwnN3kU FhxqM9IEbkUSYjEE5EwCa8sfeMHmfCHAicYSLNVoqlNCudOKB3Lus+08lgiIme0kOI9Q yU8EuB4vp62rKEJOdwA3jHc9tCDaM+xTomPiVUesyTnL8dvVS3RrUHugDrJSbzjMWa1Q Ocv9pxfkjEFBwuYR8e0DvYTSSM9Kpg9Iaz1xXJw3yDVtJg09t0BChXBjoIUNXH46YEtE D8Qg== 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=+ChaAWX/CsdzzDOyopQQhIRUp7nQugAtg3IPIwx9Bko=; b=ne/+i/4mvCww0t6C9oML2Zkx5uIxtqOvbyy5RkFGyWLjcb1isQwKnNipp2Xg4Es4f1 DSjH7m8w9sYarqdQmm7eCQsAiEx+vhoq+IpZSOh7g0jiL5DU8Dua7mUbsVTXGbk6DATh cIjXFTOG6eEl3hpzCvBZG7nMoWKzcUO5O2IsLin/84BNRxzb4cKzak+fxcqi887ffaIO 5BUuaXwVaWDAb3sSferQtDFyzaFtU2D8CwuJAW66PicHxqTAAbSvIRDaIqjkzEccPGss N/4/MhqXxyCLGNlhL5hqjdrMPcEqavPTkET9HVQhwherpVoaG9iRm95TNe51IzepTeoJ ylmg== 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 jb14-20020a170903258e00b0018907d64909si9851190plb.325.2022.11.22.04.36.08; Tue, 22 Nov 2022 04:36:19 -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 S233440AbiKVLnD (ORCPT + 90 others); Tue, 22 Nov 2022 06:43:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232132AbiKVLln (ORCPT ); Tue, 22 Nov 2022 06:41:43 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E878614C for ; Tue, 22 Nov 2022 03:38:56 -0800 (PST) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NGj1r6f3yz15MpM; Tue, 22 Nov 2022 19:38:24 +0800 (CST) Received: from dggpemm500002.china.huawei.com (7.185.36.229) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 22 Nov 2022 19:38:54 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 22 Nov 2022 19:38:53 +0800 From: Xiongfeng Wang To: , CC: , , Subject: [PATCH] watchdog: sp5100_tco: Fix PCI device refcount leak Date: Tue, 22 Nov 2022 19:56:51 +0800 Message-ID: <20221122115651.33877-1-wangxiongfeng2@huawei.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500002.china.huawei.com (7.185.36.229) 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 for_each_pci_dev() is implemented by pci_get_device(). The comment of pci_get_device() says that it will increase the reference count for the returned pci_dev and also decrease the reference count for the input pci_dev @from if it is not NULL. If we break out for_each_pci_dev() loop with pdev not NULL, we need to call pci_dev_put() to decrease the reference count. Add the missing pci_dev_put() in error path of sp5100_tco_init() and also when we unload module. Fixes: 15e28bf13008 ("watchdog: Add support for sp5100 chipset TCO") Signed-off-by: Xiongfeng Wang --- drivers/watchdog/sp5100_tco.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c index fb426b7d81da..f00f26f90444 100644 --- a/drivers/watchdog/sp5100_tco.c +++ b/drivers/watchdog/sp5100_tco.c @@ -599,7 +599,7 @@ static int __init sp5100_tco_init(void) err = platform_driver_register(&sp5100_tco_driver); if (err) - return err; + goto put_dev; sp5100_tco_platform_device = platform_device_register_simple(TCO_DRIVER_NAME, -1, NULL, 0); @@ -612,6 +612,8 @@ static int __init sp5100_tco_init(void) unreg_platform_driver: platform_driver_unregister(&sp5100_tco_driver); +put_dev: + pci_dev_put(sp5100_tco_pci); return err; } @@ -619,6 +621,7 @@ static void __exit sp5100_tco_exit(void) { platform_device_unregister(sp5100_tco_platform_device); platform_driver_unregister(&sp5100_tco_driver); + pci_dev_put(sp5100_tco_pci); } module_init(sp5100_tco_init); -- 2.20.1