mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: Fix error handling in amdgpu_atpx_detect
@ 2025-11-21  1:44 Ma Ke
  2025-11-21  6:53 ` Lazar, Lijo
  0 siblings, 1 reply; 2+ messages in thread
From: Ma Ke @ 2025-11-21  1:44 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig, airlied, simona, make24, evan.quan
  Cc: amd-gfx, dri-devel, linux-kernel, akpm, stable

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.

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",
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-21  6:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-21  1:44 [PATCH] drm/amdgpu: Fix error handling in amdgpu_atpx_detect Ma Ke
2025-11-21  6:53 ` Lazar, Lijo

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®