dm_test_gpu_mem_init() declares cpu_ptr as void *, then passes
sizeof(*cpu_ptr) to kunit_kzalloc(). Dereferencing a void pointer gives
sizeof(void), which is meaningless and triggers a Smatch static checker
warning.

The pointer is only used as a fake CPU address sentinel in the mock
bo_create_kernel() hook; its allocation size is never stored or
inspected. Change the type to u8 * so that sizeof(*cpu_ptr) resolves to
1 and the warning is gone. The u8 * assigns to the void * field
  dm_test_bo_ops_ctx.cpu_ptr without a cast.

Fixes: 0b73216c7dea ("drm/amd/display: Test GPU memory allocation")
Reported-by: Dan Carpenter <[email protected]>
Cc: Roman Li <[email protected]>
Cc: Alex Hung <[email protected]>
Cc: Tom Chung <[email protected]>
Cc: Ivan Lipski <[email protected]>
Cc: Harry Wentland <[email protected]>
Cc: Aurabindo Pillai <[email protected]>
Signed-off-by: Srinivasan Shanmugam <[email protected]>
---
 .../drm/amd/display/amdgpu_dm/tests/amdgpu_dm_services_test.c   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_services_test.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_services_test.c
index 4ff430e4b23b..4a9b0e65bbb3 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_services_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_services_test.c
@@ -335,7 +335,7 @@ static const struct amdgpu_dm_services_kunit_ops 
dm_test_bo_ops = {
  */
 static int dm_test_gpu_mem_init(struct kunit *test)
 {
-       void *cpu_ptr;
+       u8 *cpu_ptr;
 
        cpu_ptr = kunit_kzalloc(test, sizeof(*cpu_ptr), GFP_KERNEL);
        KUNIT_ASSERT_NOT_NULL(test, cpu_ptr);
-- 
2.34.1

Reply via email to