⬢ DragonFlyBSD Kernel Audit
DF-4198 / fix.diff
← back to finding ↓ download raw
--- a/sys/dev/drm/amd/display/dc/dml/dml1_display_rq_dlg_calc.c
+++ b/sys/dev/drm/amd/display/dc/dml/dml1_display_rq_dlg_calc.c
@@ -44,6 +44,9 @@
 	if (source_format == dm_444_16) {
 		if (!is_chroma)
 			ret_val = 2;
+	} else if (source_format == dm_444_8) {
+		if (!is_chroma)
+			ret_val = 1;	/* dm_mono_8: one byte per element */
 	} else if (source_format == dm_444_32) {
 		if (!is_chroma)
 			ret_val = 4;
@@ -633,6 +636,15 @@
 	bytes_per_element = get_bytes_per_element(
 			(enum source_format_class) pipe_src_param.source_format,
 			is_chroma);
+	if (bytes_per_element == 0) {
+		/* Unknown/unhandled source_format: get_bytes_per_element()
+		 * returning 0 would divide by zero below (blk256_width =
+		 * 256 / bytes_per_element for linear surfaces) and poison
+		 * every log2 derived from it. ASSERT is only WARN_ON in
+		 * release builds, so bail out explicitly. */
+		ASSERT(0);
+		return;
+	}
 	log2_bytes_per_element = dml_log2(bytes_per_element);
 	blk256_width = 0;
 	blk256_height = 0;