Skip to contentSkip to conversation

drm/xe: Fix memory leak in color pipeline initialization

PATCH New Jia Yao 1 participant 1 message Jan 25

Subsystems (3)
lore
Share & tools
lore

Jia Yao

author
#0 lore raw

PATCH 1/1 drm/xe: Fix memory leak in color pipeline initialization

Fix kasprintf() allocated pipeline names not being freed in intel_color_pipeline_plane_init(). The function allocates a string 'Color Pipeline N' for each pipeline via kasprintf() but never freed it.

Store the return value of drm_plane_create_color_pipeline_property() and free each allocated name before returning.

Fixes kmemleak:
unreferenced object 0xffff88c14e99cae0 (size 32):

    comm "(udev-worker)", pid 599, jiffies 4294671854
    hex dump (first 32 bytes):
      43 6f 6c 6f 72 20 50 69 70 65 6c 69 6e 65 20 33  Color Pipeline 3
      39 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  9...............
    backtrace (crc 993a6a5):
      kmemleak_alloc+0x4a/0xa0
      __kmalloc_node_track_caller_noprof+0x3be/0x760
      kvasprintf+0x6a/0xe0
      kasprintf+0x55/0x80
      intel_color_pipeline_plane_init+0xef/0x1f0 [xe]
      skl_universal_plane_create+0x436/0x810 [xe]
      intel_crtc_init+0x399/0x4e0 [xe]
      intel_display_driver_probe_nogem+0x60/0x1c0 [xe]
      xe_display_init_early+0xa8/0x130 [xe]
      xe_device_probe+0x3eb/0xb20 [xe]
      xe_pci_probe+0xe02/0x1210 [xe]
      local_pci_probe+0x47/0xb0
      pci_device_probe+0xf3/0x270
      really_probe+0xf1/0x410
      __driver_probe_device+0x8c/0x190
      driver_probe_device+0x24/0xd0
---
 drivers/gpu/drm/i915/display/intel_color_pipeline.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/display/intel_color_pipeline.c +8 -2
index 942d9b9c93ce..da3bda80a7e5 100644
@@ -83,7 +83,7 @@ int intel_color_pipeline_plane_init(struct drm_plane *plane, enum pipe pipe)
 	struct intel_display *display = to_intel_display(dev);
 	struct drm_prop_enum_list pipelines[MAX_COLOR_PIPELINES];
 	int len = 0;
-	int ret;
+	int ret, i;
 
 	/* Currently expose pipeline only for HDR planes */
 	if (!icl_is_hdr_plane(display, to_intel_plane(plane)->id))
@@ -95,5 +95,11 @@ int intel_color_pipeline_plane_init(struct drm_plane *plane, enum pipe pipe)
 		return ret;
 	len++;
 
-	return drm_plane_create_color_pipeline_property(plane, pipelines, len);
+	ret = drm_plane_create_color_pipeline_property(plane, pipelines, len);
+
+	/* Free allocated pipeline names */
+	for (i = 0; i < len; i++)
+		kfree(pipelines[i].name);
+
+	return ret;
 }
Signature · 1 line
2.43.0