All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] agp: efficeon: Disable PCI device on probe failure
@ 2026-06-23  7:52 Myeonghun Pak
  2026-06-23  8:03 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Myeonghun Pak @ 2026-06-23  7:52 UTC (permalink / raw)
  To: David Airlie; +Cc: dri-devel, linux-kernel, Myeonghun Pak, Ijae Kim

agp_efficeon_probe() enables the PCI device before checking whether the
GART resource can be assigned and before registering the AGP bridge.  If
either of those later steps fails, the probe path can return without
dropping the enable reference.

Route the resource-assignment failure through a shared unwind path that
puts the bridge before disabling the PCI device.  Also check the return
value from agp_add_bridge() explicitly, disabling the PCI device on
failure while leaving the bridge cleanup to agp_add_bridge()'s failure
handling.

Balance the successful probe path by disabling the PCI device from remove()
after the AGP bridge has been removed and released.

This issue was identified during our ongoing static-analysis research while
reviewing kernel code.

Fixes: 46cfc58a77de ("agp: efficeon-agp: do not use PCI resources before pci_enable_device()")
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>

---
 drivers/char/agp/efficeon-agp.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/char/agp/efficeon-agp.c b/drivers/char/agp/efficeon-agp.c
index 0d25bbdc7e..03804b08ef 100644
--- a/drivers/char/agp/efficeon-agp.c
+++ b/drivers/char/agp/efficeon-agp.c
@@ -346,6 +346,7 @@ static int agp_efficeon_probe(struct pci_dev *pdev,
 	struct agp_bridge_data *bridge;
 	u8 cap_ptr;
 	struct resource *r;
+	int err;
 
 	cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
 	if (!cap_ptr)
@@ -388,8 +389,8 @@ static int agp_efficeon_probe(struct pci_dev *pdev,
 	if (!r->start && r->end) {
 		if (pci_assign_resource(pdev, 0)) {
 			printk(KERN_ERR PFX "could not assign resource 0\n");
-			agp_put_bridge(bridge);
-			return -ENODEV;
+			err = -ENODEV;
+			goto err_put_bridge;
 		}
 	}
 
@@ -401,7 +402,17 @@ static int agp_efficeon_probe(struct pci_dev *pdev,
 	}
 
 	pci_set_drvdata(pdev, bridge);
-	return agp_add_bridge(bridge);
+	err = agp_add_bridge(bridge);
+	if (err)
+		goto err_disable_device;
+
+	return 0;
+
+err_put_bridge:
+	agp_put_bridge(bridge);
+err_disable_device:
+	pci_disable_device(pdev);
+	return err;
 }
 
 static void agp_efficeon_remove(struct pci_dev *pdev)
@@ -410,6 +421,7 @@ static void agp_efficeon_remove(struct pci_dev *pdev)
 
 	agp_remove_bridge(bridge);
 	agp_put_bridge(bridge);
+	pci_disable_device(pdev);
 }
 
 static int agp_efficeon_resume(struct device *dev)
-- 
2.47.1

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

end of thread, other threads:[~2026-06-23  8:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-23  7:52 [PATCH] agp: efficeon: Disable PCI device on probe failure Myeonghun Pak
2026-06-23  8:03 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.