From: Guenter Roeck <linux@roeck-us.net>
To: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Cc: wim@linux-watchdog.org, linux-kernel@vger.kernel.org,
yangyingliang@huawei.com
Subject: Re: [PATCH] watchdog: sp5100_tco: Fix PCI device refcount leak
Date: Wed, 23 Nov 2022 08:20:16 -0800 [thread overview]
Message-ID: <20221123162016.GB2374110@roeck-us.net> (raw)
In-Reply-To: <20221122115651.33877-1-wangxiongfeng2@huawei.com>
On Tue, Nov 22, 2022 at 07:56:51PM +0800, Xiongfeng Wang wrote:
> 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 <wangxiongfeng2@huawei.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> ---
> 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
>
prev parent reply other threads:[~2022-11-23 16:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-22 11:56 Xiongfeng Wang
2022-11-23 16:20 ` Guenter Roeck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221123162016.GB2374110@roeck-us.net \
--to=linux@roeck-us.net \
--cc=linux-kernel@vger.kernel.org \
--cc=wangxiongfeng2@huawei.com \
--cc=wim@linux-watchdog.org \
--cc=yangyingliang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®