mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Wentao Liang <vulab@iscas.ac.cn>, a-verma1@ti.com
Cc: bhelgaas@google.com, kwilczynski@kernel.org,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	lpieralisi@kernel.org, mani@kernel.org, robh@kernel.org,
	s-vadapalli@ti.com, vigneshr@ti.com, stable@vger.kernel.org, "Li,
	Hua Qian (DI FA CTR IPC CN PRC4)" <huaqian.li@siemens.com>
Subject: Re: [PATCH] PCI: keystone: Fix host bridge device leak in ks_pcie_quirk()
Date: Fri, 18 Sep 2026 07:00:07 +0200	[thread overview]
Message-ID: <6a47a43f-6844-49c7-bdd5-cd84f63d38d7@siemens.com> (raw)
In-Reply-To: <20260917132022.2153069-1-vulab@iscas.ac.cn>

On 17.09.26 15:20, Wentao Liang wrote:
> ks_pcie_quirk() obtains a reference to the host bridge device with
> pci_get_host_bridge_device() but never releases it.  Every early exit
> from the AM654 PG1.0 workaround leaks the reference: when the bridge
> device or its parent is missing, when the parent has no driver data,
> and when the RTL revision is not AM6_PCI_PG1_RTL_VER.  The quirk runs
> for every downstream PCI device, so the reference count grows without
> bound.
> 
> Add a common out label that drops the reference with
> pci_put_host_bridge_device() before returning.
> 
> Fixes: 86f271f22bbb ("PCI: keystone: Add workaround for Errata #i2037 (AM65x SR 1.0)")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  drivers/pci/controller/dwc/pci-keystone.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c
> index 278d2dba1db0..cc6739edd434 100644
> --- a/drivers/pci/controller/dwc/pci-keystone.c
> +++ b/drivers/pci/controller/dwc/pci-keystone.c
> @@ -528,7 +528,7 @@ static void ks_pcie_quirk(struct pci_dev *dev)
>  {
>  	struct pci_bus *bus = dev->bus;
>  	struct keystone_pcie *ks_pcie;
> -	struct device *bridge_dev;
> +	struct device *bridge_dev = NULL;
>  	struct pci_dev *bridge;
>  	u32 val;
>  
> @@ -582,23 +582,27 @@ static void ks_pcie_quirk(struct pci_dev *dev)
>  	if (pci_match_id(am6_pci_devids, bridge)) {
>  		bridge_dev = pci_get_host_bridge_device(dev);
>  		if (!bridge_dev || !bridge_dev->parent)
> -			return;
> +			goto out;
>  
>  		ks_pcie = dev_get_drvdata(bridge_dev->parent);
>  		if (!ks_pcie)
> -			return;
> +			goto out;
>  
>  		val = ks_pcie_app_readl(ks_pcie, PID);
>  		val &= RTL;
>  		val >>= RTL_SHIFT;
>  		if (val != AM6_PCI_PG1_RTL_VER)
> -			return;
> +			goto out;
>  
>  		if (pcie_get_readrq(dev) > 128) {
>  			dev_info(&dev->dev, "limiting MRRS to 128 bytes\n");
>  			pcie_set_readrq(dev, 128);
>  		}
>  	}
> +
> +out:
> +	if (bridge_dev)
> +		pci_put_host_bridge_device(bridge_dev);

I would pull this under the scope of pci_match_id.

>  }
>  DECLARE_PCI_FIXUP_ENABLE(PCI_ANY_ID, PCI_ANY_ID, ks_pcie_quirk);
>  

Good catch, even more as it does not only affect the legacy silicon. But
I guess the leaking normally ends when all devices were probed and
enabled, and no one has a desire to unbind/rebind them.

Jan

-- 
Siemens AG, Foundational Technologies
Linux Expert Center

      reply	other threads:[~2026-09-18  5:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 13:20 Wentao Liang
2026-09-18  5:00 ` Jan Kiszka [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=6a47a43f-6844-49c7-bdd5-cd84f63d38d7@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=a-verma1@ti.com \
    --cc=bhelgaas@google.com \
    --cc=huaqian.li@siemens.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=robh@kernel.org \
    --cc=s-vadapalli@ti.com \
    --cc=stable@vger.kernel.org \
    --cc=vigneshr@ti.com \
    --cc=vulab@iscas.ac.cn \
    /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®