[PATCH v2 5/8] drm/i915: Set crtc->name to "pipe A", "pipe B", etc.

ville.syrjala at linux.intel.com ville.syrjala at linux.intel.com
Thu Nov 12 11:39:01 PST 2015


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

v2: Fix intel_crtc leak on failure to allocate the name
    Use a local 'name' variable to make things easier

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 drivers/gpu/drm/i915/intel_display.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index b628dab..972e17f 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -10711,6 +10711,7 @@ static void intel_crtc_destroy(struct drm_crtc *crtc)
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	struct drm_device *dev = crtc->dev;
 	struct intel_unpin_work *work;
+	char *name;
 
 	spin_lock_irq(&dev->event_lock);
 	work = intel_crtc->unpin_work;
@@ -10722,8 +10723,13 @@ static void intel_crtc_destroy(struct drm_crtc *crtc)
 		kfree(work);
 	}
 
+	/*
+	 * drm_crtc_cleanup() zeroes the structure, so
+	 * need an extra dance to avoid leaking the name.
+	 */
+	name = crtc->name;
 	drm_crtc_cleanup(crtc);
-
+	kfree(name);
 	kfree(intel_crtc);
 }
 
@@ -14026,15 +14032,16 @@ static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_cr
 static void intel_crtc_init(struct drm_device *dev, int pipe)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	struct intel_crtc *intel_crtc;
+	struct intel_crtc *intel_crtc = NULL;
 	struct intel_crtc_state *crtc_state = NULL;
 	struct drm_plane *primary = NULL;
 	struct drm_plane *cursor = NULL;
+	char *name = NULL;
 	int i, ret;
 
 	intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
-	if (intel_crtc == NULL)
-		return;
+	if (!intel_crtc)
+		goto fail;
 
 	crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
 	if (!crtc_state)
@@ -14043,6 +14050,11 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
 	intel_crtc->base.state = &crtc_state->base;
 	crtc_state->base.crtc = &intel_crtc->base;
 
+	name = kasprintf(GFP_KERNEL, "pipe %c", pipe_name(pipe));
+	if (!name)
+		goto fail;
+	intel_crtc->base.name = name;
+
 	/* initialize shared scalers */
 	if (INTEL_INFO(dev)->gen >= 9) {
 		if (pipe == PIPE_C)
@@ -14105,6 +14117,7 @@ fail:
 		drm_plane_cleanup(primary);
 	if (cursor)
 		drm_plane_cleanup(cursor);
+	kfree(name);
 	kfree(crtc_state);
 	kfree(intel_crtc);
 }
-- 
2.4.10



More information about the dri-devel mailing list