dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH drm/hisilicon 2/2] drm/hisilicon: Code refactoring for hibmc_drv_de
@ 2020-07-31  1:05 Tian Tao
  2020-07-31  7:47 ` Thomas Zimmermann
  0 siblings, 1 reply; 2+ messages in thread
From: Tian Tao @ 2020-07-31  1:05 UTC (permalink / raw)
  To: airlied, daniel, tzimmermann, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, linux-kernel
  Cc: linuxarm

code refactoring for hibmc_drv_de.c, no actual function changes.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c  | 55 ++++++-------------------
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h |  2 +
 2 files changed, 15 insertions(+), 42 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
index 66132eb..af24c72 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
@@ -157,37 +157,6 @@ static const struct drm_plane_helper_funcs hibmc_plane_helper_funcs = {
 	.atomic_update = hibmc_plane_atomic_update,
 };
 
-static struct drm_plane *hibmc_plane_init(struct hibmc_drm_private *priv)
-{
-	struct drm_device *dev = priv->dev;
-	struct drm_plane *plane;
-	int ret = 0;
-
-	plane = devm_kzalloc(dev->dev, sizeof(*plane), GFP_KERNEL);
-	if (!plane) {
-		DRM_ERROR("failed to alloc memory when init plane\n");
-		return ERR_PTR(-ENOMEM);
-	}
-	/*
-	 * plane init
-	 * TODO: Now only support primary plane, overlay planes
-	 * need to do.
-	 */
-	ret = drm_universal_plane_init(dev, plane, 1, &hibmc_plane_funcs,
-				       channel_formats1,
-				       ARRAY_SIZE(channel_formats1),
-				       NULL,
-				       DRM_PLANE_TYPE_PRIMARY,
-				       NULL);
-	if (ret) {
-		DRM_ERROR("failed to init plane: %d\n", ret);
-		return ERR_PTR(ret);
-	}
-
-	drm_plane_helper_add(plane, &hibmc_plane_helper_funcs);
-	return plane;
-}
-
 static void hibmc_crtc_dpms(struct drm_crtc *crtc, int dpms)
 {
 	struct hibmc_drm_private *priv = crtc->dev->dev_private;
@@ -534,22 +503,24 @@ static const struct drm_crtc_helper_funcs hibmc_crtc_helper_funcs = {
 int hibmc_de_init(struct hibmc_drm_private *priv)
 {
 	struct drm_device *dev = priv->dev;
-	struct drm_crtc *crtc;
-	struct drm_plane *plane;
+	struct drm_crtc *crtc = &priv->crtc;
+	struct drm_plane *plane = &priv->plane;
 	int ret;
 
-	plane = hibmc_plane_init(priv);
-	if (IS_ERR(plane)) {
-		DRM_ERROR("failed to create plane: %ld\n", PTR_ERR(plane));
-		return PTR_ERR(plane);
-	}
+	ret = drm_universal_plane_init(dev, plane, 1, &hibmc_plane_funcs,
+				       channel_formats1,
+				       ARRAY_SIZE(channel_formats1),
+				       NULL,
+				       DRM_PLANE_TYPE_PRIMARY,
+				       NULL);
 
-	crtc = devm_kzalloc(dev->dev, sizeof(*crtc), GFP_KERNEL);
-	if (!crtc) {
-		DRM_ERROR("failed to alloc memory when init crtc\n");
-		return -ENOMEM;
+	if (ret) {
+		DRM_ERROR("failed to init plane: %d\n", ret);
+		return ret;
 	}
 
+	drm_plane_helper_add(plane, &hibmc_plane_helper_funcs);
+
 	ret = drm_crtc_init_with_planes(dev, crtc, plane,
 					NULL, &hibmc_crtc_funcs, NULL);
 	if (ret) {
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
index a683763..91ef15c 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
@@ -28,6 +28,8 @@ struct hibmc_drm_private {
 
 	/* drm */
 	struct drm_device  *dev;
+	struct drm_plane plane;
+	struct drm_crtc crtc;
 	struct drm_encoder encoder;
 	struct drm_connector connector;
 	bool mode_config_initialized;
-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH drm/hisilicon 2/2] drm/hisilicon: Code refactoring for hibmc_drv_de
  2020-07-31  1:05 [PATCH drm/hisilicon 2/2] drm/hisilicon: Code refactoring for hibmc_drv_de Tian Tao
@ 2020-07-31  7:47 ` Thomas Zimmermann
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Zimmermann @ 2020-07-31  7:47 UTC (permalink / raw)
  To: Tian Tao, airlied, daniel, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, linux-kernel
  Cc: linuxarm


