⬢ DragonFlyBSD Kernel Audit
DF-4484 / fix.diff
← back to finding ↓ download raw
--- orig_acpi_video.c	2026-09-20 19:16:19.855126316 +0000
+++ patched_acpi_video.c	2026-09-20 19:16:19.867126165 +0000
@@ -52,6 +52,7 @@
 	int		vo_fullpower;
 	int		vo_economy;
 	int		vo_numlevels;
+	int		vo_matched;	/* reprobe walk matched this output */
 	int		*vo_levels;
 	struct sysctl_ctx_list vo_sysctl_ctx;
 	struct sysctl_oid *vo_sysctl_tree;
@@ -384,10 +385,10 @@
 	case VID_NOTIFY_REPROBE:
 		ACPI_SERIAL_BEGIN(video);
 		STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next)
-			vo->handle = NULL;
+			vo->vo_matched = 0;
 		acpi_video_bind_outputs(sc);
 		STAILQ_FOREACH_MUTABLE(vo, &sc->vid_outputs, vo_next, vo_tmp) {
-			if (vo->handle == NULL) {
+			if (vo->vo_matched == 0) {
 				STAILQ_REMOVE(&sc->vid_outputs, vo,
 				    acpi_video_output, vo_next);
 				acpi_video_vo_destroy(vo);
@@ -436,12 +437,14 @@
 
 	STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
 		if (vo->adr == adr) {
+			vo->vo_matched = 1;
 			acpi_video_vo_bind(vo, handle);
 			return;
 		}
 	}
 	vo = acpi_video_vo_init(adr);
 	if (vo != NULL) {
+		vo->vo_matched = 1;
 		acpi_video_vo_bind(vo, handle);
 		STAILQ_INSERT_TAIL(&sc->vid_outputs, vo, vo_next);
 	}
@@ -594,8 +597,13 @@
 acpi_video_vo_bind(struct acpi_video_output *vo, ACPI_HANDLE handle)
 {
 	ACPI_SERIAL_BEGIN(video_output);
-	if (vo->vo_levels != NULL)
+	if (vo->vo_levels != NULL) {
+		AcpiRemoveNotifyHandler(vo->handle, ACPI_DEVICE_NOTIFY,
+		    acpi_video_vo_notify_handler);
 		AcpiOsFree(vo->vo_levels);
+		vo->vo_levels = NULL;
+		vo->vo_numlevels = 0;
+	}
 	vo->handle = handle;
 	vo->vo_numlevels = vo_get_brightness_levels(handle, &vo->vo_levels);
 	if (vo->vo_numlevels >= 2) {
@@ -1000,6 +1008,7 @@
 		goto out;
 	}
 	*levelp = levels;
+	AcpiOsFree(bcl_buf.Pointer);
 	return (n);
 
 out: