Skip to contentSkip to conversation

drm/nouveau: fix PCI device reference leaks in dispnv04

PATCH New Jaeyeong Lee 2 participants 2 messages Nov 29

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/nouveau: fix PCI device reference leaks in dispnv04

pci_get_domain_bus_and_slot() returns a referenced PCI device. The nForce arbitration and clock paths pass that device directly to pci_read_config_dword(), losing the pointer and leaking one reference on every invocation.

Keep the bridge pointer and drop the temporary reference after each configuration-space read.

Fixes 2fa6d6cdaf283c05 ("drm/nouveau: deprecate pci_get_bus_and_slot()")
---
 drivers/gpu/drm/nouveau/dispnv04/arb.c |  6 ++++--
 drivers/gpu/drm/nouveau/dispnv04/hw.c  | 13 +++++++++----
 2 files changed, 13 insertions(+), 6 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/arb.c +4 -2
index 1d3542d60..15859ec5a 100644
@@ -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;
drivers/gpu/drm/nouveau/dispnv04/hw.c +9 -4
index 8b376f9c8..4b29b77ba 100644
@@ -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;
 	}
 
Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/nouveau: Fixes trailer cites wrong commit for dispnv04 pci_dev leak --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/nouveau: Fixes trailer cites wrong commit for dispnv04 pci_dev leak
--

commit d77cb05c2913f228ea0d6d6679426ec339d32cca
Author: Jaeyeong Lee <[email protected]>

Quoted 7 lines

drm/nouveau: fix PCI device reference leaks in dispnv04

pci_get_domain_bus_and_slot() returns a referenced PCI device. The nForce arbitration and clock paths pass that device directly to pci_read_config_dword(), losing the pointer and leaking one reference on every invocation.

Quoted 6 lines

Keep the bridge pointer and drop the temporary reference after each configuration-space read.

Fixes 2fa6d6cdaf283c05 ("drm/nouveau: deprecate pci_get_bus_and_slot()")

[Severity: Low]
Should the Fixes: tag point to 6ee738610f41 ("drm/nouveau: Add DRM driver for NVIDIA GPUs") instead?

Commit 2fa6d6cdaf28 ("drm/nouveau: deprecate pci_get_bus_and_slot()") only replaced pci_get_bus_and_slot() with pci_get_domain_bus_and_slot(), and pci_get_bus_and_slot() already returned a referenced struct pci_dev that required pci_dev_put().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1