gpu: host1x: Plug potential memory leak
authorThierry Reding <treding@nvidia.com>
Thu, 2 Sep 2021 20:33:09 +0000 (22:33 +0200)
committerThierry Reding <treding@nvidia.com>
Thu, 16 Sep 2021 16:06:52 +0000 (18:06 +0200)
The memory allocated for a DMA fence could be leaked if the code failed
to allocate the waiter object. Make sure to release the fence allocation
on failure.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/gpu/host1x/fence.c

index e49083b..ecab728 100644 (file)
@@ -152,8 +152,10 @@ struct dma_fence *host1x_fence_create(struct host1x_syncpt *sp, u32 threshold)
                return ERR_PTR(-ENOMEM);
 
        fence->waiter = kzalloc(sizeof(*fence->waiter), GFP_KERNEL);
-       if (!fence->waiter)
+       if (!fence->waiter) {
+               kfree(fence);
                return ERR_PTR(-ENOMEM);
+       }
 
        fence->sp = sp;
        fence->threshold = threshold;