From patchwork Tue Nov 22 11:56:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongfeng Wang X-Patchwork-Id: 24320 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2158399wrr; Tue, 22 Nov 2022 04:04:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf4lorbikXMe0SuiHt4VoDq55XIQ8ujJ+DyLChlKK/hDvoIYJbOM4AcvvCMTZGOgGwQEetV2 X-Received: by 2002:a63:e644:0:b0:45f:702a:aec2 with SMTP id p4-20020a63e644000000b0045f702aaec2mr3323125pgj.450.1669118648398; Tue, 22 Nov 2022 04:04:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669118648; cv=none; d=google.com; s=arc-20160816; b=NH9hobnT4pgpnspNha5T4M+bqVCdzzy3imCbVfzc6PIgE2hjX4EqUeYhU6RCTrMi0m NY9gTI6uh3ETidpaIClfhios4W6j6upsnjEmyYjnyX/4ki1eaEyPeUGQpY77//bFuMp/ Tc5JBLxgP6mfqUT08EZb+sMovnrXAEelZZ9+KbgWJXeASevAhhwYldUUGBbMPfEuAb2C CbqWPitYuInbUenBS0eg6XmbJPzkao93Yc/VQ1u23XLd4eNrnOonCbb9kkfYrzXXXXAp 9fvQg1CrOeLD7fdKvRMduyRSupncJLJPMZ5NziTCJbqK7HoXrTicwF79aqoLyKfWUW5T OtTA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a056a00218300b005397c4ad9e1si14845429pfi.134.2022.11.22.04.03.44; Tue, 22 Nov 2022 04:04:08 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750197756055362803?= X-GMAIL-MSGID: =?utf-8?q?1750197756055362803?= 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) 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);