[ Upstream commit 56be6503aab2bc3a30beae408071b9be5e1bae51 ]

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

Signed-off-by: Noralf Trønnes <nor...@tronnes.org>
Reviewed-by: Gerd Hoffmann <kra...@redhat.com>
Link: 
https://patchwork.freedesktop.org/patch/msgid/20190225144232.20761-2-nor...@tronnes.org
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
 drivers/gpu/drm/drm_drv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index a7b6734bc3c32..340440febf9a5 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -505,7 +505,7 @@ int drm_dev_init(struct drm_device *dev,
        }
 
        kref_init(&dev->ref);
-       dev->dev = parent;
+       dev->dev = get_device(parent);
        dev->driver = driver;
 
        INIT_LIST_HEAD(&dev->filelist);
@@ -572,6 +572,7 @@ int drm_dev_init(struct drm_device *dev,
        drm_minor_free(dev, DRM_MINOR_CONTROL);
        drm_fs_inode_free(dev->anon_inode);
 err_free:
+       put_device(dev->dev);
        mutex_destroy(&dev->master_mutex);
        mutex_destroy(&dev->ctxlist_mutex);
        mutex_destroy(&dev->filelist_mutex);
@@ -607,6 +608,8 @@ void drm_dev_fini(struct drm_device *dev)
        drm_minor_free(dev, DRM_MINOR_RENDER);
        drm_minor_free(dev, DRM_MINOR_CONTROL);
 
+       put_device(dev->dev);
+
        mutex_destroy(&dev->master_mutex);
        mutex_destroy(&dev->ctxlist_mutex);
        mutex_destroy(&dev->filelist_mutex);
-- 
2.20.1



Reply via email to