diff options
author | Noralf Trønnes <noralf@tronnes.org> | 2019-02-08 09:01:02 -0500 |
---|---|---|
committer | Noralf Trønnes <noralf@tronnes.org> | 2019-02-21 06:11:32 -0500 |
commit | 1ee57d4d75fbc74bb2ae601c8f334219165ef276 (patch) | |
tree | c1147055afbfad120a467bd7210108743d0fd9ad | |
parent | 1fdafbd023793e754aa6ca73c877a375e83b8239 (diff) |
drm: Fix drm_release() and device unplug
If userspace has open fd(s) when drm_dev_unplug() is run, it will result
in drm_dev_unregister() being called twice. First in drm_dev_unplug() and
then later in drm_release() through the call to drm_put_dev().
Since userspace already holds a ref on drm_device through the drm_minor,
it's not necessary to add extra ref counting based on no open file
handles. Instead just drm_dev_put() unconditionally in drm_dev_unplug().
We now have this:
- Userpace holds a ref on drm_device as long as there's open fd(s)
- The driver holds a ref on drm_device as long as it's bound to the
struct device
When both sides are done with drm_device, it is released.
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Reviewed-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Sean Paul <sean@poorly.run>
Link: https://patchwork.freedesktop.org/patch/msgid/20190208140103.28919-2-noralf@tronnes.org
-rw-r--r-- | drivers/gpu/drm/drm_drv.c | 6 | ||||
-rw-r--r-- | drivers/gpu/drm/drm_file.c | 6 |
2 files changed, 3 insertions, 9 deletions
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 4fec551eb781..f2d5a41b61f7 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c | |||
@@ -376,11 +376,7 @@ void drm_dev_unplug(struct drm_device *dev) | |||
376 | synchronize_srcu(&drm_unplug_srcu); | 376 | synchronize_srcu(&drm_unplug_srcu); |
377 | 377 | ||
378 | drm_dev_unregister(dev); | 378 | drm_dev_unregister(dev); |
379 | 379 | drm_dev_put(dev); | |
380 | mutex_lock(&drm_global_mutex); | ||
381 | if (dev->open_count == 0) | ||
382 | drm_dev_put(dev); | ||
383 | mutex_unlock(&drm_global_mutex); | ||
384 | } | 380 | } |
385 | EXPORT_SYMBOL(drm_dev_unplug); | 381 | EXPORT_SYMBOL(drm_dev_unplug); |
386 | 382 | ||
diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index b1838a41ad43..ee4df8f8a62d 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c | |||
@@ -479,11 +479,9 @@ int drm_release(struct inode *inode, struct file *filp) | |||
479 | 479 | ||
480 | drm_file_free(file_priv); | 480 | drm_file_free(file_priv); |
481 | 481 | ||
482 | if (!--dev->open_count) { | 482 | if (!--dev->open_count) |
483 | drm_lastclose(dev); | 483 | drm_lastclose(dev); |
484 | if (drm_dev_is_unplugged(dev)) | 484 | |
485 | drm_put_dev(dev); | ||
486 | } | ||
487 | mutex_unlock(&drm_global_mutex); | 485 | mutex_unlock(&drm_global_mutex); |
488 | 486 | ||
489 | drm_minor_release(minor); | 487 | drm_minor_release(minor); |