dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/nouveau/dispnv04: Fix PCI device reference leaks on nForce
@ 2026-11-29  5:00 Yuho Choi
  0 siblings, 0 replies; only message in thread
From: Yuho Choi @ 2026-11-29  5:00 UTC (permalink / raw)
  To: Lyude Paul, Danilo Krummrich
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Simona Vetter, dri-devel, nouveau, Yuho Choi

nv04_update_arb() and nouveau_hw_get_clock() read memory settings from
functions of the nForce/nForce2 host bridge. They look the device up
with pci_get_domain_bus_and_slot(), which returns it with an elevated
reference count, and pass it straight to pci_read_config_dword()
without ever dropping that reference.

Both are called from nv04_crtc_do_mode_set_base() through
nouveau_calc_arb(), so every mode set on an nForce or nForce2 IGP
leaks two references to host bridge functions.

Keep the device in a local variable and call pci_dev_put() once its
config space has been read, as nv1a_ram_new() does for the same host
bridge.

Fixes: 6ee738610f41 ("drm/nouveau: Add DRM driver for NVIDIA GPUs")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
Compile-tested only (x86_64, DRM_NOUVEAU=m, W=1, on drm-misc-fixes). I
don't have an nForce or nForce2 board, and QEMU does not emulate these
GPUs, so I could not run this path.

The lookups could in theory return NULL; that is unchanged here, since
these host bridge functions are always present on nForce chipsets.

 drivers/gpu/drm/nouveau/dispnv04/arb.c |  6 ++++--
 drivers/gpu/drm/nouveau/dispnv04/hw.c  | 13 +++++++++----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv04/arb.c b/drivers/gpu/drm/nouveau/dispnv04/arb.c
index 1d3542d6006b..15859ec5a532 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/arb.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/arb.c
@@ -209,11 +209,13 @@ nv04_update_arb(struct drm_device *dev, int VClk, int bpp,
 	sim_data.two_heads = nv_two_heads(dev);
 	if ((pdev->device & 0xffff) == 0x01a0 /*CHIPSET_NFORCE*/ ||
 	    (pdev->device & 0xffff) == 0x01f0 /*CHIPSET_NFORCE2*/) {
+		struct pci_dev *bridge;
 		uint32_t type;
 		int domain = pci_domain_nr(pdev->bus);
 
-		pci_read_config_dword(pci_get_domain_bus_and_slot(domain, 0, 1),
-				      0x7c, &type);
+		bridge = pci_get_domain_bus_and_slot(domain, 0, 1);
+		pci_read_config_dword(bridge, 0x7c, &type);
+		pci_dev_put(bridge);
 
 		sim_data.memory_type = (type >> 12) & 1;
 		sim_data.memory_width = 64;
diff --git a/drivers/gpu/drm/nouveau/dispnv04/hw.c b/drivers/gpu/drm/nouveau/dispnv04/hw.c
index 8b376f9c8746..4b29b77baaac 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/hw.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/hw.c
@@ -223,9 +223,12 @@ nouveau_hw_get_clock(struct drm_device *dev, enum nvbios_pll_type plltype)
 
 	if (plltype == PLL_MEMORY &&
 	    (pdev->device & 0x0ff0) == CHIPSET_NFORCE) {
+		struct pci_dev *bridge;
 		uint32_t mpllP;
-		pci_read_config_dword(pci_get_domain_bus_and_slot(domain, 0, 3),
-				      0x6c, &mpllP);
+
+		bridge = pci_get_domain_bus_and_slot(domain, 0, 3);
+		pci_read_config_dword(bridge, 0x6c, &mpllP);
+		pci_dev_put(bridge);
 		mpllP = (mpllP >> 8) & 0xf;
 		if (!mpllP)
 			mpllP = 4;
@@ -234,10 +237,12 @@ nouveau_hw_get_clock(struct drm_device *dev, enum nvbios_pll_type plltype)
 	} else
 	if (plltype == PLL_MEMORY &&
 	    (pdev->device & 0xff0) == CHIPSET_NFORCE2) {
+		struct pci_dev *bridge;
 		uint32_t clock;
 
-		pci_read_config_dword(pci_get_domain_bus_and_slot(domain, 0, 5),
-				      0x4c, &clock);
+		bridge = pci_get_domain_bus_and_slot(domain, 0, 5);
+		pci_read_config_dword(bridge, 0x4c, &clock);
+		pci_dev_put(bridge);
 		return clock / 1000;
 	}
 

base-commit: e950f467b8adbfb2f460d9b9454280cdbf597885
-- 
2.56.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-30 15:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29  5:00 [PATCH] drm/nouveau/dispnv04: Fix PCI device reference leaks on nForce Yuho Choi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox