[PATCH v2 2/7] drm/vkms: free the colorop whose initialization failed

From: Oarora Etimis

Date: Sat Nov 28 2026 - 13:20:14 EST


The error path of vkms_initialize_color_pipeline() walks ops[0..i-1],
but ops[i] is already allocated when its drm_plane_colorop_*_init()
call fails, so it leaks.

Walk ops[0..i] instead, and call drm_colorop_cleanup() only on the
entries that were linked, since init can fail before that.

Fixes: c1e578bd08da ("drm/vkms: Add enumerated 1D curve colorop")

Signed-off-by: Oarora Etimis <oaroraetimis@xxxxxxxxx>
---
drivers/gpu/drm/vkms/vkms_colorop.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_colorop.c b/drivers/gpu/drm/vkms/vkms_colorop.c
index 9424b1994239..4e6a82193f2e 100644
--- a/drivers/gpu/drm/vkms/vkms_colorop.c
+++ b/drivers/gpu/drm/vkms/vkms_colorop.c
@@ -126,11 +126,17 @@ static int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_pr
return 0;

cleanup:
- for (j = 0; j < i; j++) {
- if (ops[j]) {
+ for (j = 0; j <= i && j < ARRAY_SIZE(ops); j++) {
+ if (!ops[j])
+ continue;
+
+ /*
+ * drm_plane_colorop_init() can fail before the colorop is
+ * linked and has a device; there is nothing to undo then.
+ */
+ if (ops[j]->dev)
drm_colorop_cleanup(ops[j]);
- kfree(ops[j]);
- }
+ kfree(ops[j]);
}

return ret;

--
2.56.1