From: "Noralf Trønnes" <noralf@tronnes.org>
To: dri-devel@lists.freedesktop.org
Cc: daniel.vetter@ffwll.ch, laurent.pinchart@ideasonboard.com,
david@lechnology.com
Subject: [PATCH v2 03/11] drm/fb-helper: Ensure driver module is pinned in fb_open()
Date: Fri, 8 Sep 2017 17:07:22 +0200 [thread overview]
Message-ID: <1504883250-43487-4-git-send-email-noralf@tronnes.org> (raw)
In-Reply-To: <1504883250-43487-1-git-send-email-noralf@tronnes.org>
If struct fb_ops is defined in a library like cma, fb_open() takes a
ref on the library instead of the driver module. Use
fb_ops.fb_open/fb_release to ensure that the driver module is pinned.
Add drm_fb_helper_fb_open() and drm_fb_helper_fb_release() to
DRM_FB_HELPER_DEFAULT_OPS().
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---
drivers/gpu/drm/drm_fb_helper.c | 41 +++++++++++++++++++++++++++++++++++++++++
include/drm/drm_fb_helper.h | 14 ++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index 74c1053..b080004 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -1037,6 +1037,47 @@ void drm_fb_helper_fb_destroy(struct fb_info *info)
EXPORT_SYMBOL(drm_fb_helper_fb_destroy);
/**
+ * drm_fb_helper_fb_open - implementation for &fb_ops.fb_open
+ * @info: fbdev registered by the helper
+ * @user: 1=userspace, 0=fbcon
+ *
+ * If &fb_ops is wrapped in a library, pin the driver module.
+ */
+int drm_fb_helper_fb_open(struct fb_info *info, int user)
+{
+ struct drm_fb_helper *fb_helper = info->par;
+ struct drm_device *dev = fb_helper->dev;
+
+ /* Skip fbcon, it detaches itself in unregister_framebuffer() */
+ if (user && info->fbops->owner != dev->driver->fops->owner) {
+ if (!try_module_get(dev->driver->fops->owner))
+ return -ENODEV;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(drm_fb_helper_fb_open);
+
+/**
+ * drm_fb_helper_fb_release - implementation for &fb_ops.fb_release
+ * @info: fbdev registered by the helper
+ * @user: 1=userspace, 0=fbcon
+ *
+ * If &fb_ops is wrapped in a library, unpin the driver module.
+ */
+int drm_fb_helper_fb_release(struct fb_info *info, int user)
+{
+ struct drm_fb_helper *fb_helper = info->par;
+ struct drm_device *dev = fb_helper->dev;
+
+ if (user && info->fbops->owner != dev->driver->fops->owner)
+ module_put(dev->driver->fops->owner);
+
+ return 0;
+}
+EXPORT_SYMBOL(drm_fb_helper_fb_release);
+
+/**
* drm_fb_helper_sys_read - wrapper around fb_sys_read
* @info: fb_info struct pointer
* @buf: userspace buffer to read from framebuffer memory
diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h
index dd78eb3..b44fc62 100644
--- a/include/drm/drm_fb_helper.h
+++ b/include/drm/drm_fb_helper.h
@@ -233,6 +233,8 @@ struct drm_fb_helper {
*/
#define DRM_FB_HELPER_DEFAULT_OPS \
.fb_destroy = drm_fb_helper_fb_destroy, \
+ .fb_open = drm_fb_helper_fb_open, \
+ .fb_release = drm_fb_helper_fb_release, \
.fb_check_var = drm_fb_helper_check_var, \
.fb_set_par = drm_fb_helper_set_par, \
.fb_setcmap = drm_fb_helper_setcmap, \
@@ -270,6 +272,8 @@ void drm_fb_helper_deferred_io(struct fb_info *info,
struct list_head *pagelist);
void drm_fb_helper_fb_destroy(struct fb_info *info);
+int drm_fb_helper_fb_open(struct fb_info *info, int user);
+int drm_fb_helper_fb_release(struct fb_info *info, int user);
ssize_t drm_fb_helper_sys_read(struct fb_info *info, char __user *buf,
size_t count, loff_t *ppos);
@@ -405,6 +409,16 @@ static inline void drm_fb_helper_fb_destroy(struct fb_info *info)
{
}
+static inline int drm_fb_helper_fb_open(struct fb_info *info, int user)
+{
+ return -ENODEV;
+}
+
+static inline int drm_fb_helper_fb_release(struct fb_info *info, int user)
+{
+ return -ENODEV;
+}
+
static inline ssize_t drm_fb_helper_sys_read(struct fb_info *info,
char __user *buf, size_t count,
loff_t *ppos)
--
2.7.4
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2017-09-08 15:07 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-08 15:07 [PATCH v2 00/11] drm/tinydrm: Support device unplug Noralf Trønnes
2017-09-08 15:07 ` [PATCH v2 01/11] drm: Use srcu to protect drm_device.unplugged Noralf Trønnes
2017-09-08 15:07 ` [PATCH v2 02/11] drm/fb-helper: Support device unplug Noralf Trønnes
2017-09-08 15:07 ` Noralf Trønnes [this message]
2017-09-08 15:07 ` [PATCH v2 04/11] drm/fb-helper: Don't restore if fbdev is not in use Noralf Trønnes
2017-09-08 15:07 ` [PATCH v2 05/11] drm/fb-cma-helper: Make struct drm_fbdev_cma public Noralf Trønnes
2017-09-08 15:07 ` [PATCH v2 06/11] drm/fb-cma-helper: Support device unplug Noralf Trønnes
2017-09-08 15:07 ` [PATCH v2 07/11] drm/tinydrm: Drop driver registered message Noralf Trønnes
2017-09-09 21:33 ` David Lechner
2017-09-16 12:15 ` Noralf Trønnes
2017-09-08 15:07 ` [PATCH v2 08/11] drm/tinydrm: Embed drm_device in tinydrm_device Noralf Trønnes
2017-09-08 15:07 ` [PATCH v2 09/11] drm/tinydrm: Support device unplug in core Noralf Trønnes
2017-09-08 15:07 ` [PATCH v2 10/11] drm/tinydrm/mi0283qt: Let the display pipe handle power Noralf Trønnes
2017-09-08 15:07 ` [PATCH v2 11/11] drm/tinydrm: Support device unplug in drivers Noralf Trønnes
2017-09-08 16:33 ` [PATCH v2 00/11] drm/tinydrm: Support device unplug Daniel Vetter
2018-03-16 8:03 ` Daniel Vetter
2018-03-17 14:40 ` Noralf Trønnes
2018-03-19 13:45 ` Daniel Vetter
2018-03-19 14:50 ` Oleksandr Andrushchenko
2018-03-26 13:02 ` Oleksandr Andrushchenko
2018-03-26 16:36 ` Noralf Trønnes
2018-03-27 5:47 ` Oleksandr Andrushchenko
2018-03-27 5:56 ` Daniel Vetter
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=1504883250-43487-4-git-send-email-noralf@tronnes.org \
--to=noralf@tronnes.org \
--cc=daniel.vetter@ffwll.ch \
--cc=david@lechnology.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=laurent.pinchart@ideasonboard.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