drm/virtio: Open-code drm_simple_encoder_init()
Subsystems (4)
PATCH 1/1 drm/virtio: Open-code drm_simple_encoder_init()
drm_simple_encoder_init() is a thin wrapper around drm_encoder_init() that only provides a minimal drm_encoder_funcs instance with .destroy = drm_encoder_cleanup.
Inline the helper in virtgpu_display.c and provide a local drm_encoder_funcs instance instead. This removes the unnecessary indirection and prepares for the eventual removal of drm_simple_encoder_init().
No functional changes intended.
--- drivers/gpu/drm/virtio/virtgpu_display.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_display.c +6 -1
@@ -232,6 +232,10 @@ static enum drm_mode_status virtio_gpu_conn_mode_valid(struct drm_connector *conreturn MODE_BAD ; } +static const struct drm_encoder_funcs virtio_gpu_enc_cleanup_funcs = { + .destroy = drm_encoder_cleanup +}; +static const struct drm_encoder_helper_funcs virtio_gpu_enc_helper_funcs = { .mode_set = virtio_gpu_enc_mode_set, .enable = virtio_gpu_enc_enable,
@@ -306,7 +310,8 @@ static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index)if (vgdev->has_edid)drm_connector_attach_edid_property (connector); -drm_simple_encoder_init (dev, encoder,DRM_MODE_ENCODER_VIRTUAL ); +drm_encoder_init (dev, encoder, &virtio_gpu_enc_cleanup_funcs, +DRM_MODE_ENCODER_VIRTUAL ,NULL );drm_encoder_helper_add (encoder, &virtio_gpu_enc_helper_funcs); encoder->possible_crtcs =1 << index;
Signature · 1 line
2.53.0
Thomas Zimmermann
maintainerHi
Am 27.02.26 um 11:35 schrieb Hardik Phalet:
Quoted 32 lines
drm_simple_encoder_init()is a thin wrapper arounddrm_encoder_init()that only provides a minimaldrm_encoder_funcsinstance with .destroy =drm_encoder_cleanup.Inline the helper in
virtgpu_display.cand provide a localdrm_encoder_funcsinstance instead. This removes the unnecessary indirection and prepares for the eventual removal ofdrm_simple_encoder_init().No functional changes intended.
Signed-off-by Hardik Phalet <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_display.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/drm/virtio/virtgpu_display.c +4
-0@@ -232,6 +232,10 @@ static enum drm_mode_status virtio_gpu_conn_mode_valid(struct drm_connector *conreturn MODE_BAD ; } +static const struct drm_encoder_funcs virtio_gpu_enc_cleanup_funcs = { + .destroy = drm_encoder_cleanup +}; +static const struct drm_encoder_helper_funcs virtio_gpu_enc_helper_funcs = { .mode_set = virtio_gpu_enc_mode_set, .enable = virtio_gpu_enc_enable,
drivers/gpu/drm/virtio/virtgpu_display.c static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index) · line 314
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_display.c +2
-1@@ -306,7 +310,8 @@ static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index)if (vgdev->has_edid)drm_connector_attach_edid_property (connector); -drm_simple_encoder_init (dev, encoder,DRM_MODE_ENCODER_VIRTUAL ); +drm_encoder_init (dev, encoder, &virtio_gpu_enc_cleanup_funcs, +DRM_MODE_ENCODER_VIRTUAL ,NULL );
This looks correct, but you should also remove the include statement at [1]
[1] https://elixir.bootlin.com/linux/v6.19/source/drivers/gpu/drm/virtio/virtgpu_display.c#L35
Best regards
Thomas
Quoted 3 lines
drivers/gpu/drm/virtio/virtgpu_display.c +0
-0drm_encoder_helper_add (encoder, &virtio_gpu_enc_helper_funcs); encoder->possible_crtcs =1 << index;
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Dmitry Osipenko
maintainerQuoted 46 lines · Thomas Zimmermann
Hi
Am 27.02.26 um 11:35 schrieb Hardik Phalet:
Quoted 34 lines
drm_simple_encoder_init()is a thin wrapper arounddrm_encoder_init()that only provides a minimaldrm_encoder_funcsinstance with .destroy =drm_encoder_cleanup.Inline the helper in
virtgpu_display.cand provide a localdrm_encoder_funcsinstance instead. This removes the unnecessary indirection and prepares for the eventual removal ofdrm_simple_encoder_init().No functional changes intended.
Signed-off-by Hardik Phalet <[email protected]>---
drivers/gpu/drm/virtio/virtgpu_display.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/ renamed from drivers/gpu/drm/virtio/virtgpu_display.c +0
-0
drm/virtio/virtgpu_display.c
indexf1dae9569805..8bd6cdc6c16e100644drivers/gpu/drm/virtio/virtgpu_display.c +0
-0@@ -232,6 +232,10 @@ static enum drm_mode_statusvirtio_gpu_conn_mode_valid(struct
drm_connector*con
returnMODE_BAD;
}
+static const structdrm_encoder_funcsvirtio_gpu_enc_cleanup_funcs= { + .destroy =drm_encoder_cleanupdrivers/gpu/drm/virtio/virtgpu_display.c +2
-0+}; +static const struct
drm_encoder_helper_funcsvirtio_gpu_enc_helper_funcs= {
.mode_set =virtio_gpu_enc_mode_set,
.enable =virtio_gpu_enc_enable,drivers/gpu/drm/virtio/virtgpu_display.c static int vgdev_output_init(struct · line 315
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_display.c +2
-0@@ -306,7 +310,8 @@ static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index) if (vgdev->has_edid) drm_connector_attach_edid_property(connector); - drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_VIRTUAL); + drm_encoder_init(dev, encoder, &virtio_gpu_enc_cleanup_funcs, + DRM_MODE_ENCODER_VIRTUAL, NULL);This looks correct, but you should also remove the include statement at [1]
Quoted 2 lines
[1] https://elixir.bootlin.com/linux/v6.19/source/drivers/gpu/drm/
virtio/virtgpu_display.c#L35
The patch adds more lines than removes. What's wrong with drm_simple_encoder_init() and why it needs to be removed eventually?
Signature · 2 lines
Best regards, Dmitry
Thomas Zimmermann
maintainerHi
Am 02.03.26 um 14:57 schrieb Dmitry Osipenko:
Quoted 46 lines · Thomas Zimmermann
Quoted 45 lines
Hi
Am 27.02.26 um 11:35 schrieb Hardik Phalet:
Quoted 34 lines
drm_simple_encoder_init()is a thin wrapper arounddrm_encoder_init()that only provides a minimaldrm_encoder_funcsinstance with .destroy =drm_encoder_cleanup.Inline the helper in
virtgpu_display.cand provide a localdrm_encoder_funcsinstance instead. This removes the unnecessary indirection and prepares for the eventual removal ofdrm_simple_encoder_init().No functional changes intended.
Signed-off-by Hardik Phalet <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_display.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/ renamed from drivers/gpu/drm/virtio/virtgpu_display.c +0
-0
drm/virtio/virtgpu_display.c
indexf1dae9569805..8bd6cdc6c16e100644drivers/gpu/drm/virtio/virtgpu_display.c +0
-0@@ -232,6 +232,10 @@ static enum drm_mode_statusvirtio_gpu_conn_mode_valid(struct
drm_connector*con
returnMODE_BAD;
}
+static const structdrm_encoder_funcsvirtio_gpu_enc_cleanup_funcs= {
+ .destroy =drm_encoder_cleanupdrivers/gpu/drm/virtio/virtgpu_display.c +2
-0+}; + static const struct drm_encoder_helper_funcs
virtio_gpu_enc_helper_funcs= {
.mode_set =virtio_gpu_enc_mode_set,
.enable =virtio_gpu_enc_enable,drivers/gpu/drm/virtio/virtgpu_display.c static int vgdev_output_init(struct · line 315
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_display.c +2
-0@@ -306,7 +310,8 @@ static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index) if (vgdev->has_edid) drm_connector_attach_edid_property(connector); - drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_VIRTUAL); + drm_encoder_init(dev, encoder, &virtio_gpu_enc_cleanup_funcs, + DRM_MODE_ENCODER_VIRTUAL, NULL);This looks correct, but you should also remove the include statement at [1]
Quoted 4 lines
Quoted 2 lines
[1] https://elixir.bootlin.com/linux/v6.19/source/drivers/gpu/drm/
virtio/virtgpu_display.c#L35The patch adds more lines than removes. What's wrong with
drm_simple_encoder_init()and why it needs to be removed eventually?
I added it myself a few years ago in an attempt to save some lines of code. That was a mistake. It's a helper without any purpose. Helpers should do something.
Best regards
Thomas
Quoted 1 line
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Dmitry Osipenko
maintainerQuoted 52 lines · Thomas Zimmermann
Hi
Am 02.03.26 um 14:57 schrieb Dmitry Osipenko:
Quoted 49 lines · Thomas Zimmermann
Quoted 48 lines
Hi
Am 27.02.26 um 11:35 schrieb Hardik Phalet:
Quoted 35 lines
drm_simple_encoder_init()is a thin wrapper arounddrm_encoder_init()that only provides a minimaldrm_encoder_funcsinstance with .destroy =drm_encoder_cleanup.Inline the helper in
virtgpu_display.cand provide a localdrm_encoder_funcsinstance instead. This removes the unnecessary indirection and prepares for the eventual removal ofdrm_simple_encoder_init().No functional changes intended.
Signed-off-by Hardik Phalet <[email protected]>---
drivers/gpu/drm/virtio/virtgpu_display.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/ renamed from drivers/gpu/drm/virtio/virtgpu_display.c +0
-0
drm/virtio/virtgpu_display.c
indexf1dae9569805..8bd6cdc6c16e100644drivers/gpu/drm/virtio/virtgpu_display.c +0
-0@@ -232,6 +232,10 @@ static enum drm_mode_statusvirtio_gpu_conn_mode_valid(struct
drm_connector*con returnMODE_BAD;
}
+static const structdrm_encoder_funcsvirtio_gpu_enc_cleanup_funcs= {
+ .destroy =drm_encoder_cleanupdrivers/gpu/drm/virtio/virtgpu_display.c +2
-0+}; +static const struct
drm_encoder_helper_funcsvirtio_gpu_enc_helper_funcs= {
.mode_set =virtio_gpu_enc_mode_set,
.enable =virtio_gpu_enc_enable,drivers/gpu/drm/virtio/virtgpu_display.c static int vgdev_output_init(struct · line 316
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_display.c +2
-0@@ -306,7 +310,8 @@ static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index) if (vgdev->has_edid) drm_connector_attach_edid_property(connector); - drm_simple_encoder_init(dev, encoder,DRM_MODE_ENCODER_VIRTUAL ); + drm_encoder_init(dev, encoder, &virtio_gpu_enc_cleanup_funcs, + DRM_MODE_ENCODER_VIRTUAL, NULL);This looks correct, but you should also remove the include statement at [1]
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
[1] https://elixir.bootlin.com/linux/v6.19/source/drivers/gpu/drm/
virtio/virtgpu_display.c#L35The patch adds more lines than removes. What's wrong with
drm_simple_encoder_init()and why it needs to be removed eventually?I added it myself a few years ago in an attempt to save some lines of code. That was a mistake. It's a helper without any purpose. Helpers should do something.
It saves few lines and makes code easier to read. Don't see value in removal of the helper.
Signature · 2 lines
Best regards, Dmitry
Thomas Zimmermann
maintainerAm 02.03.26 um 16:31 schrieb Dmitry Osipenko:
Quoted 55 lines · Thomas Zimmermann
Quoted 54 lines
Hi
Am 02.03.26 um 14:57 schrieb Dmitry Osipenko:
Quoted 51 lines · Thomas Zimmermann
Quoted 50 lines
Hi
Am 27.02.26 um 11:35 schrieb Hardik Phalet:
Quoted 35 lines
drm_simple_encoder_init()is a thin wrapper arounddrm_encoder_init()that only provides a minimaldrm_encoder_funcsinstance with .destroy =drm_encoder_cleanup.Inline the helper in
virtgpu_display.cand provide a localdrm_encoder_funcsinstance instead. This removes the unnecessary indirection and prepares for the eventual removal ofdrm_simple_encoder_init().No functional changes intended.
Signed-off-by Hardik Phalet <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_display.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/ renamed from drivers/gpu/drm/virtio/virtgpu_display.c +0
-0
drm/virtio/virtgpu_display.c
indexf1dae9569805..8bd6cdc6c16e100644drivers/gpu/drm/virtio/virtgpu_display.c +0
-0@@ -232,6 +232,10 @@ static enum drm_mode_statusvirtio_gpu_conn_mode_valid(struct
drm_connector*con
returnMODE_BAD;
}
+static const structdrm_encoder_funcsvirtio_gpu_enc_cleanup_funcs= {
+ .destroy =drm_encoder_cleanupdrivers/gpu/drm/virtio/virtgpu_display.c +2
-0+}; + static const struct drm_encoder_helper_funcs
virtio_gpu_enc_helper_funcs= {
.mode_set =virtio_gpu_enc_mode_set,
.enable =virtio_gpu_enc_enable,drivers/gpu/drm/virtio/virtgpu_display.c static int vgdev_output_init(struct · line 316
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_display.c +2
-0@@ -306,7 +310,8 @@ static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index) if (vgdev->has_edid) drm_connector_attach_edid_property(connector); - drm_simple_encoder_init(dev, encoder,DRM_MODE_ENCODER_VIRTUAL ); + drm_encoder_init(dev, encoder, &virtio_gpu_enc_cleanup_funcs, + DRM_MODE_ENCODER_VIRTUAL, NULL);This looks correct, but you should also remove the include statement at [1]
[1] https://elixir.bootlin.com/linux/v6.19/source/drivers/gpu/drm/
virtio/virtgpu_display.c#L35
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
The patch adds more lines than removes. What's wrong with
drm_simple_encoder_init()and why it needs to be removed eventually?I added it myself a few years ago in an attempt to save some lines of code. That was a mistake. It's a helper without any purpose. Helpers should do something.
It saves few lines and makes code easier to read. Don't see value in removal of the helper.
All it does is to set a default cleanup function. But that's not even clear from the helper's name.
If we really want a default cleanup, we should call drm_encoder_cleanup() as a default at [1]. Drivers could then just leave out the encoder funcs entirely.
[1] https://elixir.bootlin.com/linux/v6.19/source/drivers/gpu/drm/drm_mode_config.c#L530
Best regards
Thomas
Quoted 1 line
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Dmitry Osipenko
maintainerQuoted 69 lines · Thomas Zimmermann
Am 02.03.26 um 16:31 schrieb Dmitry Osipenko:
Quoted 55 lines · Thomas Zimmermann
Quoted 54 lines
Hi
Am 02.03.26 um 14:57 schrieb Dmitry Osipenko:
Quoted 51 lines · Thomas Zimmermann
Quoted 50 lines
Hi
Am 27.02.26 um 11:35 schrieb Hardik Phalet:
Quoted 35 lines
drm_simple_encoder_init()is a thin wrapper arounddrm_encoder_init()that only provides a minimaldrm_encoder_funcsinstance with .destroy =drm_encoder_cleanup.Inline the helper in
virtgpu_display.cand provide a localdrm_encoder_funcsinstance instead. This removes the unnecessary indirection and prepares for the eventual removal ofdrm_simple_encoder_init().No functional changes intended.
Signed-off-by Hardik Phalet <[email protected]>---
drivers/gpu/drm/virtio/virtgpu_display.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/ renamed from drivers/gpu/drm/virtio/virtgpu_display.c +0
-0
drm/virtio/virtgpu_display.c
indexf1dae9569805..8bd6cdc6c16e100644drivers/gpu/drm/virtio/virtgpu_display.c +0
-0@@ -232,6 +232,10 @@ static enum drm_mode_statusvirtio_gpu_conn_mode_valid(struct
drm_connector*con returnMODE_BAD;
}
+static const structdrm_encoder_funcsvirtio_gpu_enc_cleanup_funcs= {
+ .destroy =drm_encoder_cleanupdrivers/gpu/drm/virtio/virtgpu_display.c +2
-0+}; +static const struct
drm_encoder_helper_funcsvirtio_gpu_enc_helper_funcs= {
.mode_set =virtio_gpu_enc_mode_set,
.enable =virtio_gpu_enc_enable,drivers/gpu/drm/virtio/virtgpu_display.c static int vgdev_output_init(struct · line 316
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_display.c +2
-0@@ -306,7 +310,8 @@ static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index) if (vgdev->has_edid) drm_connector_attach_edid_property(connector); - drm_simple_encoder_init(dev, encoder,DRM_MODE_ENCODER_VIRTUAL ); + drm_encoder_init(dev, encoder, &virtio_gpu_enc_cleanup_funcs, + DRM_MODE_ENCODER_VIRTUAL, NULL);This looks correct, but you should also remove the include statement at [1]
[1] https://elixir.bootlin.com/linux/v6.19/source/drivers/gpu/drm/
virtio/virtgpu_display.c#L35Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
The patch adds more lines than removes. What's wrong with
drm_simple_encoder_init()and why it needs to be removed eventually?I added it myself a few years ago in an attempt to save some lines of code. That was a mistake. It's a helper without any purpose. Helpers should do something.
It saves few lines and makes code easier to read. Don't see value in removal of the helper.
All it does is to set a default cleanup function. But that's not even clear from the helper's name.
Quoted 6 lines
If we really want a default cleanup, we should call
drm_encoder_cleanup()as a default at [1]. Drivers could then just leave out the encoder funcs entirely.[1] https://elixir.bootlin.com/linux/v6.19/source/drivers/gpu/drm/
drm_mode_config.c#L530
There are a lot of drivers using drm_simple_encoder_init() in kernel. What problem the default cleanup function creates? If none, to me the drm_simple_encoder_init() serves its purpose, improving the drivers' code. I won't object much if you'll insist on merging the patch, but so far it looks like a very bikeshed change without a clear explanation of the solved problem.
Signature · 2 lines
Best regards, Dmitry