linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeffy Chen <jeffy.chen@rock-chips.com>
To: linux-kernel@vger.kernel.org
Cc: briannorris@chromium.org, dianders@chromium.org,
	tfiga@chromium.org, seanpaul@chromium.org, zyw@rock-chips.com,
	marcheu@chromium.org, mark.yao@rock-chips.com, hshi@chromium.org,
	Jeffy Chen <jeffy.chen@rock-chips.com>,
	Daniel Vetter <daniel.vetter@intel.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	dri-devel@lists.freedesktop.org,
	Chris Wilson <chris@chris-wilson.co.uk>,
	David Airlie <airlied@linux.ie>, Tom Gundersen <teg@jklm.no>,
	Dave Airlie <airlied@redhat.com>
Subject: [PATCH v7 1/2] drm: Unplug drm device when unregistering it
Date: Tue, 11 Apr 2017 11:31:41 +0800	[thread overview]
Message-ID: <1491881502-24357-2-git-send-email-jeffy.chen@rock-chips.com> (raw)
In-Reply-To: <1491881502-24357-1-git-send-email-jeffy.chen@rock-chips.com>

After unbinding drm, the user space may still owns the drm dev fd,
and may still be able to call drm ioctl.

We're using an unplugged state to prevent something like that, so
let's reuse it here.

Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
Reviewed-by: Sean Paul <seanpaul@chromium.org>

---

Changes in v7:
Address Sean Paul <seanpaul@chromium.org>'s comments.

Changes in v6:
Address Daniel Vetter <daniel@ffwll.ch>'s comments.

Changes in v5:
Fix wrong git account.

Changes in v2:
Fix some commit messages.

 drivers/gpu/drm/drm_drv.c     | 8 ++++----
 drivers/gpu/drm/udl/udl_drv.c | 2 +-
 include/drm/drmP.h            | 5 +++--
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index b5c6bb4..ad13e20 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -357,12 +357,9 @@ EXPORT_SYMBOL(drm_put_dev);
 
 void drm_unplug_dev(struct drm_device *dev)
 {
-	/* for a USB device */
-	drm_dev_unregister(dev);
-
 	mutex_lock(&drm_global_mutex);
 
-	drm_device_set_unplugged(dev);
+	drm_device_set_plug_state(dev, false);
 
 	if (dev->open_count == 0) {
 		drm_put_dev(dev);
@@ -787,6 +784,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
 	if (drm_core_check_feature(dev, DRIVER_MODESET))
 		drm_modeset_register_all(dev);
 
+	drm_device_set_plug_state(dev, true);
+
 	ret = 0;
 
 	DRM_INFO("Initialized %s %d.%d.%d %s for %s on minor %d\n",
@@ -826,6 +825,7 @@ void drm_dev_unregister(struct drm_device *dev)
 	drm_lastclose(dev);
 
 	dev->registered = false;
+	drm_unplug_dev(dev);
 
 	if (drm_core_check_feature(dev, DRIVER_MODESET))
 		drm_modeset_unregister_all(dev);
diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c
index cd8b017..5dbd916 100644
--- a/drivers/gpu/drm/udl/udl_drv.c
+++ b/drivers/gpu/drm/udl/udl_drv.c
@@ -108,7 +108,7 @@ static void udl_usb_disconnect(struct usb_interface *interface)
 	drm_kms_helper_poll_disable(dev);
 	udl_fbdev_unplug(dev);
 	udl_drop_usb(dev);
-	drm_unplug_dev(dev);
+	drm_dev_unregister(dev);
 }
 
 /*
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3bfafcd..a9a5a64 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -488,10 +488,11 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,
 	return ((dev->driver->driver_features & feature) ? 1 : 0);
 }
 
-static inline void drm_device_set_unplugged(struct drm_device *dev)
+static inline void drm_device_set_plug_state(struct drm_device *dev,
+					     bool plugged)
 {
 	smp_wmb();
-	atomic_set(&dev->unplugged, 1);
+	atomic_set(&dev->unplugged, !plugged);
 }
 
 static inline int drm_device_is_unplugged(struct drm_device *dev)
-- 
2.1.4

  reply	other threads:[~2017-04-11  3:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-11  3:31 [PATCH v7 0/2] drm: rockchip: Fix rockchip drm unbind crash error Jeffy Chen
2017-04-11  3:31 ` Jeffy Chen [this message]
2017-04-12  6:33   ` [PATCH v7 1/2] drm: Unplug drm device when unregistering it Daniel Vetter
2017-04-12  8:17     ` jeffy
2017-04-12  8:44       ` jeffy
2017-04-11  3:31 ` [PATCH v7 2/2] drm: Prevent release fb after cleanup drm_mode_config Jeffy Chen
2017-04-12  6:36   ` Daniel Vetter
2017-04-12  8:39     ` jeffy

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=1491881502-24357-2-git-send-email-jeffy.chen@rock-chips.com \
    --to=jeffy.chen@rock-chips.com \
    --cc=airlied@linux.ie \
    --cc=airlied@redhat.com \
    --cc=briannorris@chromium.org \
    --cc=chris@chris-wilson.co.uk \
    --cc=daniel.vetter@intel.com \
    --cc=dianders@chromium.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hshi@chromium.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcheu@chromium.org \
    --cc=mark.yao@rock-chips.com \
    --cc=seanpaul@chromium.org \
    --cc=teg@jklm.no \
    --cc=tfiga@chromium.org \
    --cc=zyw@rock-chips.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).