[Intel-gfx] [PATCH v2 09/13] drm/i915: Introduce intel_plane_alloc()

Ville Syrjala ville.syrjala at linux.intel.com
Wed May 30 16:59:29 UTC 2018


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

Pull the common plane+plane_state allocation into a small helper.
Reduces the amount of boilerplate in the plane initialization
functions.

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 drivers/gpu/drm/i915/intel_display.c | 44 ++++++++-----------------------
 drivers/gpu/drm/i915/intel_drv.h     |  3 +++
 drivers/gpu/drm/i915/intel_sprite.c  | 50 ++++++++++++++++++++++++------------
 3 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 2d6147e71aca..a581118f5c7b 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -13441,8 +13441,7 @@ bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
 static struct intel_plane *
 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
 {
-	struct intel_plane *primary = NULL;
-	struct intel_plane_state *state = NULL;
+	struct intel_plane *primary;
 	const uint32_t *intel_primary_formats;
 	unsigned int supported_rotations;
 	unsigned int possible_crtcs;
@@ -13450,19 +13449,9 @@ intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
 	const uint64_t *modifiers;
 	int ret;
 
-	primary = kzalloc(sizeof(*primary), GFP_KERNEL);
-	if (!primary) {
-		ret = -ENOMEM;
-		goto fail;
-	}
-
-	state = intel_create_plane_state(&primary->base);
-	if (!state) {
-		ret = -ENOMEM;
-		goto fail;
-	}
-
-	primary->base.state = &state->base;
+	primary = intel_plane_alloc();
+	if (IS_ERR(primary))
+		return primary;
 
 	primary->can_scale = false;
 	primary->max_downscale = 1;
@@ -13597,8 +13586,7 @@ intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
 	return primary;
 
 fail:
-	kfree(state);
-	kfree(primary);
+	intel_plane_free(primary);
 
 	return ERR_PTR(ret);
 }
@@ -13607,24 +13595,13 @@ static struct intel_plane *
 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
 			  enum pipe pipe)
 {
-	struct intel_plane *cursor = NULL;
-	struct intel_plane_state *state = NULL;
 	unsigned int possible_crtcs;
+	struct intel_plane *cursor;
 	int ret;
 
-	cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
-	if (!cursor) {
-		ret = -ENOMEM;
-		goto fail;
-	}
-
-	state = intel_create_plane_state(&cursor->base);
-	if (!state) {
-		ret = -ENOMEM;
-		goto fail;
-	}
-
-	cursor->base.state = &state->base;
+	cursor = intel_plane_alloc();
+	if (IS_ERR(cursor))
+		return cursor;
 
 	cursor->can_scale = false;
 	cursor->max_downscale = 1;
@@ -13674,8 +13651,7 @@ intel_cursor_plane_create(struct drm_i915_private *dev_priv,
 	return cursor;
 
 fail:
-	kfree(state);
-	kfree(cursor);
+	intel_plane_free(cursor);
 
 	return ERR_PTR(ret);
 }
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index e39827b5da5f..b9035432f285 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -2089,6 +2089,9 @@ bool skl_plane_has_ccs(struct drm_i915_private *dev_priv,
 bool intel_format_is_yuv(uint32_t format);
 bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
 			  enum pipe pipe, enum plane_id plane_id);
+struct intel_plane *intel_plane_alloc(void);
+void intel_plane_free(struct intel_plane *plane);
+
 
 /* intel_tv.c */
 void intel_tv_init(struct drm_i915_private *dev_priv);
diff --git a/drivers/gpu/drm/i915/intel_sprite.c b/drivers/gpu/drm/i915/intel_sprite.c
index a87ec18b8828..36b86416f11e 100644
--- a/drivers/gpu/drm/i915/intel_sprite.c
+++ b/drivers/gpu/drm/i915/intel_sprite.c
@@ -1369,12 +1369,40 @@ bool skl_plane_has_ccs(struct drm_i915_private *dev_priv,
 		 plane_id == PLANE_SPRITE0);
 }
 
+struct intel_plane *intel_plane_alloc(void)
+{
+	struct intel_plane_state *plane_state;
+	struct intel_plane *plane;
+
+	plane = kzalloc(sizeof(*plane), GFP_KERNEL);
+	if (!plane)
+		return ERR_PTR(-ENOMEM);
+
+	plane_state = intel_create_plane_state(&plane->base);
+	if (!plane_state) {
+		kfree(plane);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	plane->base.state = &plane_state->base;
+
+	return plane;
+}
+
+void intel_plane_free(struct intel_plane *plane)
+{
+	struct intel_plane_state *plane_state =
+		to_intel_plane_state(plane->base.state);
+
+	kfree(plane_state);
+	kfree(plane);
+}
+
 struct intel_plane *
 intel_sprite_plane_create(struct drm_i915_private *dev_priv,
 			  enum pipe pipe, int plane)
 {
-	struct intel_plane *intel_plane = NULL;
-	struct intel_plane_state *state = NULL;
+	struct intel_plane *intel_plane;
 	unsigned long possible_crtcs;
 	const uint32_t *plane_formats;
 	const uint64_t *modifiers;
@@ -1382,18 +1410,9 @@ intel_sprite_plane_create(struct drm_i915_private *dev_priv,
 	int num_plane_formats;
 	int ret;
 
-	intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
-	if (!intel_plane) {
-		ret = -ENOMEM;
-		goto fail;
-	}
-
-	state = intel_create_plane_state(&intel_plane->base);
-	if (!state) {
-		ret = -ENOMEM;
-		goto fail;
-	}
-	intel_plane->base.state = &state->base;
+	intel_plane = intel_plane_alloc();
+	if (IS_ERR(intel_plane))
+		return intel_plane;
 
 	if (INTEL_GEN(dev_priv) >= 9) {
 		intel_plane->can_scale = true;
@@ -1519,8 +1538,7 @@ intel_sprite_plane_create(struct drm_i915_private *dev_priv,
 	return intel_plane;
 
 fail:
-	kfree(state);
-	kfree(intel_plane);
+	intel_plane_free(intel_plane);
 
 	return ERR_PTR(ret);
 }
-- 
2.16.1



More information about the Intel-gfx mailing list