Skip to content

Commit

Permalink
drm: Use kref_put_mutex in drm_gem_object_unreference_unlocked
Browse files Browse the repository at this point in the history
If kref_put_mutex returns true then the caller or the put function is responsible
for unlocking the mutex. The usual pattern assumes that the free
callback unlocks the mutex, but since that is shared with the locked
variant we need to explicitly unlock here.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
  • Loading branch information
Maarten Lankhorst authored and Daniel Vetter committed Apr 7, 2015
1 parent be26a66 commit 0578be6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions include/drm/drm_gem.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,16 @@ drm_gem_object_unreference(struct drm_gem_object *obj)
static inline void
drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
{
if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
struct drm_device *dev = obj->dev;
struct drm_device *dev;

if (!obj)
return;

mutex_lock(&dev->struct_mutex);
if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
drm_gem_object_free(&obj->refcount);
dev = obj->dev;
if (kref_put_mutex(&obj->refcount, drm_gem_object_free, &dev->struct_mutex))
mutex_unlock(&dev->struct_mutex);
}
else
might_lock(&dev->struct_mutex);
}

int drm_gem_handle_create(struct drm_file *file_priv,
Expand Down

0 comments on commit 0578be6

Please sign in to comment.