mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shuai Xue <xueshuai@linux.alibaba.com>
To: Yunhui Cui <cuiyunhui@bytedance.com>,
	renyu.zj@linux.alibaba.com, will@kernel.org,
	mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bjorn Helgaas <bhelgaas@google.com>
Subject: Re: [PATCH v2 1/2] perf/dwc_pcie: fix the incorrect reference count
Date: Fri, 7 Feb 2025 10:19:59 +0800	[thread overview]
Message-ID: <76dad20a-0180-46a0-9840-6d8444d1749a@linux.alibaba.com> (raw)
In-Reply-To: <20250205031425.67265-2-cuiyunhui@bytedance.com>



在 2025/2/5 11:14, Yunhui Cui 写道:
> for_each_pci_dev increments pdev refcount. Call pci_dev_put after access
> to decrement it.
> 
> Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
> ---
>   drivers/perf/dwc_pcie_pmu.c | 42 ++++++++++++++++++++++++++-----------
>   1 file changed, 30 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c
> index cccecae9823f..4ac53167d7ab 100644
> --- a/drivers/perf/dwc_pcie_pmu.c
> +++ b/drivers/perf/dwc_pcie_pmu.c
> @@ -553,6 +553,7 @@ static u16 dwc_pcie_des_cap(struct pci_dev *pdev)
>   
>   static void dwc_pcie_unregister_dev(struct dwc_pcie_dev_info *dev_info)
>   {
> +	pci_dev_put(dev_info->pdev);
>   	platform_device_unregister(dev_info->plat_dev);
>   	list_del(&dev_info->dev_node);
>   	kfree(dev_info);
> @@ -572,8 +573,10 @@ static int dwc_pcie_register_dev(struct pci_dev *pdev)
>   		return PTR_ERR(plat_dev);
>   
>   	dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
> -	if (!dev_info)
> +	if (!dev_info) {
> +		platform_device_unregister(plat_dev);
>   		return -ENOMEM;
> +	}
>   
>   	/* Cache platform device to handle pci device hotplug */
>   	dev_info->plat_dev = plat_dev;
> @@ -594,8 +597,11 @@ static int dwc_pcie_pmu_notifier(struct notifier_block *nb,
>   	case BUS_NOTIFY_ADD_DEVICE:
>   		if (!dwc_pcie_des_cap(pdev))
>   			return NOTIFY_DONE;
> -		if (dwc_pcie_register_dev(pdev))
> +		pci_dev_get(pdev);
> +		if (dwc_pcie_register_dev(pdev)) {
> +			pci_dev_put(pdev);
>   			return NOTIFY_BAD;
> +		}
>   		break;
>   	case BUS_NOTIFY_DEL_DEVICE:
>   		dev_info = dwc_pcie_find_dev_info(pdev);
> @@ -730,20 +736,29 @@ static struct platform_driver dwc_pcie_pmu_driver = {
>   	.driver = {.name = "dwc_pcie_pmu",},
>   };
>   
> +static void dwc_pcie_cleanup_devices(void)
> +{
> +	struct dwc_pcie_dev_info *dev_info, *tmp;
> +
> +	list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node) {
> +		dwc_pcie_unregister_dev(dev_info);
> +	}
> +}
> +
>   static int __init dwc_pcie_pmu_init(void)
>   {
>   	struct pci_dev *pdev = NULL;
>   	int ret;
>   
>   	for_each_pci_dev(pdev) {
> -		if (!dwc_pcie_des_cap(pdev))
> +		if (!dwc_pcie_des_cap(pdev)) {
> +			pci_dev_put(pdev);

If the pdev has no RAS cap, we do not need to put the device.

> The reference count for @from is
> always decremented if it is not %NULL.

Please see comments from pci_get_device() for more details.

Shuai


  reply	other threads:[~2025-02-07  2:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-05  3:14 [PATCH v2 0/2] Fix dwc_pcie pmu driver issues Yunhui Cui
2025-02-05  3:14 ` [PATCH v2 1/2] perf/dwc_pcie: fix the incorrect reference count Yunhui Cui
2025-02-07  2:19   ` Shuai Xue [this message]
2025-02-08  2:57     ` [External] " yunhui cui
2025-02-05  3:14 ` [PATCH v2 2/2] perf/dwc_pcie: fix duplicate pci_dev devices Yunhui Cui
2025-02-07  2:35   ` Shuai Xue
2025-02-08  2:59     ` [External] " yunhui cui

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=76dad20a-0180-46a0-9840-6d8444d1749a@linux.alibaba.com \
    --to=xueshuai@linux.alibaba.com \
    --cc=bhelgaas@google.com \
    --cc=cuiyunhui@bytedance.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=renyu.zj@linux.alibaba.com \
    --cc=will@kernel.org \
    /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®