Skip to contentSkip to conversation

drm/vkms: Adjust vkms_state->active_planes allocation type

PATCH Applied Kees Cook 3 participants 4 messages Apr 26, 2025 – May 6, 2025

Subsystems (3)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 drm/vkms: Adjust vkms_state->active_planes allocation type

In preparation for making the kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)

The assigned type is "struct vkms_plane_state **", but the returned type will be "struct drm_plane **". These are the same size (pointer size), but the types don't match. Adjust the allocation type to match the assignment.

---
Cc: Louis Chauvet <[email protected]>
Cc: Haneen Mohammed <[email protected]>
Cc: Simona Vetter <[email protected]>
Cc: Melissa Wen <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: David Airlie <[email protected]>
Cc: <[email protected]>

---
 drivers/gpu/drm/vkms/vkms_crtc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vkms/vkms_crtc.c +1 -1
index 12034ec12029..8c9898b9055d 100644
@@ -194,7 +194,7 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
 		i++;
 	}
 
-	vkms_state->active_planes = kcalloc(i, sizeof(plane), GFP_KERNEL);
+	vkms_state->active_planes = kcalloc(i, sizeof(*vkms_state->active_planes), GFP_KERNEL);
 	if (!vkms_state->active_planes)
 		return -ENOMEM;
 	vkms_state->num_active_planes = i;
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Le 26/04/2025 à 08:14, Kees Cook a écrit :

Quoted 8 lines

In preparation for making the kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)

The assigned type is "struct vkms_plane_state **", but the returned type will be "struct drm_plane **". These are the same size (pointer size), but the types don't match. Adjust the allocation type to match the assignment.

I think this is an issue, can you add the proper Fixup tag in this commit?

With this:

Quoted 28 lines

---
Cc: Louis Chauvet <[email protected]>
Cc: Haneen Mohammed <[email protected]>
Cc: Simona Vetter <[email protected]>
Cc: Melissa Wen <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: David Airlie <[email protected]>
Cc: <[email protected]>

---
  drivers/gpu/drm/vkms/vkms_crtc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vkms/vkms_crtc.c +1 -1
index 12034ec12029..8c9898b9055d 100644
@@ -194,7 +194,7 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
  		i++;
  	}
 
-	vkms_state->active_planes = kcalloc(i, sizeof(plane), GFP_KERNEL);
+	vkms_state->active_planes = kcalloc(i, sizeof(*vkms_state->active_planes), GFP_KERNEL);
  	if (!vkms_state->active_planes)
  		return -ENOMEM;
  	vkms_state->num_active_planes = i;
Signature · 3 lines
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
author
#2 lore raw
Quoted 8 lines · Louis Chauvet

Le 26/04/2025 à 08:14, Kees Cook a écrit :

Quoted 5 lines

In preparation for making the kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)

Quoted 5 lines
Quoted 3 lines

The assigned type is "struct vkms_plane_state **", but the returned type will be "struct drm_plane **". These are the same size (pointer size), but the types don't match. Adjust the allocation type to match the assignment.

I think this is an issue, can you add the proper Fixup tag in this commit?

I think trailers updating tools like b4 will pick this up:

Fixes 8b1865873651 ("drm/vkms: totally reworked crc data tracking")

Would you rather I send a v2 with the Fixes added?

Quoted 4 lines

With this:

Thanks!

-Kees

Signature · 1 line
Kees Cook
#3 lore raw
In reply to Kees Cook
Quoted 10 lines · Kees Cook

In preparation for making the kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)

The assigned type is "struct vkms_plane_state **", but the returned type will be "struct drm_plane **". These are the same size (pointer size), but the types don't match. Adjust the allocation type to match the assignment.

[...]

Applied, thanks!

[1/1] drm/vkms: Adjust vkms_state->active_planes allocation type

      commit: 258aebf100540d36aba910f545d4d5ddf4ecaf0b

Best regards,

Signature · 1 line
Louis Chauvet <[email protected]>