All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm: Use kref_put_mutex in drm_gem_object_unreference_unlocked
@ 2015-04-07 13:56 Maarten Lankhorst
  2015-04-07 14:19 ` Ville Syrjälä
  0 siblings, 1 reply; 4+ messages in thread
From: Maarten Lankhorst @ 2015-04-07 13:56 UTC (permalink / raw)
  To: dri-devel@lists.freedesktop.org; +Cc: Daniel Vetter

If kref_put_mutex returns true then the caller or the put function is responsible
for unlocking the mutex.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
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)
 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,

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm: Use kref_put_mutex in drm_gem_object_unreference_unlocked
  2015-04-07 13:56 [PATCH] drm: Use kref_put_mutex in drm_gem_object_unreference_unlocked Maarten Lankhorst
@ 2015-04-07 14:19 ` Ville Syrjälä
  2015-04-07 14:23   ` Maarten Lankhorst
  0 siblings, 1 reply; 4+ messages in thread
From: Ville Syrjälä @ 2015-04-07 14:19 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: Daniel Vetter, dri-devel@lists.freedesktop.org

On Tue, Apr 07, 2015 at 03:56:07PM +0200, Maarten Lankhorst wrote:
> If kref_put_mutex returns true then the caller or the put function is responsible
> for unlocking the mutex.

This patch introduces the kref_put_mutex() usage, so this commit
message is rather confusing.

> 
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
> 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)
>  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,
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm: Use kref_put_mutex in drm_gem_object_unreference_unlocked
  2015-04-07 14:19 ` Ville Syrjälä
@ 2015-04-07 14:23   ` Maarten Lankhorst
  2015-04-07 15:15     ` Daniel Vetter
  0 siblings, 1 reply; 4+ messages in thread
From: Maarten Lankhorst @ 2015-04-07 14:23 UTC (permalink / raw)
  To: Ville Syrjälä; +Cc: Daniel Vetter, dri-devel@lists.freedesktop.org

Hey,

Op 07-04-15 om 16:19 schreef Ville Syrjälä:
> On Tue, Apr 07, 2015 at 03:56:07PM +0200, Maarten Lankhorst wrote:
>> If kref_put_mutex returns true then the caller or the put function is responsible
>> for unlocking the mutex.
> This patch introduces the kref_put_mutex() usage, so this commit
> message is rather confusing.
>
This was because of the confusion that happened when doing the same in
i915_gem_request_unreference__unlocked, so I thought I would mention it
explicitly in the commit message. :-)

~Maarten

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm: Use kref_put_mutex in drm_gem_object_unreference_unlocked
  2015-04-07 14:23   ` Maarten Lankhorst
@ 2015-04-07 15:15     ` Daniel Vetter
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Vetter @ 2015-04-07 15:15 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: Daniel Vetter, dri-devel@lists.freedesktop.org

On Tue, Apr 07, 2015 at 04:23:55PM +0200, Maarten Lankhorst wrote:
> Hey,
> 
> Op 07-04-15 om 16:19 schreef Ville Syrjälä:
> > On Tue, Apr 07, 2015 at 03:56:07PM +0200, Maarten Lankhorst wrote:
> >> If kref_put_mutex returns true then the caller or the put function is responsible
> >> for unlocking the mutex.
> > This patch introduces the kref_put_mutex() usage, so this commit
> > message is rather confusing.
> >
> This was because of the confusion that happened when doing the same in
> i915_gem_request_unreference__unlocked, so I thought I would mention it
> explicitly in the commit message. :-)

I've added a bit more text to make it clearer and applied the patch to
topic/drm-misc.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-07 15:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-07 13:56 [PATCH] drm: Use kref_put_mutex in drm_gem_object_unreference_unlocked Maarten Lankhorst
2015-04-07 14:19 ` Ville Syrjälä
2015-04-07 14:23   ` Maarten Lankhorst
2015-04-07 15:15     ` Daniel Vetter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.