drm/drv: Hold ref on parent device during drm_device lifetime

This makes it safe to access drm_device->dev after the parent device has
been removed/unplugged.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190225144232.20761-2-noralf@tronnes.org
This commit is contained in:
Noralf Trønnes 2019-02-25 15:42:26 +01:00
parent a7db690c06
commit 56be6503aa

View File

@ -521,7 +521,7 @@ int drm_dev_init(struct drm_device *dev,
BUG_ON(!parent); BUG_ON(!parent);
kref_init(&dev->ref); kref_init(&dev->ref);
dev->dev = parent; dev->dev = get_device(parent);
dev->driver = driver; dev->driver = driver;
/* no per-device feature limits by default */ /* no per-device feature limits by default */
@ -591,6 +591,7 @@ err_minors:
drm_minor_free(dev, DRM_MINOR_RENDER); drm_minor_free(dev, DRM_MINOR_RENDER);
drm_fs_inode_free(dev->anon_inode); drm_fs_inode_free(dev->anon_inode);
err_free: err_free:
put_device(dev->dev);
mutex_destroy(&dev->master_mutex); mutex_destroy(&dev->master_mutex);
mutex_destroy(&dev->ctxlist_mutex); mutex_destroy(&dev->ctxlist_mutex);
mutex_destroy(&dev->clientlist_mutex); mutex_destroy(&dev->clientlist_mutex);
@ -626,6 +627,8 @@ void drm_dev_fini(struct drm_device *dev)
drm_minor_free(dev, DRM_MINOR_PRIMARY); drm_minor_free(dev, DRM_MINOR_PRIMARY);
drm_minor_free(dev, DRM_MINOR_RENDER); drm_minor_free(dev, DRM_MINOR_RENDER);
put_device(dev->dev);
mutex_destroy(&dev->master_mutex); mutex_destroy(&dev->master_mutex);
mutex_destroy(&dev->ctxlist_mutex); mutex_destroy(&dev->ctxlist_mutex);
mutex_destroy(&dev->clientlist_mutex); mutex_destroy(&dev->clientlist_mutex);