mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Wentao Liang <vulab@iscas.ac.cn>, gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	mathias.nyman@intel.com, sarah.a.sharp@linux.intel.com,
	stable@vger.kernel.org
Subject: Re: [PATCH] usb: host: Fix companion leak in usb_enable_intel_xhci_ports()
Date: Wed, 30 Sep 2026 16:27:53 +0300	[thread overview]
Message-ID: <57369b29-27ce-432d-aac3-b86c71a08330@linux.intel.com> (raw)
In-Reply-To: <20260916164840.2085101-1-vulab@iscas.ac.cn>

On 9/16/26 19:48, Wentao Liang wrote:
> usb_enable_intel_xhci_ports() iterates over the PCI devices with
> for_each_pci_dev() to check whether an Intel EHCI companion exists and
> breaks out of the loop as soon as one is found. for_each_pci_dev()
> takes a reference on the device returned by pci_get_device(), and
> breaking out of the loop leaves that reference held. The companion
> pointer is only used to set the ehci_found flag and the reference is
> never dropped, leaking a reference to the EHCI companion device on
> every port switch operation.
> 
> Drop the reference with pci_dev_put() once the lookup is done. When no
> companion is found the loop leaves companion set to NULL, for which
> pci_dev_put() is a no-op.
> 
> Fixes: 26b76798e050 ("Intel xhci: refactor EHCI/xHCI port switching")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>   drivers/usb/host/pci-quirks.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
> index 0404489c2f6a..bde5bc248d45 100644
> --- a/drivers/usb/host/pci-quirks.c
> +++ b/drivers/usb/host/pci-quirks.c
> @@ -1076,6 +1076,8 @@ void usb_enable_intel_xhci_ports(struct pci_dev *xhci_pdev)
>   			break;
>   		}
>   	}
> +	/* for_each_pci_dev() takes a reference on the found companion */
> +	pci_dev_put(companion);
>   
>   	if (!ehci_found)
>   		return;

pci_dev_put() should only be called if we break out of the loop, i.e when ehci_found == true.

Moving pci_dev_put() a couple lines lower, after the if (!ehci_found) check should work.

Thanks
Mathias

      reply	other threads:[~2026-09-30 13:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 16:48 Wentao Liang
2026-09-30 13:27 ` Mathias Nyman [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=57369b29-27ce-432d-aac3-b86c71a08330@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=sarah.a.sharp@linux.intel.com \
    --cc=stable@vger.kernel.org \
    --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®