[PATCH] drm/amd/display: use kvfree() to free kvcalloc() DTN log buffer
From: Ziheng Wei
Date: Sun Dec 06 2026 - 03:03:57 EST
dm_dtn_log_append_v() allocates log_ctx->buf with kvcalloc(), which may
fall back to vmalloc() for large DTN logs. Both dm_dtn_log_append_v()
on reallocation and dtn_log_read() on completion free it with kfree()
instead of kvfree(), which corrupts allocator metadata if the buffer is
vmalloc-backed.
Use kvfree() in both places, matching amdgpu_dm_helpers_test.c.
Found by LLM-assisted static analysis. Compile-tested on x86_64.
Fixes: 46659a83e466 ("drm/amd/display: Support reading hw state from debugfs file")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ziheng Wei <zihengw03@xxxxxxx>
---
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 2 +-
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
index 36f32ed4b..9c3346bd5 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
@@ -4279,7 +4279,7 @@ static ssize_t dtn_log_read(
}
}
- kfree(log_ctx.buf);
+ kvfree(log_ctx.buf);
return result;
}
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
index 52c084f3b..5881cc0a6 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
@@ -587,7 +587,7 @@ void dm_dtn_log_append_v(struct dc_context *ctx,
if (buf) {
memcpy(buf, log_ctx->buf, log_ctx->pos);
- kfree(log_ctx->buf);
+ kvfree(log_ctx->buf);
log_ctx->buf = buf;
log_ctx->size = total;
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0