mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Lazar, Lijo" <lijo.lazar@amd.com>
To: Ma Ke <make24@iscas.ac.cn>,
	alexander.deucher@amd.com, christian.koenig@amd.com,
	airlied@gmail.com, simona@ffwll.ch, evan.quan@amd.com
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] drm/amdgpu: Fix error handling in amdgpu_atpx_detect
Date: Fri, 21 Nov 2025 12:23:12 +0530	[thread overview]
Message-ID: <5f614997-41a5-432f-ab3c-ea1011c16dc4@amd.com> (raw)
In-Reply-To: <20251121014415.37964-1-make24@iscas.ac.cn>



On 11/21/2025 7:14 AM, Ma Ke wrote:
> amdgpu_atpx_detect() uses pci_get_class() in two while loops to
> iterate through VGA and OTHER display class PCI devices. Each call to
> pci_get_class() increments the reference count of the returned PCI
> device. However, after the loops complete, there are no corresponding
> pci_dev_put() to decrement these reference counts.
> 
> Add pci_dev_put() after each while loop to release reference counts
> held by the last devices found in each class.
> 
> Found by code review.

This doesn't look correct. Below is the documented API behaviour.

"Iterates through the list of known PCI devices. If a PCI device is 
found with a matching class, the reference count to the device is 
incremented and a pointer to its device structure is returned. 
Otherwise, NULL is returned. A new search is initiated by passing NULL 
as the from argument. Otherwise if from is not NULL, searches continue 
from next device on the global list. The reference count for from is 
always decremented if it is not NULL."


After a device is found, it goes in as the "from" device for the next 
iteration. Then reference count of the from device is decremented. Both 
the loops continue till pdev gets to NULL. So there is nothing to put() 
after the loops are completed.

Thanks,
Lijo

> 
> Cc: stable@vger.kernel.org
> Fixes: 5d30ed3c2c74 ("Revert "drm/amdgpu: simplify ATPX detection"")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
> index 3893e6fc2f03..9eb776a2e8bb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
> @@ -617,6 +617,9 @@ static bool amdgpu_atpx_detect(void)
>   		amdgpu_atpx_get_quirks(pdev);
>   	}
>   
> +	pci_dev_put(pdev);
> +	pdev = NULL;
> +
>   	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) {
>   		vga_count++;
>   
> @@ -627,6 +630,8 @@ static bool amdgpu_atpx_detect(void)
>   		amdgpu_atpx_get_quirks(pdev);
>   	}
>   
> +	pci_dev_put(pdev);
> +
>   	if (has_atpx && vga_count == 2) {
>   		acpi_get_name(amdgpu_atpx_priv.atpx.handle, ACPI_FULL_PATHNAME, &buffer);
>   		pr_info("vga_switcheroo: detected switching method %s handle\n",


      reply	other threads:[~2025-11-21  6:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-21  1:44 Ma Ke
2025-11-21  6:53 ` Lazar, Lijo [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=5f614997-41a5-432f-ab3c-ea1011c16dc4@amd.com \
    --to=lijo.lazar@amd.com \
    --cc=airlied@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=evan.quan@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=make24@iscas.ac.cn \
    --cc=simona@ffwll.ch \
    --cc=stable@vger.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®