diff options
author | Maarten Lankhorst <maarten.lankhorst@linux.intel.com> | 2015-04-07 09:56:07 -0400 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2015-04-07 12:11:25 -0400 |
commit | 0578be680c6623ad6515b60a0b41ec70ebc1f204 (patch) | |
tree | 3b25074a3f4cbb88413f8b5fde910453e9753658 /include/drm | |
parent | be26a66de5f5722388966a62d772df832818bcb9 (diff) |
drm: Use kref_put_mutex in drm_gem_object_unreference_unlocked
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>
Diffstat (limited to 'include/drm')
-rw-r--r-- | include/drm/drm_gem.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 1e6ae1458f7a..7a592d7e398b 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h | |||
@@ -149,14 +149,16 @@ drm_gem_object_unreference(struct drm_gem_object *obj) | |||
149 | static inline void | 149 | static inline void |
150 | drm_gem_object_unreference_unlocked(struct drm_gem_object *obj) | 150 | drm_gem_object_unreference_unlocked(struct drm_gem_object *obj) |
151 | { | 151 | { |
152 | if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) { | 152 | struct drm_device *dev; |
153 | struct drm_device *dev = obj->dev; | 153 | |
154 | if (!obj) | ||
155 | return; | ||
154 | 156 | ||
155 | mutex_lock(&dev->struct_mutex); | 157 | dev = obj->dev; |
156 | if (likely(atomic_dec_and_test(&obj->refcount.refcount))) | 158 | if (kref_put_mutex(&obj->refcount, drm_gem_object_free, &dev->struct_mutex)) |
157 | drm_gem_object_free(&obj->refcount); | ||
158 | mutex_unlock(&dev->struct_mutex); | 159 | mutex_unlock(&dev->struct_mutex); |
159 | } | 160 | else |
161 | might_lock(&dev->struct_mutex); | ||
160 | } | 162 | } |
161 | 163 | ||
162 | int drm_gem_handle_create(struct drm_file *file_priv, | 164 | int drm_gem_handle_create(struct drm_file *file_priv, |