Skip to contentSkip to conversation

drm/virtio: Fix an NULL vs IS_ERR() bug in virtio_gpu_object_shmem_init()

PATCH In review Dan Carpenter 2 participants 2 messages Nov 18, 2021 – Nov 23, 2021

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

PATCH v2 1/1 drm/virtio: Fix an NULL vs IS_ERR() bug in virtio_gpu_object_shmem_init()

The drm_gem_shmem_get_sg_table() function never returns NULL. It returns error pointers on error.

Fixes c66df701e783 ("drm/virtio: switch from ttm to gem shmem helpers")

---
v2: I originally sent this patch on 19 Jun 2020 but it was somehow
not applied. As I review it now, I see that the bug is actually older than I originally thought and so I have updated the Fixes tag.

 drivers/gpu/drm/virtio/virtgpu_object.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_object.c +2 -2
index f648b0e24447..8bb80289672c 100644
@@ -168,9 +168,9 @@ static int virtio_gpu_object_shmem_init(struct virtio_gpu_device *vgdev,
 	 * since virtio_gpu doesn't support dma-buf import from other devices.
 	 */
 	shmem->pages = drm_gem_shmem_get_sg_table(&bo->base.base);
-	if (!shmem->pages) {
+	if (IS_ERR(shmem->pages)) {
 		drm_gem_shmem_unpin(&bo->base.base);
-		return -EINVAL;
+		return PTR_ERR(shmem->pages);
 	}
 
 	if (use_dma_api) {
Signature · 1 line
2.20.1
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Dan Carpenter

The drm_gem_shmem_get_sg_table() function never returns NULL. It returns error pointers on error.

Fixes c66df701e783 ("drm/virtio: switch from ttm to gem shmem helpers")

---
v2: I originally sent this patch on 19 Jun 2020 but it was somehow
not applied. As I review it now, I see that the bug is actually older than I originally thought and so I have updated the Fixes tag.