drm/virtio: Fix NULL vs IS_ERR checking in virtio_gpu_object_shmem_init
Subsystems (4)
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.
---
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
@@ -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
Quoted 5 lines · Miaoqian Lin
Since
drm_prime_pages_to_sg()function return error pointers. Thedrm_gem_shmem_get_sg_table()function returns error pointers too. UsingIS_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")Signed-off-by Miaoqian Lin <[email protected]>---
changes in v2:
- Update Fixes tag.
- rebase the working tree.
v1 Link: https://lore.kernel.org/all/[email protected]/
Dmitry Osipenko
maintainerQuoted 21 lines · Miaoqian Lin
Since
drm_prime_pages_to_sg()function return error pointers. Thedrm_gem_shmem_get_sg_table()function returns error pointers too. UsingIS_ERR()to check the return value to fix this.Fixes 2f2aa13724d5 ("drm/virtio: move virtio_gpu_mem_entry initialization to new function")Signed-off-by Miaoqian Lin <[email protected]>---
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@@ -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