Skip to content

Commit

Permalink
dma-buf: fix an error pointer vs NULL bug
Browse files Browse the repository at this point in the history
Smatch detected potential error pointer dereference.

    drivers/gpu/drm/drm_syncobj.c:888 drm_syncobj_transfer_to_timeline()
    error: 'fence' dereferencing possible ERR_PTR()

The error pointer comes from dma_fence_allocate_private_stub().  One
caller expected error pointers and one expected NULL pointers.  Change
it to return NULL and update the caller which expected error pointers,
drm_syncobj_assign_null_handle(), to check for NULL instead.

Fixes: f781f66 ("dma-buf: keep the signaling time of merged fences v3")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Sumit Semwal <sumit.semwal@linaro.org>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/b09f1996-3838-4fa2-9193-832b68262e43@moroto.mountain
  • Loading branch information
Dan Carpenter authored and sumitsemwal committed Jul 6, 2023
1 parent 7f34e01 commit 00ae149
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion drivers/dma-buf/dma-fence.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ struct dma_fence *dma_fence_allocate_private_stub(ktime_t timestamp)

fence = kzalloc(sizeof(*fence), GFP_KERNEL);
if (fence == NULL)
return ERR_PTR(-ENOMEM);
return NULL;

dma_fence_init(fence,
&dma_fence_stub_ops,
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/drm_syncobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
{
struct dma_fence *fence = dma_fence_allocate_private_stub(ktime_get());

if (IS_ERR(fence))
return PTR_ERR(fence);
if (!fence)
return -ENOMEM;

drm_syncobj_replace_fence(syncobj, fence);
dma_fence_put(fence);
Expand Down

0 comments on commit 00ae149

Please sign in to comment.