[PATCH v2 8/8] drm/atmel-hlcdc: destroy properly the plane state in the reset callback

Ludovic Desroches posted 8 patches 1 month, 2 weeks ago
[PATCH v2 8/8] drm/atmel-hlcdc: destroy properly the plane state in the reset callback
Posted by Ludovic Desroches 1 month, 2 weeks ago
If there is a plane state to destroy when doing a plane reset, destroy
it using the atmel_hlcdc_plane_destroy_state() function. So we call
__drm_atomic_helper_plane_destroy_state() and avoid code duplication.

Signed-off-by: Ludovic Desroches <ludovic.desroches@microchip.com>
---
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 52 ++++++++++++-------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
index c1f3aaae29fb9f6b947f81e2fb4e7a61e10ac5d9..81dc730362322a4bae9b48dca97b06baa1e331e7 100644
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
+++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
@@ -1155,32 +1155,6 @@ static int atmel_hlcdc_plane_alloc_dscrs(struct drm_plane *p,
 	return -ENOMEM;
 }
 
-static void atmel_hlcdc_plane_reset(struct drm_plane *p)
-{
-	struct atmel_hlcdc_plane_state *state;
-
-	if (p->state) {
-		state = drm_plane_state_to_atmel_hlcdc_plane_state(p->state);
-
-		if (state->base.fb)
-			drm_framebuffer_put(state->base.fb);
-
-		kfree(state);
-		p->state = NULL;
-	}
-
-	state = kzalloc(sizeof(*state), GFP_KERNEL);
-	if (state) {
-		if (atmel_hlcdc_plane_alloc_dscrs(p, state)) {
-			kfree(state);
-			drm_err(p->dev,
-				"Failed to allocate initial plane state\n");
-			return;
-		}
-		__drm_atomic_helper_plane_reset(p, &state->base);
-	}
-}
-
 static struct drm_plane_state *
 atmel_hlcdc_plane_atomic_duplicate_state(struct drm_plane *p)
 {
@@ -1222,6 +1196,32 @@ static void atmel_hlcdc_plane_atomic_destroy_state(struct drm_plane *p,
 	kfree(state);
 }
 
+static void atmel_hlcdc_plane_reset(struct drm_plane *p)
+{
+	struct atmel_hlcdc_plane_state *state;
+	struct atmel_hlcdc_dc *dc = p->dev->dev_private;
+	struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p);
+
+	if (p->state) {
+		atmel_hlcdc_plane_atomic_destroy_state(p, p->state);
+		p->state = NULL;
+	}
+
+	state = kzalloc(sizeof(*state), GFP_KERNEL);
+	if (state) {
+		if (atmel_hlcdc_plane_alloc_dscrs(p, state)) {
+			kfree(state);
+			drm_err(p->dev,
+				"Failed to allocate initial plane state\n");
+			return;
+		}
+		__drm_atomic_helper_plane_reset(p, &state->base);
+	}
+
+	if (plane->layer.desc->layout.csc)
+		dc->desc->ops->lcdc_csc_init(plane, plane->layer.desc);
+}
+
 static const struct drm_plane_funcs layer_plane_funcs = {
 	.update_plane = drm_atomic_helper_update_plane,
 	.disable_plane = drm_atomic_helper_disable_plane,

-- 
2.51.0
Re: [PATCH v2 8/8] drm/atmel-hlcdc: destroy properly the plane state in the reset callback
Posted by Manikandan.M@microchip.com 1 month ago
On 18/12/25 6:56 pm, Ludovic Desroches wrote:
> If there is a plane state to destroy when doing a plane reset, destroy
> it using the atmel_hlcdc_plane_destroy_state() function. So we call
> __drm_atomic_helper_plane_destroy_state() and avoid code duplication.
> 
> Signed-off-by: Ludovic Desroches <ludovic.desroches@microchip.com>

Reviewed-by: Manikandan Muralidharan <manikandan.m@microchip.com>

> ---
>   drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 52 ++++++++++++-------------
>   1 file changed, 26 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
> index c1f3aaae29fb9f6b947f81e2fb4e7a61e10ac5d9..81dc730362322a4bae9b48dca97b06baa1e331e7 100644
> --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
> +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
> @@ -1155,32 +1155,6 @@ static int atmel_hlcdc_plane_alloc_dscrs(struct drm_plane *p,
>   	return -ENOMEM;
>   }
>   
> -static void atmel_hlcdc_plane_reset(struct drm_plane *p)
> -{
> -	struct atmel_hlcdc_plane_state *state;
> -
> -	if (p->state) {
> -		state = drm_plane_state_to_atmel_hlcdc_plane_state(p->state);
> -
> -		if (state->base.fb)
> -			drm_framebuffer_put(state->base.fb);
> -
> -		kfree(state);
> -		p->state = NULL;
> -	}
> -
> -	state = kzalloc(sizeof(*state), GFP_KERNEL);
> -	if (state) {
> -		if (atmel_hlcdc_plane_alloc_dscrs(p, state)) {
> -			kfree(state);
> -			drm_err(p->dev,
> -				"Failed to allocate initial plane state\n");
> -			return;
> -		}
> -		__drm_atomic_helper_plane_reset(p, &state->base);
> -	}
> -}
> -
>   static struct drm_plane_state *
>   atmel_hlcdc_plane_atomic_duplicate_state(struct drm_plane *p)
>   {
> @@ -1222,6 +1196,32 @@ static void atmel_hlcdc_plane_atomic_destroy_state(struct drm_plane *p,
>   	kfree(state);
>   }
>   
> +static void atmel_hlcdc_plane_reset(struct drm_plane *p)
> +{
> +	struct atmel_hlcdc_plane_state *state;
> +	struct atmel_hlcdc_dc *dc = p->dev->dev_private;
> +	struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p);
> +
> +	if (p->state) {
> +		atmel_hlcdc_plane_atomic_destroy_state(p, p->state);
> +		p->state = NULL;
> +	}
> +
> +	state = kzalloc(sizeof(*state), GFP_KERNEL);
> +	if (state) {
> +		if (atmel_hlcdc_plane_alloc_dscrs(p, state)) {
> +			kfree(state);
> +			drm_err(p->dev,
> +				"Failed to allocate initial plane state\n");
> +			return;
> +		}
> +		__drm_atomic_helper_plane_reset(p, &state->base);
> +	}
> +
> +	if (plane->layer.desc->layout.csc)
> +		dc->desc->ops->lcdc_csc_init(plane, plane->layer.desc);
> +}
> +
>   static const struct drm_plane_funcs layer_plane_funcs = {
>   	.update_plane = drm_atomic_helper_update_plane,
>   	.disable_plane = drm_atomic_helper_disable_plane,
> 

-- 
Thanks and Regards,
Manikandan M.