Skip to contentSkip to conversation

drm/virtio: Fix NULL vs IS_ERR checking in virtio_gpu_object_shmem_init

PATCH In review Miaoqian Lin 3 participants 3 messages Jun 2, 2022 – Jun 29, 2022

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

PATCH v2 1/1 drm/virtio: Fix NULL vs IS_ERR checking in virtio_gpu_object_shmem_init

Since drm_prime_pages_to_sg() function return error pointers. The drm_gem_shmem_get_sg_table() function returns error pointers too. Using IS_ERR() to check the return value to fix this.

Fixes 2f2aa13724d5 ("drm/virtio: move virtio_gpu_mem_entry initialization to new function")

---
changes in v2:
- Update Fixes tag.
- rebase the working tree.
v1 Link: https://lore.kernel.org/all/[email protected]/

---
 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 f293e6ad52da..1cc8f3fc8e4b 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);
-	if (!shmem->pages) {
+	if (IS_ERR(shmem->pages)) {
 		drm_gem_shmem_unpin(&bo->base);
-		return -EINVAL;
+		return PTR_ERR(shmem->pages);
 	}
 
 	if (use_dma_api) {
Signature · 1 line
2.25.1
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Miaoqian Lin

Since drm_prime_pages_to_sg() function return error pointers. The drm_gem_shmem_get_sg_table() function returns error pointers too. Using IS_ERR() to check the return value to fix this.

Quoted 7 lines
Fixes 2f2aa13724d5 ("drm/virtio: move virtio_gpu_mem_entry initialization to new function")

---
changes in v2:
- Update Fixes tag.
- rebase the working tree.
v1 Link: https://lore.kernel.org/all/[email protected]/

maintainer
#2 lore raw
In reply to Miaoqian Lin
Quoted 21 lines · Miaoqian Lin

Since drm_prime_pages_to_sg() function return error pointers. The drm_gem_shmem_get_sg_table() function returns error pointers too. Using IS_ERR() to check the return value to fix this.

Fixes 2f2aa13724d5 ("drm/virtio: move virtio_gpu_mem_entry initialization to new function")

---
changes in v2:
- Update Fixes tag.
- rebase the working tree.
v1 Link: https://lore.kernel.org/all/[email protected]/

---
 drivers/gpu/drm/virtio/virtgpu_object.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_object.c +0 -0
index f293e6ad52da..1cc8f3fc8e4b 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.

drivers/gpu/drm/virtio/virtgpu_object.c static int virtio_gpu_object_shmem_init(struct virtio_gpu_device *vgdev, · line 176

Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_object.c +2 -2
 	 */
 	shmem->pages = drm_gem_shmem_get_sg_table(&bo->base);
-	if (!shmem->pages) {
+	if (IS_ERR(shmem->pages)) {
 		drm_gem_shmem_unpin(&bo->base);
-		return -EINVAL;
+		return PTR_ERR(shmem->pages);
 	}
 
 	if (use_dma_api) {

Sorry for noticing this late. This patch is incorrect because shmem->pages must be NULLed on error, otherwise virtio_gpu_cleanup_object() will crash :/

I also had a patch that fixes this problem [1] and it did it properly. I see that this patch is in -next already, so will update my patch to fix the fix now.

[1]
https://vanko.io/project/dri-devel/patch/[email protected]/

Signature · 2 lines
Best regards,
Dmitry