From nobody Wed Apr 15 23:30:24 2026 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 3B09AC4332F for ; Tue, 22 Nov 2022 11:43:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233022AbiKVLnE (ORCPT ); Tue, 22 Nov 2022 06:43:04 -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: quoted-printable 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Guenter Roeck --- 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) =20 err =3D platform_driver_register(&sp5100_tco_driver); if (err) - return err; + goto put_dev; =20 sp5100_tco_platform_device =3D platform_device_register_simple(TCO_DRIVER_NAME, -1, NULL, 0); @@ -612,6 +612,8 @@ static int __init sp5100_tco_init(void) =20 unreg_platform_driver: platform_driver_unregister(&sp5100_tco_driver); +put_dev: + pci_dev_put(sp5100_tco_pci); return err; } =20 @@ -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); } =20 module_init(sp5100_tco_init); --=20 2.20.1