[-- Attachment #1.1.1: Type: text/plain, Size: 4499 bytes --]

Hi

Am 31.07.20 um 03:05 schrieb Tian Tao:
> code refactoring for hibmc_drv_de.c, no actual function changes.

No, there's tons of functional changes. The memory used to be allocated
with devres helpers and released automatically. In rare circumstances,
the memory's release could have happened before the DRM device got
released, which would have caused memory corruption of some kind.

Now you're embedding the data structures in struct hibmc_drm_private,
which is good. The whole release problem has been resolved, because
struct hibmc_drm_private is allocated with drmm_kzalloc and always
released with the DRM device. You're commit message should mention all this.

> 
> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
> ---
>  drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c  | 55 ++++++-------------------
>  drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h |  2 +
>  2 files changed, 15 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> index 66132eb..af24c72 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> @@ -157,37 +157,6 @@ static const struct drm_plane_helper_funcs hibmc_plane_helper_funcs = {
>  	.atomic_update = hibmc_plane_atomic_update,
>  };
>  
> -static struct drm_plane *hibmc_plane_init(struct hibmc_drm_private *priv)
> -{
> -	struct drm_device *dev = priv->dev;
> -	struct drm_plane *plane;
> -	int ret = 0;
> -
> -	plane = devm_kzalloc(dev->dev, sizeof(*plane), GFP_KERNEL);
> -	if (!plane) {
> -		DRM_ERROR("failed to alloc memory when init plane\n");
> -		return ERR_PTR(-ENOMEM);
> -	}
> -	/*
> -	 * plane init
> -	 * TODO: Now only support primary plane, overlay planes
> -	 * need to do.
> -	 */
> -	ret = drm_universal_plane_init(dev, plane, 1, &hibmc_plane_funcs,
> -				       channel_formats1,
> -				       ARRAY_SIZE(channel_formats1),
> -				       NULL,
> -				       DRM_PLANE_TYPE_PRIMARY,
> -				       NULL);
> -	if (ret) {
> -		DRM_ERROR("failed to init plane: %d\n", ret);
> -		return ERR_PTR(ret);
> -	}
> -
> -	drm_plane_helper_add(plane, &hibmc_plane_helper_funcs);
> -	return plane;
> -}
> -
>  static void hibmc_crtc_dpms(struct drm_crtc *crtc, int dpms)
>  {
>  	struct hibmc_drm_private *priv = crtc->dev->dev_private;
> @@ -534,22 +503,24 @@ static const struct drm_crtc_helper_funcs hibmc_crtc_helper_funcs = {
>  int hibmc_de_init(struct hibmc_drm_private *priv)
>  {
>  	struct drm_device *dev = priv->dev;
> -	struct drm_crtc *crtc;
> -	struct drm_plane *plane;
> +	struct drm_crtc *crtc = &priv->crtc;
> +	struct drm_plane *plane = &priv->plane;
>  	int ret;
>  
> -	plane = hibmc_plane_init(priv);
> -	if (IS_ERR(plane)) {
> -		DRM_ERROR("failed to create plane: %ld\n", PTR_ERR(plane));
> -		return PTR_ERR(plane);
> -	}
> +	ret = drm_universal_plane_init(dev, plane, 1, &hibmc_plane_funcs,
> +				       channel_formats1,
> +				       ARRAY_SIZE(channel_formats1),
> +				       NULL,
> +				       DRM_PLANE_TYPE_PRIMARY,
> +				       NULL);
>  
> -	crtc = devm_kzalloc(dev->dev, sizeof(*crtc), GFP_KERNEL);
> -	if (!crtc) {
> -		DRM_ERROR("failed to alloc memory when init crtc\n");
> -		return -ENOMEM;
> +	if (ret) {
> +		DRM_ERROR("failed to init plane: %d\n", ret);
> +		return ret;
>  	}
>  
> +	drm_plane_helper_add(plane, &hibmc_plane_helper_funcs);
> +
>  	ret = drm_crtc_init_with_planes(dev, crtc, plane,
>  					NULL, &hibmc_crtc_funcs, NULL);
>  	if (ret) {
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
> index a683763..91ef15c 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
> @@ -28,6 +28,8 @@ struct hibmc_drm_private {
>  
>  	/* drm */
>  	struct drm_device  *dev;
> +	struct drm_plane plane;

There was a TODO comment that mentioned overlay planes. I suggest
calling this field primary_plane, so it's clear which plane it represents.

Best regards
Thomas

> +	struct drm_crtc crtc;
>  	struct drm_encoder encoder;
>  	struct drm_connector connector;
>  	bool mode_config_initialized;
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 516 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-31  7:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31  1:05 [PATCH drm/hisilicon 2/2] drm/hisilicon: Code refactoring for hibmc_drv_de Tian Tao
2020-07-31  7:47 ` Thomas Zimmermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).