summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/drm_managed.c
diff options
context:
space:
mode:
authorThomas Zimmermann <tzimmermann@suse.de>2022-05-02 17:25:12 +0300
committerThomas Zimmermann <tzimmermann@suse.de>2022-05-05 10:04:10 +0300
commite13f13e039dc8f31168b5569120a7658035c80ee (patch)
treec7d809d901f8b170f5cc329bb44204f9907dd34e /drivers/gpu/drm/drm_managed.c
parentcce6bedb38ed08f1c3a9b1b01fbba0fdb472fb50 (diff)
downloadlinux-e13f13e039dc8f31168b5569120a7658035c80ee.tar.xz
drm: Add DRM-managed mutex_init()
Add drmm_mutex_init(), a helper that provides managed mutex cleanup. The mutex will be destroyed with the final reference of the DRM device. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/msgid/20220502142514.2174-2-tzimmermann@suse.de
Diffstat (limited to 'drivers/gpu/drm/drm_managed.c')
-rw-r--r--drivers/gpu/drm/drm_managed.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/drivers/gpu/drm/drm_managed.c b/drivers/gpu/drm/drm_managed.c
index 37d7db6223be..4cf214de50c4 100644
--- a/drivers/gpu/drm/drm_managed.c
+++ b/drivers/gpu/drm/drm_managed.c
@@ -8,6 +8,7 @@
#include <drm/drm_managed.h>
#include <linux/list.h>
+#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
@@ -262,3 +263,29 @@ void drmm_kfree(struct drm_device *dev, void *data)
free_dr(dr_match);
}
EXPORT_SYMBOL(drmm_kfree);
+
+static void drmm_mutex_release(struct drm_device *dev, void *res)
+{
+ struct mutex *lock = res;
+
+ mutex_destroy(lock);
+}
+
+/**
+ * drmm_mutex_init - &drm_device-managed mutex_init()
+ * @dev: DRM device
+ * @lock: lock to be initialized
+ *
+ * Returns:
+ * 0 on success, or a negative errno code otherwise.
+ *
+ * This is a &drm_device-managed version of mutex_init(). The initialized
+ * lock is automatically destroyed on the final drm_dev_put().
+ */
+int drmm_mutex_init(struct drm_device *dev, struct mutex *lock)
+{
+ mutex_init(lock);
+
+ return drmm_add_action_or_reset(dev, drmm_mutex_release, lock);
+}
+EXPORT_SYMBOL(drmm_mutex_init);