[5.15.y] drm/virtio: Fix error code in virtio_gpu_object_shmem_init()

Message ID 20230302172538.3508747-1-harshit.m.mogalapalli@oracle.com
State New
Headers
Series [5.15.y] drm/virtio: Fix error code in virtio_gpu_object_shmem_init() |

Commit Message

Harshit Mogalapalli March 2, 2023, 5:25 p.m. UTC
  In virtio_gpu_object_shmem_init() we are passing NULL to PTR_ERR, which
is returning 0/success.

Fix this by storing error value in 'ret' variable before assigning
shmem->pages to NULL.

Found using static analysis with Smatch.

Fixes: 64b88afbd92f ("drm/virtio: Correct drm_gem_shmem_get_sg_table() error handling")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
Only compile tested.

Upstream commit b5c9ed70d1a9 ("drm/virtio: Improve DMA API usage for shmem BOs")
deleted this code, so this patch is not necessary in linux-6.1.y and
linux-6.2.y.
---
 drivers/gpu/drm/virtio/virtgpu_object.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Dmitry Osipenko March 3, 2023, 9:32 p.m. UTC | #1
On 3/2/23 20:25, Harshit Mogalapalli wrote:
> In virtio_gpu_object_shmem_init() we are passing NULL to PTR_ERR, which
> is returning 0/success.
> 
> Fix this by storing error value in 'ret' variable before assigning
> shmem->pages to NULL.
> 
> Found using static analysis with Smatch.
> 
> Fixes: 64b88afbd92f ("drm/virtio: Correct drm_gem_shmem_get_sg_table() error handling")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> ---
> Only compile tested.
> 
> Upstream commit b5c9ed70d1a9 ("drm/virtio: Improve DMA API usage for shmem BOs")
> deleted this code, so this patch is not necessary in linux-6.1.y and
> linux-6.2.y.
> ---
>  drivers/gpu/drm/virtio/virtgpu_object.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c
> index 7e75fb0fc7bd..25d399b00404 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_object.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_object.c
> @@ -169,8 +169,9 @@ static int virtio_gpu_object_shmem_init(struct virtio_gpu_device *vgdev,
>  	shmem->pages = drm_gem_shmem_get_sg_table(&bo->base);
>  	if (IS_ERR(shmem->pages)) {
>  		drm_gem_shmem_unpin(&bo->base);
> +		ret = PTR_ERR(shmem->pages);
>  		shmem->pages = NULL;
> -		return PTR_ERR(shmem->pages);
> +		return ret;
>  	}
>  
>  	if (use_dma_api) {

Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
  
Greg KH March 10, 2023, 12:07 p.m. UTC | #2
On Sat, Mar 04, 2023 at 12:32:22AM +0300, Dmitry Osipenko wrote:
> On 3/2/23 20:25, Harshit Mogalapalli wrote:
> > In virtio_gpu_object_shmem_init() we are passing NULL to PTR_ERR, which
> > is returning 0/success.
> > 
> > Fix this by storing error value in 'ret' variable before assigning
> > shmem->pages to NULL.
> > 
> > Found using static analysis with Smatch.
> > 
> > Fixes: 64b88afbd92f ("drm/virtio: Correct drm_gem_shmem_get_sg_table() error handling")
> > Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> > ---
> > Only compile tested.
> > 
> > Upstream commit b5c9ed70d1a9 ("drm/virtio: Improve DMA API usage for shmem BOs")
> > deleted this code, so this patch is not necessary in linux-6.1.y and
> > linux-6.2.y.
> > ---
> >  drivers/gpu/drm/virtio/virtgpu_object.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c
> > index 7e75fb0fc7bd..25d399b00404 100644
> > --- a/drivers/gpu/drm/virtio/virtgpu_object.c
> > +++ b/drivers/gpu/drm/virtio/virtgpu_object.c
> > @@ -169,8 +169,9 @@ static int virtio_gpu_object_shmem_init(struct virtio_gpu_device *vgdev,
> >  	shmem->pages = drm_gem_shmem_get_sg_table(&bo->base);
> >  	if (IS_ERR(shmem->pages)) {
> >  		drm_gem_shmem_unpin(&bo->base);
> > +		ret = PTR_ERR(shmem->pages);
> >  		shmem->pages = NULL;
> > -		return PTR_ERR(shmem->pages);
> > +		return ret;
> >  	}
> >  
> >  	if (use_dma_api) {
> 
> Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>

Both fixes now queued up, thanks.

greg k-h
  

Patch

diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c
index 7e75fb0fc7bd..25d399b00404 100644
--- a/drivers/gpu/drm/virtio/virtgpu_object.c
+++ b/drivers/gpu/drm/virtio/virtgpu_object.c
@@ -169,8 +169,9 @@  static int virtio_gpu_object_shmem_init(struct virtio_gpu_device *vgdev,
 	shmem->pages = drm_gem_shmem_get_sg_table(&bo->base);
 	if (IS_ERR(shmem->pages)) {
 		drm_gem_shmem_unpin(&bo->base);
+		ret = PTR_ERR(shmem->pages);
 		shmem->pages = NULL;
-		return PTR_ERR(shmem->pages);
+		return ret;
 	}
 
 	if (use_dma_api) {