[PATCH] drm/gud: avoid divide error in gud_stats_debugfs
From: YuanZhe Liu
Date: Thu Oct 29 2026 - 03:35:48 EST
gud_stats_debugfs() computes the compression ratio by dividing the
accumulated uncompressed length by stats_actual_length. That counter is
zero until the first framebuffer flush has completed, so reading the
stats debugfs file on a display which negotiates LZ4 compression raises
a divide error before any frame has been sent. The wrap-around reset in
gud_flush_rect() also clears the counter for a moment, which a
concurrent read can observe.
Copy the counter into a local variable and skip the ratio computation
when it is zero.
Fixes: 40e1a70b4aed ("drm: Add GUD USB Display driver")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
drivers/gpu/drm/gud/gud_drv.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/gud/gud_drv.c b/drivers/gpu/drm/gud/gud_drv.c
index 3a1b9e2a2eaa..85ddb302d2ba 100644
--- a/drivers/gpu/drm/gud/gud_drv.c
+++ b/drivers/gpu/drm/gud/gud_drv.c
@@ -329,10 +329,17 @@ static int gud_stats_debugfs(struct seq_file *m, void *data)
seq_puts(m, "\n");
if (gdrm->compression) {
+ u64 actual_length = gdrm->stats_actual_length;
u64 remainder;
- u64 ratio = div64_u64_rem(gdrm->stats_length, gdrm->stats_actual_length,
- &remainder);
- u64 ratio_frac = div64_u64(remainder * 10, gdrm->stats_actual_length);
+ u64 ratio, ratio_frac;
+
+ if (!actual_length) {
+ seq_puts(m, "Compression ratio: n/a\n");
+ return 0;
+ }
+
+ ratio = div64_u64_rem(gdrm->stats_length, actual_length, &remainder);
+ ratio_frac = div64_u64(remainder * 10, actual_length);
seq_printf(m, "Compression ratio: %llu.%llu\n", ratio, ratio_frac);
}
--
2.34.1