drm/virtio: Replace deprecated drm_simple_encoder_init()
Subsystems (4)
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
@@ -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
[email protected]
AI reviewThank 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
[ ... ]
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
Thomas Zimmermann
maintainerHi
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_displayby definingvirtio_gpu_encoder_funcswith the defaultdrm_encoder_cleanupcallback, and migrate directly todrm_encoder_init()Signed-off-by Davide Bonatto <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_display.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/gpu/drm/virtio/virtgpu_display.c +7
-1@@ -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)