Skip to content

Commit e6a1c40

Browse files
committed
drm/omap: Fix locking in omap_gem_new_dmabuf()
omap_gem_new_dmabuf() creates the new gem object, and then takes and holds the omap_obj->lock for the rest of the function. This has two issues: - omap_gem_free_object(), which is called in the error paths, also takes the same lock, leading to deadlock - Even if the above wouldn't happen, in the error cases omap_gem_new_dmabuf() still unlocks omap_obj->lock, even after the omap_obj has already been freed. Furthermore, I don't think there's any reason to take the lock at all, as the object was just created and not yet shared with anyone else. To fix all this, drop taking the lock. Fixes: 3cbd0c5 ("drm/omap: gem: Replace struct_mutex usage with omap_obj private lock") Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Reviewed-by: Sebastian Reichel <[email protected]> Signed-off-by: Tomi Valkeinen <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 0d76cb1 commit e6a1c40

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

drivers/gpu/drm/omapdrm/omap_gem.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,8 +1402,6 @@ struct drm_gem_object *omap_gem_new_dmabuf(struct drm_device *dev, size_t size,
14021402

14031403
omap_obj = to_omap_bo(obj);
14041404

1405-
mutex_lock(&omap_obj->lock);
1406-
14071405
omap_obj->sgt = sgt;
14081406

14091407
if (omap_gem_sgt_is_contiguous(sgt, size)) {
@@ -1418,21 +1416,17 @@ struct drm_gem_object *omap_gem_new_dmabuf(struct drm_device *dev, size_t size,
14181416
pages = kcalloc(npages, sizeof(*pages), GFP_KERNEL);
14191417
if (!pages) {
14201418
omap_gem_free_object(obj);
1421-
obj = ERR_PTR(-ENOMEM);
1422-
goto done;
1419+
return ERR_PTR(-ENOMEM);
14231420
}
14241421

14251422
omap_obj->pages = pages;
14261423
ret = drm_prime_sg_to_page_array(sgt, pages, npages);
14271424
if (ret) {
14281425
omap_gem_free_object(obj);
1429-
obj = ERR_PTR(-ENOMEM);
1430-
goto done;
1426+
return ERR_PTR(-ENOMEM);
14311427
}
14321428
}
14331429

1434-
done:
1435-
mutex_unlock(&omap_obj->lock);
14361430
return obj;
14371431
}
14381432

0 commit comments

Comments
 (0)