Skip to contentSkip to conversation

drm/fb_dma: Add checks in drm_fb_dma_get_scanout_buffer()

PATCH In review Jocelyn Falempe 2 participants 3 messages Apr 26, 2024 – Apr 30, 2024

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

PATCH 1/1 drm/fb_dma: Add checks in drm_fb_dma_get_scanout_buffer()

plane->state and plane->state->fb can be NULL, so add a check before dereferencing them.
Found by testing with the imx driver.

Fixes 879b3b6511fe9 ("drm/fb_dma: Add generic get_scanout_buffer() for drm_panic")
---
 drivers/gpu/drm/drm_fb_dma_helper.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_fb_dma_helper.c +3 -0
index 96e5ab960f12..d7bffde94cc5 100644
@@ -167,6 +167,9 @@ int drm_fb_dma_get_scanout_buffer(struct drm_plane *plane,
 	struct drm_gem_dma_object *dma_obj;
 	struct drm_framebuffer *fb;
 
+	if (!plane->state || !plane->state->fb)
+		return -ENODEV;
+
 	fb = plane->state->fb;
 	/* Only support linear modifier */
 	if (fb->modifier != DRM_FORMAT_MOD_LINEAR)

base-commit: 2e3f08a1ac99cb9a19a5cb151593d4f9df5cc6a7

Signature · 1 line
2.44.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am 26.04.24 um 14:10 schrieb Jocelyn Falempe:

Quoted 15 lines

plane->state and plane->state->fb can be NULL, so add a check before dereferencing them.
Found by testing with the imx driver.

Fixes 879b3b6511fe9 ("drm/fb_dma: Add generic get_scanout_buffer() for drm_panic")
---
  drivers/gpu/drm/drm_fb_dma_helper.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_fb_dma_helper.c +0 -0
index 96e5ab960f12..d7bffde94cc5 100644

drivers/gpu/drm/drm_fb_dma_helper.c int drm_fb_dma_get_scanout_buffer(struct drm_plane *plane, · line 172

Quoted 6 lines
drivers/gpu/drm/drm_fb_dma_helper.c +3 -0
@@ -167,6 +167,9 @@ int drm_fb_dma_get_scanout_buffer(struct drm_plane *plane,
  	struct drm_gem_dma_object *dma_obj;
  	struct drm_framebuffer *fb;
 
+	if (!plane->state || !plane->state->fb)
+		return -ENODEV;
+

It's EINVAL here. With that fixed, free free to add

Best regards
Thomas

Quoted 5 lines
drivers/gpu/drm/drm_fb_dma_helper.c +0 -0
  	fb = plane->state->fb;
  	/* Only support linear modifier */
  	if (fb->modifier != DRM_FORMAT_MOD_LINEAR)

base-commit: 2e3f08a1ac99cb9a19a5cb151593d4f9df5cc6a7

Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#2 lore raw
Quoted 13 lines · Thomas Zimmermann

Am 26.04.24 um 14:10 schrieb Jocelyn Falempe:

Quoted 10 lines

plane->state and plane->state->fb can be NULL, so add a check before dereferencing them.
Found by testing with the imx driver.

Fixes 879b3b6511fe9 ("drm/fb_dma: Add generic get_scanout_buffer() for drm_panic")

---
  drivers/gpu/drm/drm_fb_dma_helper.c | 3 +++

  1 file changed, 3 insertions(+)
Quoted 13 lines

drivers/gpu/drm/drm_fb_dma_helper.c int drm_fb_dma_get_scanout_buffer(struct drm_plane · line 172

Quoted 11 lines
drivers/gpu/drm/drm_fb_dma_helper.c +3 -0
index 96e5ab960f12..d7bffde94cc5 100644
@@ -167,6 +167,9 @@ int drm_fb_dma_get_scanout_buffer(struct drm_plane 
 *plane,
       struct drm_gem_dma_object *dma_obj;
       struct drm_framebuffer *fb;
+    if (!plane->state || !plane->state->fb)
+        return -ENODEV;
+

It's EINVAL here. With that fixed, free free to add

Thanks, I just merged it to drm-misc-next with that fixed.

Quoted 12 lines

Best regards
Thomas

Quoted 5 lines
drivers/gpu/drm/drm_fb_dma_helper.c +0 -0
       fb = plane->state->fb;
       /* Only support linear modifier */
       if (fb->modifier != DRM_FORMAT_MOD_LINEAR)

base-commit: 2e3f08a1ac99cb9a19a5cb151593d4f9df5cc6a7

Signature · 1 line
Jocelyn