dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Jyri Sarha <jsarha@ti.com>
To: dri-devel@lists.freedesktop.org
Cc: Jyri Sarha <jsarha@ti.com>,
	tomi.valkeinen@ti.com, laurent.pinchart@ideasonboard.com
Subject: [PATCH] drm/drm_bridge: adjust bridge module's refcount
Date: Tue, 29 Nov 2016 23:12:56 +0200	[thread overview]
Message-ID: <1480453976-26303-1-git-send-email-jsarha@ti.com> (raw)

Store the module that provides the bridge and adjust its refcount
accordingly. The bridge module unload should not be allowed while the
bridge is attached.

Signed-off-by: Jyri Sarha <jsarha@ti.com>
---
 drivers/gpu/drm/drm_bridge.c | 15 ++++++++++++---
 include/drm/drm_bridge.h     | 11 ++++++++++-
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index 0ee052b..36d427b 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -61,22 +61,26 @@
 static LIST_HEAD(bridge_list);
 
 /**
- * drm_bridge_add - add the given bridge to the global bridge list
+ * __drm_bridge_add - add the given bridge to the global bridge list
  *
  * @bridge: bridge control structure
+ * @module: module that provides this bridge
  *
  * RETURNS:
  * Unconditionally returns Zero.
  */
-int drm_bridge_add(struct drm_bridge *bridge)
+int __drm_bridge_add(struct drm_bridge *bridge, struct module *module)
 {
+#ifdef MODULE
+	bridge->module = module;
+#endif
 	mutex_lock(&bridge_lock);
 	list_add_tail(&bridge->list, &bridge_list);
 	mutex_unlock(&bridge_lock);
 
 	return 0;
 }
-EXPORT_SYMBOL(drm_bridge_add);
+EXPORT_SYMBOL(__drm_bridge_add);
 
 /**
  * drm_bridge_remove - remove the given bridge from the global bridge list
@@ -114,6 +118,9 @@ int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge)
 	if (bridge->dev)
 		return -EBUSY;
 
+	if (!try_module_get(bridge->module))
+		return -ENOENT;
+
 	bridge->dev = dev;
 
 	if (bridge->funcs->attach)
@@ -144,6 +151,8 @@ void drm_bridge_detach(struct drm_bridge *bridge)
 	if (bridge->funcs->detach)
 		bridge->funcs->detach(bridge);
 
+	module_put(bridge->module);
+
 	bridge->dev = NULL;
 }
 EXPORT_SYMBOL(drm_bridge_detach);
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index 530a1d6..d60d5d2 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -25,6 +25,7 @@
 
 #include <linux/list.h>
 #include <linux/ctype.h>
+#include <linux/module.h>
 #include <drm/drm_mode_object.h>
 #include <drm/drm_modes.h>
 
@@ -192,13 +193,21 @@ struct drm_bridge {
 #ifdef CONFIG_OF
 	struct device_node *of_node;
 #endif
+#ifdef MODULE
+	struct module *module;
+#endif
 	struct list_head list;
 
 	const struct drm_bridge_funcs *funcs;
 	void *driver_private;
 };
 
-int drm_bridge_add(struct drm_bridge *bridge);
+int __drm_bridge_add(struct drm_bridge *bridge, struct module *module);
+#ifdef MODULE
+#define drm_bridge_add(bridge) __drm_bridge_add(bridge, THIS_MODULE)
+#else
+#define drm_bridge_add(bridge) __drm_bridge_add(bridge, NULL)
+#endif
 void drm_bridge_remove(struct drm_bridge *bridge);
 struct drm_bridge *of_drm_find_bridge(struct device_node *np);
 int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
-- 
1.9.1

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

             reply	other threads:[~2016-11-29 21:13 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20161129211315epcas3p2a805abe8449509312f481ab7dcea96ef@epcas3p2.samsung.com>
2016-11-29 21:12 ` Jyri Sarha [this message]
2016-11-29 21:30   ` [PATCH] drm/drm_bridge: adjust bridge module's refcount Jyri Sarha
2016-11-29 22:06   ` Laurent Pinchart
2016-11-30  8:13     ` Daniel Vetter
2016-11-30  8:25       ` Laurent Pinchart
2016-11-30  9:12         ` Daniel Vetter
2016-11-30  9:56           ` Laurent Pinchart
2016-11-30 10:55             ` Daniel Vetter
2016-11-30 11:03               ` Laurent Pinchart
2016-11-30 13:09                 ` Daniel Vetter
2016-12-01  7:07                   ` Andrzej Hajda
2016-12-01  7:18                     ` Daniel Vetter
2016-12-01 13:22                       ` Andrzej Hajda
2016-12-01 15:12                         ` Daniel Vetter
2016-12-02  6:49                           ` Andrzej Hajda
2016-11-30  8:32     ` Jyri Sarha
2016-11-30  8:37       ` Laurent Pinchart
2016-11-30  8:55         ` Jyri Sarha
2016-11-30  9:03           ` Laurent Pinchart
2016-11-30  9:13             ` Jyri Sarha
2016-11-30  9:30               ` Laurent Pinchart
2016-11-30  8:11   ` Andrzej Hajda
2016-11-30  8:16     ` Laurent Pinchart
2016-11-30  9:26       ` Andrzej Hajda
2016-11-30  9:39         ` Laurent Pinchart
2016-12-01  6:50           ` Andrzej Hajda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1480453976-26303-1-git-send-email-jsarha@ti.com \
    --to=jsarha@ti.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=tomi.valkeinen@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).