Skip to contentSkip to conversation

drm/virtio: Fix a NULL vs ERR_PTR() bug in virtio_gpu_user_framebuffer_create()

PATCH Applied Dan Carpenter 2 participants 2 messages Aug 13 – Aug 14

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

PATCH 1/1 drm/virtio: Fix a NULL vs ERR_PTR() bug in virtio_gpu_user_framebuffer_create()

Smatch complains that returning a NULL here will lead to a NULL pointer dereference in drm_mode_addfb2(). Return an error pointer instead.

Fixes dc5698e80cf7 ("Add virtio gpu driver.")

---
This code is obviously over a decade old. I think this patch is correct. None of the other implementations return NULL, but I haven't tested it.

---
 drivers/gpu/drm/virtio/virtgpu_display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_display.c +1 -1
index 44ffffec550f..85ea252c658e 100644
@@ -344,7 +344,7 @@ virtio_gpu_user_framebuffer_create(struct drm_device *dev,
 	if (ret) {
 		kfree(virtio_gpu_fb);
 		drm_gem_object_put(obj);
-		return NULL;
+		return ERR_PTR(ret);
 	}
 
 	return &virtio_gpu_fb->base;
Signature · 1 line
2.53.0
maintainer Applied
#1 lore raw
Quoted 17 lines · Dan Carpenter

Smatch complains that returning a NULL here will lead to a NULL pointer dereference in drm_mode_addfb2(). Return an error pointer instead.

Fixes dc5698e80cf7 ("Add virtio gpu driver.")

---
This code is obviously over a decade old. I think this patch is correct. None of the other implementations return NULL, but I haven't tested it.

---
 drivers/gpu/drm/virtio/virtgpu_display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_display.c +0 -0
index 44ffffec550f..85ea252c658e 100644

drivers/gpu/drm/virtio/virtgpu_display.c virtio_gpu_user_framebuffer_create(struct drm_device *dev, · line 350

Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_display.c +1 -1
@@ -344,7 +344,7 @@ virtio_gpu_user_framebuffer_create(struct drm_device *dev,
 	if (ret) {
 		kfree(virtio_gpu_fb);
 		drm_gem_object_put(obj);
-		return NULL;
+		return ERR_PTR(ret);
 	}
 
 	return &virtio_gpu_fb->base;

Applied to drm-misc-fixes, thanks!

Signature · 2 lines
Best regards,
Dmitry