dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/gem: use new idr deletion interface to cleanup drm_gem_handle_delete()
@ 2017-09-25 18:47 Aishwarya Pant
  2017-09-26  8:20 ` [Outreachy kernel] " Daniel Vetter
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Aishwarya Pant @ 2017-09-25 18:47 UTC (permalink / raw)
  To: Daniel Vetter, Jani Nikula, Sean Paul, David Airlie, dri-devel
  Cc: outreachy-kernel

The IDR deletion interface now returns the deleted entry or NULL if it was not
present. So we don't have to do the extra work of checking if we have a
reference on the drm_gem_object, this can be handled by checking the return
value from idr_remove() and the extra locks can be dropped.

Signed-off-by: Aishwarya Pant <aishpant@gmail.com>
---
 drivers/gpu/drm/drm_gem.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index c55f338..f62757a 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -282,29 +282,12 @@ drm_gem_handle_delete(struct drm_file *filp, u32 handle)
 {
 	struct drm_gem_object *obj;
 
-	/* This is gross. The idr system doesn't let us try a delete and
-	 * return an error code.  It just spews if you fail at deleting.
-	 * So, we have to grab a lock around finding the object and then
-	 * doing the delete on it and dropping the refcount, or the user
-	 * could race us to double-decrement the refcount and cause a
-	 * use-after-free later.  Given the frequency of our handle lookups,
-	 * we may want to use ida for number allocation and a hash table
-	 * for the pointers, anyway.
-	 */
 	spin_lock(&filp->table_lock);
-
-	/* Check if we currently have a reference on the object */
-	obj = idr_replace(&filp->object_idr, NULL, handle);
-	spin_unlock(&filp->table_lock);
-	if (IS_ERR_OR_NULL(obj))
+	obj = idr_remove(&filp->object_idr, handle);
+	if (!obj)
 		return -EINVAL;
-
 	/* Release driver's reference and decrement refcount. */
 	drm_gem_object_release_handle(handle, obj, filp);
-
-	/* And finally make the handle available for future allocations. */
-	spin_lock(&filp->table_lock);
-	idr_remove(&filp->object_idr, handle);
 	spin_unlock(&filp->table_lock);
 
 	return 0;
-- 
2.7.4

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

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

end of thread, other threads:[~2017-09-29  4:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-25 18:47 [PATCH] drm/gem: use new idr deletion interface to cleanup drm_gem_handle_delete() Aishwarya Pant
2017-09-26  8:20 ` [Outreachy kernel] " Daniel Vetter
2017-09-26  8:38   ` Julia Lawall
2017-09-26  8:47     ` Daniel Vetter
2017-09-26  9:05       ` Daniel Vetter
2017-09-26 10:20         ` Julia Lawall
2017-09-26  9:11   ` Aishwarya Pant
2017-09-26  9:12 ` Chris Wilson
2017-09-26  9:20   ` Aishwarya Pant
2017-09-29  4:52 ` [drm/gem] 05eadb82a7: BUG:sleeping_function_called_from_invalid_context_at_kernel/locking/mutex.c kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).