drm/gem: Check locking in drm_gem_object_unreference
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Thu, 15 Oct 2015 07:36:25 +0000 (09:36 +0200)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Mon, 19 Oct 2015 09:00:35 +0000 (11:00 +0200)
Pretty soon only some drivers will need dev->struct_mutex in their
gem_free_object callbacks. Hence it's really important to make sure
everything still keeps getting this right.

v2: Don't check for locking before we check for non-NULL obj. Spotted
by Dan Carpenter.

Link: http://mid.gmane.org/1444894601-5200-10-git-send-email-daniel.vetter@ffwll.ch
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
include/drm/drm_gem.h

index 7a592d7e398b0e4c1c1eca5dd50bff816a634972..15e7f007380f0e08bdbe5148266f5e924f6c6aad 100644 (file)
@@ -142,8 +142,11 @@ drm_gem_object_reference(struct drm_gem_object *obj)
 static inline void
 drm_gem_object_unreference(struct drm_gem_object *obj)
 {
-       if (obj != NULL)
+       if (obj != NULL) {
+               WARN_ON(!mutex_is_locked(&obj->dev->struct_mutex));
+
                kref_put(&obj->refcount, drm_gem_object_free);
+       }
 }
 
 static inline void