Skip to contentSkip to conversation

drm/virtio: Replace deprecated drm_simple_encoder_init()

PATCH In review Davide Bonatto 3 participants 3 messages Sep 9

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/virtio: Replace deprecated drm_simple_encoder_init()

drm_simple_encoder_init() is deprecated as it introduces an unnecessary intermediate layer between atomic modesetting and DRM drivers.

Inline the helper call in virtgpu_display by defining virtio_gpu_encoder_funcs with the default drm_encoder_cleanup callback, and migrate directly to drm_encoder_init()

---
 drivers/gpu/drm/virtio/virtgpu_display.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_display.c +7 -1
index a1a875a0c706..85986578001f 100644
@@ -67,6 +67,10 @@ static const struct drm_framebuffer_funcs virtio_gpu_fb_funcs = {
 	.dirty = drm_atomic_helper_dirtyfb,
 };
 
+static const struct drm_encoder_funcs virtio_gpu_encoder_funcs = {
+	.destroy = drm_encoder_cleanup,
+};
+
 static int
 virtio_gpu_framebuffer_init(struct drm_device *dev,
 			    struct virtio_gpu_framebuffer *vgfb,
@@ -306,7 +310,9 @@ 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_encoder_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.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Missing error check for drm_encoder_init return value. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing error check for drm_encoder_init return value.
--

commit 731688e34b570f6cb070588f1d74f9b42481123c
Author: Davide Bonatto <[email protected]>

drm/virtio: Replace deprecated drm_simple_encoder_init()

This patch replaces the deprecated drm_simple_encoder_init() with a direct call to drm_encoder_init(), defining a default cleanup callback directly in virtio_gpu_encoder_funcs.

Quoted 4 lines
drivers/gpu/drm/virtio/virtgpu_display.c +0 -0
index a1a875a0c706a..85986578001fe 100644

[ ... ]

drivers/gpu/drm/virtio/virtgpu_display.c static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index) · line 314

Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_display.c +2 -1
@@ -306,7 +310,9 @@ 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_encoder_funcs,
+		DRM_MODE_ENCODER_VIRTUAL, NULL);

[Severity: Medium]
Does this code need to check the return value of drm_encoder_init()?

If drm_encoder_init() fails (for example, due to a memory allocation failure for the encoder name), it returns a negative error code like -ENOMEM and cleans up the partially initialized object.

Since this return value is not validated in vgdev_output_init(), the function will proceed to use the uninitialized encoder, attaching it to a connector and registering the connector with userspace. Could this lead to a NULL pointer dereference or corrupted state when the DRM subsystem interacts with it?

Quoted 4 lines
drivers/gpu/drm/virtio/virtgpu_display.c +1 -0
+
 	drm_encoder_helper_add(encoder, &virtio_gpu_enc_helper_funcs);
 	encoder->possible_crtcs = 1 << index;
 
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Davide Bonatto

Hi

Am 09.09.26 um 09:34 schrieb Davide Bonatto:

Quoted 2 lines

drm_simple_encoder_init() is deprecated as it introduces an unnecessary intermediate layer between atomic modesetting and DRM drivers.

This helper has meanwhile been removed entirely.

Best regards
Thomas

Quoted 36 lines

Inline the helper call in virtgpu_display by defining virtio_gpu_encoder_funcs with the default drm_encoder_cleanup callback, and migrate directly to drm_encoder_init()

---
  drivers/gpu/drm/virtio/virtgpu_display.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_display.c +7 -1
index a1a875a0c706..85986578001f 100644
@@ -67,6 +67,10 @@ static const struct drm_framebuffer_funcs virtio_gpu_fb_funcs = {
  	.dirty = drm_atomic_helper_dirtyfb,
  };
 
+static const struct drm_encoder_funcs virtio_gpu_encoder_funcs = {
+	.destroy = drm_encoder_cleanup,
+};
+
  static int
  virtio_gpu_framebuffer_init(struct drm_device *dev,
  			    struct virtio_gpu_framebuffer *vgfb,
@@ -306,7 +310,9 @@ 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_encoder_funcs,
+		DRM_MODE_ENCODER_VIRTUAL, NULL);
+
  	drm_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, (HRB 36809, AG Nürnberg)