diff mbox series

[v2] drm/virtio: Fix NULL vs IS_ERR checking in virtio_gpu_object_shmem_init

Message ID 20220602104223.54527-1-linmq006@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2] drm/virtio: Fix NULL vs IS_ERR checking in virtio_gpu_object_shmem_init | expand

Commit Message

Miaoqian Lin June 2, 2022, 10:42 a.m. UTC
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")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
changes in v2:
- Update Fixes tag.
- rebase the working tree.
v1 Link: https://lore.kernel.org/all/20211222072649.18169-1-linmq006@gmail.com/
---
 drivers/gpu/drm/virtio/virtgpu_object.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Chia-I Wu June 12, 2022, 4:11 a.m. UTC | #1
On Thu, Jun 2, 2022 at 3:42 AM Miaoqian Lin <linmq006@gmail.com> wrote:
>
> 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")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> changes in v2:
> - Update Fixes tag.
> - rebase the working tree.
> v1 Link: https://lore.kernel.org/all/20211222072649.18169-1-linmq006@gmail.com/
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Dmitry Osipenko June 29, 2022, 10:15 p.m. UTC | #2
On 6/2/22 13:42, Miaoqian Lin wrote:
> 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")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> changes in v2:
> - Update Fixes tag.
> - rebase the working tree.
> v1 Link: https://lore.kernel.org/all/20211222072649.18169-1-linmq006@gmail.com/
> ---
>  drivers/gpu/drm/virtio/virtgpu_object.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c
> index f293e6ad52da..1cc8f3fc8e4b 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_object.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_object.c
> @@ -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) {

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/20220526235040.678984-6-dmitry.osipenko@collabora.com/
diff mbox series

Patch

diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c
index f293e6ad52da..1cc8f3fc8e4b 100644
--- a/drivers/gpu/drm/virtio/virtgpu_object.c
+++ b/drivers/gpu/drm/virtio/virtgpu_object.c
@@ -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) {