[PATCH 1/1] drm/blend: size zpos array to active planes instead of total

From: Gustavo Piaz Da Silva

Date: Thu Apr 30 2026 - 20:14:00 EST


drm_atomic_helper_crtc_normalize_zpos() allocates a temporary
array with num_total_plane entries, which is the total number of
planes registered across the entire DRM device. However, the
function only processes planes active on the given CRTC, as
described by crtc_state->plane_mask.

Replace num_total_plane with hweight32(crtc_state->plane_mask),
which counts exactly the planes that drm_for_each_plane_mask will
visit. This ensures the allocation is sized precisely for the work
being done, reducing memory pressure on devices where
num_total_plane is significantly larger than the number of active
planes per CRTC.

Signed-off-by: Gustavo Piaz Da Silva <gustavopiazdasilva2102@xxxxxxxxx>
---
drivers/gpu/drm/drm_blend.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_blend.c b/drivers/gpu/drm/drm_blend.c
index 1f3af27d2418e..ffa1870528726 100644
--- a/drivers/gpu/drm/drm_blend.c
+++ b/drivers/gpu/drm/drm_blend.c
@@ -465,7 +465,7 @@ static int drm_atomic_helper_crtc_normalize_zpos(struct drm_crtc *crtc,
{
struct drm_atomic_state *state = crtc_state->state;
struct drm_device *dev = crtc->dev;
- int total_planes = dev->mode_config.num_total_plane;
+ int total_planes = hweight32(crtc_state->plane_mask);
struct drm_plane_state **states;
struct drm_plane *plane;
int i, n = 0;
--
2.43.0