diff mbox series

[RFC,2/4] drm/vkms: Switch to managed for encoder

Message ID 20240814-google-vkms-managed-v1-2-7ab8b8921103@bootlin.com (mailing list archive)
State New, archived
Headers show
Series drm/vkms: Switch all vkms object to DRM managed objects | expand

Commit Message

Louis Chauvet Aug. 14, 2024, 10:06 a.m. UTC
The current VKMS driver uses non-managed function to create encoders. It
is not an issue yet, but in order to support multiple devices easly,
convert this code to use drm and device managed helpers.

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
 drivers/gpu/drm/vkms/vkms_drv.h    |  1 -
 drivers/gpu/drm/vkms/vkms_output.c | 21 +++++++++------------
 2 files changed, 9 insertions(+), 13 deletions(-)

Comments

José Expósito Aug. 20, 2024, 9:09 a.m. UTC | #1
> The current VKMS driver uses non-managed function to create encoders. It
> is not an issue yet, but in order to support multiple devices easly,

s/easly/easily

> convert this code to use drm and device managed helpers.
> 
> Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>

Reviewed-by: José Expósito <jose.exposito89@gmail.com>

> ---
>  drivers/gpu/drm/vkms/vkms_drv.h    |  1 -
>  drivers/gpu/drm/vkms/vkms_output.c | 21 +++++++++------------
>  2 files changed, 9 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
> index cea7b2640c5d..2c9d1f20ce84 100644
> --- a/drivers/gpu/drm/vkms/vkms_drv.h
> +++ b/drivers/gpu/drm/vkms/vkms_drv.h
> @@ -42,7 +42,6 @@
>   */
>  struct vkms_output {
>  	struct drm_crtc crtc;
> -	struct drm_encoder encoder;
>  	struct drm_writeback_connector wb_connector;
>  	struct hrtimer vblank_hrtimer;
>  	ktime_t period_ns;
> diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c
> index 4767838c3a73..cb8507917b5f 100644
> --- a/drivers/gpu/drm/vkms/vkms_output.c
> +++ b/drivers/gpu/drm/vkms/vkms_output.c
> @@ -16,9 +16,7 @@ static const struct drm_connector_funcs vkms_connector_funcs = {
>  	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
>  };
>  
> -static const struct drm_encoder_funcs vkms_encoder_funcs = {
> -	.destroy = drm_encoder_cleanup,
> -};
> +static const struct drm_encoder_funcs vkms_encoder_funcs = {};

This struct is not required, drmm_encoder_init() can take a NULL value.

>  
>  static int vkms_conn_get_modes(struct drm_connector *connector)
>  {
> @@ -55,7 +53,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int possible_crtc_index)
>  	struct vkms_output *output = &vkmsdev->output;
>  	struct drm_device *dev = &vkmsdev->drm;
>  	struct drm_connector *connector;
> -	struct drm_encoder *encoder = &output->encoder;
> +	struct drm_encoder *encoder;
>  	struct drm_crtc *crtc = &output->crtc;
>  	struct vkms_plane *primary, *cursor = NULL;
>  	int ret;
> @@ -103,8 +101,12 @@ int vkms_output_init(struct vkms_device *vkmsdev, int possible_crtc_index)
>  
>  	drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
>  
> -	ret = drm_encoder_init(dev, encoder, &vkms_encoder_funcs,
> -			       DRM_MODE_ENCODER_VIRTUAL, NULL);
> +	encoder = drmm_kzalloc(&vkmsdev->drm, sizeof(*encoder), GFP_KERNEL);

&vkmsdev->drm => dev

> +	if (!encoder)

The same here, we could log this error:
		DRM_ERROR("Failed to allocate encoder\n");

> +		return -ENOMEM;
> +
> +	ret = drmm_encoder_init(dev, encoder, &vkms_encoder_funcs,

vkms_encoder_funcs can be NULL.

> +				DRM_MODE_ENCODER_VIRTUAL, NULL);
>  	if (ret) {
>  		DRM_ERROR("Failed to init encoder\n");
>  		return ret;
> @@ -118,7 +120,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int possible_crtc_index)
>  	ret = drm_connector_attach_encoder(connector, encoder);
>  	if (ret) {
>  		DRM_ERROR("Failed to attach connector to encoder\n");
> -		goto err_attach;
> +		return ret;
>  	}
>  
>  	if (vkmsdev->config->writeback) {
> @@ -130,9 +132,4 @@ int vkms_output_init(struct vkms_device *vkmsdev, int possible_crtc_index)
>  	drm_mode_config_reset(dev);
>  
>  	return 0;
> -
> -err_attach:
> -	drm_encoder_cleanup(encoder);
> -
> -	return ret;
>  }
Louis Chauvet Aug. 26, 2024, 4:24 p.m. UTC | #2
Le 20/08/24 - 11:09, José Expósito a écrit :
> > The current VKMS driver uses non-managed function to create encoders. It
> > is not an issue yet, but in order to support multiple devices easly,
> 
> s/easly/easily
> 
> > convert this code to use drm and device managed helpers.
> > 
> > Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
> 
> Reviewed-by: José Expósito <jose.exposito89@gmail.com>

Thanks!
 
> > ---
> >  drivers/gpu/drm/vkms/vkms_drv.h    |  1 -
> >  drivers/gpu/drm/vkms/vkms_output.c | 21 +++++++++------------
> >  2 files changed, 9 insertions(+), 13 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
> > index cea7b2640c5d..2c9d1f20ce84 100644
> > --- a/drivers/gpu/drm/vkms/vkms_drv.h
> > +++ b/drivers/gpu/drm/vkms/vkms_drv.h
> > @@ -42,7 +42,6 @@
> >   */
> >  struct vkms_output {
> >  	struct drm_crtc crtc;
> > -	struct drm_encoder encoder;
> >  	struct drm_writeback_connector wb_connector;
> >  	struct hrtimer vblank_hrtimer;
> >  	ktime_t period_ns;
> > diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c
> > index 4767838c3a73..cb8507917b5f 100644
> > --- a/drivers/gpu/drm/vkms/vkms_output.c
> > +++ b/drivers/gpu/drm/vkms/vkms_output.c
> > @@ -16,9 +16,7 @@ static const struct drm_connector_funcs vkms_connector_funcs = {
> >  	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
> >  };
> >  
> > -static const struct drm_encoder_funcs vkms_encoder_funcs = {
> > -	.destroy = drm_encoder_cleanup,
> > -};
> > +static const struct drm_encoder_funcs vkms_encoder_funcs = {};
> 
> This struct is not required, drmm_encoder_init() can take a NULL value.
> 
> >  
> >  static int vkms_conn_get_modes(struct drm_connector *connector)
> >  {
> > @@ -55,7 +53,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int possible_crtc_index)
> >  	struct vkms_output *output = &vkmsdev->output;
> >  	struct drm_device *dev = &vkmsdev->drm;
> >  	struct drm_connector *connector;
> > -	struct drm_encoder *encoder = &output->encoder;
> > +	struct drm_encoder *encoder;
> >  	struct drm_crtc *crtc = &output->crtc;
> >  	struct vkms_plane *primary, *cursor = NULL;
> >  	int ret;
> > @@ -103,8 +101,12 @@ int vkms_output_init(struct vkms_device *vkmsdev, int possible_crtc_index)
> >  
> >  	drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
> >  
> > -	ret = drm_encoder_init(dev, encoder, &vkms_encoder_funcs,
> > -			       DRM_MODE_ENCODER_VIRTUAL, NULL);
> > +	encoder = drmm_kzalloc(&vkmsdev->drm, sizeof(*encoder), GFP_KERNEL);
> 
> &vkmsdev->drm => dev
> 
> > +	if (!encoder)
> 
> The same here, we could log this error:
> 		DRM_ERROR("Failed to allocate encoder\n");
> 
> > +		return -ENOMEM;
> > +
> > +	ret = drmm_encoder_init(dev, encoder, &vkms_encoder_funcs,
> 
> vkms_encoder_funcs can be NULL.
> 
> > +				DRM_MODE_ENCODER_VIRTUAL, NULL);
> >  	if (ret) {
> >  		DRM_ERROR("Failed to init encoder\n");
> >  		return ret;
> > @@ -118,7 +120,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int possible_crtc_index)
> >  	ret = drm_connector_attach_encoder(connector, encoder);
> >  	if (ret) {
> >  		DRM_ERROR("Failed to attach connector to encoder\n");
> > -		goto err_attach;
> > +		return ret;
> >  	}
> >  
> >  	if (vkmsdev->config->writeback) {
> > @@ -130,9 +132,4 @@ int vkms_output_init(struct vkms_device *vkmsdev, int possible_crtc_index)
> >  	drm_mode_config_reset(dev);
> >  
> >  	return 0;
> > -
> > -err_attach:
> > -	drm_encoder_cleanup(encoder);
> > -
> > -	return ret;
> >  }
diff mbox series

Patch

diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index cea7b2640c5d..2c9d1f20ce84 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -42,7 +42,6 @@ 
  */
 struct vkms_output {
 	struct drm_crtc crtc;
-	struct drm_encoder encoder;
 	struct drm_writeback_connector wb_connector;
 	struct hrtimer vblank_hrtimer;
 	ktime_t period_ns;
diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c
index 4767838c3a73..cb8507917b5f 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -16,9 +16,7 @@  static const struct drm_connector_funcs vkms_connector_funcs = {
 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 };
 
-static const struct drm_encoder_funcs vkms_encoder_funcs = {
-	.destroy = drm_encoder_cleanup,
-};
+static const struct drm_encoder_funcs vkms_encoder_funcs = {};
 
 static int vkms_conn_get_modes(struct drm_connector *connector)
 {
@@ -55,7 +53,7 @@  int vkms_output_init(struct vkms_device *vkmsdev, int possible_crtc_index)
 	struct vkms_output *output = &vkmsdev->output;
 	struct drm_device *dev = &vkmsdev->drm;
 	struct drm_connector *connector;
-	struct drm_encoder *encoder = &output->encoder;
+	struct drm_encoder *encoder;
 	struct drm_crtc *crtc = &output->crtc;
 	struct vkms_plane *primary, *cursor = NULL;
 	int ret;
@@ -103,8 +101,12 @@  int vkms_output_init(struct vkms_device *vkmsdev, int possible_crtc_index)
 
 	drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
 
-	ret = drm_encoder_init(dev, encoder, &vkms_encoder_funcs,
-			       DRM_MODE_ENCODER_VIRTUAL, NULL);
+	encoder = drmm_kzalloc(&vkmsdev->drm, sizeof(*encoder), GFP_KERNEL);
+	if (!encoder)
+		return -ENOMEM;
+
+	ret = drmm_encoder_init(dev, encoder, &vkms_encoder_funcs,
+				DRM_MODE_ENCODER_VIRTUAL, NULL);
 	if (ret) {
 		DRM_ERROR("Failed to init encoder\n");
 		return ret;
@@ -118,7 +120,7 @@  int vkms_output_init(struct vkms_device *vkmsdev, int possible_crtc_index)
 	ret = drm_connector_attach_encoder(connector, encoder);
 	if (ret) {
 		DRM_ERROR("Failed to attach connector to encoder\n");
-		goto err_attach;
+		return ret;
 	}
 
 	if (vkmsdev->config->writeback) {
@@ -130,9 +132,4 @@  int vkms_output_init(struct vkms_device *vkmsdev, int possible_crtc_index)
 	drm_mode_config_reset(dev);
 
 	return 0;
-
-err_attach:
-	drm_encoder_cleanup(encoder);
-
-	return ret;
 }