⬢ DragonFlyBSD Kernel Audit
DF-5064 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/dev/drm/drm_dragonfly.c b/sys/dev/drm/drm_dragonfly.c
--- a/sys/dev/drm/drm_dragonfly.c
+++ b/sys/dev/drm/drm_dragonfly.c
@@ -290,7 +290,18 @@ drm_device_detach(device_t kdev)
 #endif
 
 	drm_fini_pdev(&dev->pdev);
 
+	/*
+	 * DF-5064: unpublish the device and drop the primary reference the
+	 * same way Linux's pci remove path (i915_pci_remove &al) does.
+	 * Without drm_dev_unregister() the /dev/dri minors stay reachable
+	 * and every open/ioctl calls into dev->driver, which lives in the
+	 * (about to be) unloaded driver module.  Without drm_dev_put() the
+	 * whole drm_device graph leaks on every kldunload.
+	 */
+	drm_dev_unregister(dev);
+	drm_dev_put(dev);
+
 	return 0;
 }