drm: Use drmm_ for drm_dev_init cleanup
Well for the simple stuff at least, vblank, gem and minor cleanup I want to further split up as a demonstration. v2: We need to clear drm_device->dev otherwise the debug drm printing after our cleanup hook (e.g. in drm_manged_release) will chase released memory and result in a use-after-free. Not really pretty, but oh well. Reviewed-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200323144950.3018436-22-daniel.vetter@ffwll.ch
This commit is contained in:
parent
a5c71fdba9
commit
2cbf7fc671
@ -580,6 +580,23 @@ static void drm_fs_inode_free(struct inode *inode)
|
||||
* used.
|
||||
*/
|
||||
|
||||
static void drm_dev_init_release(struct drm_device *dev, void *res)
|
||||
{
|
||||
drm_legacy_ctxbitmap_cleanup(dev);
|
||||
drm_legacy_remove_map_hash(dev);
|
||||
drm_fs_inode_free(dev->anon_inode);
|
||||
|
||||
put_device(dev->dev);
|
||||
/* Prevent use-after-free in drm_managed_release when debugging is
|
||||
* enabled. Slightly awkward, but can't really be helped. */
|
||||
dev->dev = NULL;
|
||||
mutex_destroy(&dev->master_mutex);
|
||||
mutex_destroy(&dev->clientlist_mutex);
|
||||
mutex_destroy(&dev->filelist_mutex);
|
||||
mutex_destroy(&dev->struct_mutex);
|
||||
drm_legacy_destroy_members(dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* drm_dev_init - Initialise new DRM device
|
||||
* @dev: DRM device
|
||||
@ -647,11 +664,15 @@ int drm_dev_init(struct drm_device *dev,
|
||||
mutex_init(&dev->clientlist_mutex);
|
||||
mutex_init(&dev->master_mutex);
|
||||
|
||||
ret = drmm_add_action(dev, drm_dev_init_release, NULL);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
dev->anon_inode = drm_fs_inode_new();
|
||||
if (IS_ERR(dev->anon_inode)) {
|
||||
ret = PTR_ERR(dev->anon_inode);
|
||||
DRM_ERROR("Cannot allocate anonymous inode: %d\n", ret);
|
||||
goto err_free;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (drm_core_check_feature(dev, DRIVER_RENDER)) {
|
||||
@ -688,19 +709,12 @@ err_setunique:
|
||||
if (drm_core_check_feature(dev, DRIVER_GEM))
|
||||
drm_gem_destroy(dev);
|
||||
err_ctxbitmap:
|
||||
drm_legacy_ctxbitmap_cleanup(dev);
|
||||
drm_legacy_remove_map_hash(dev);
|
||||
err_minors:
|
||||
drm_minor_free(dev, DRM_MINOR_PRIMARY);
|
||||
drm_minor_free(dev, DRM_MINOR_RENDER);
|
||||
drm_fs_inode_free(dev->anon_inode);
|
||||
err_free:
|
||||
put_device(dev->dev);
|
||||
mutex_destroy(&dev->master_mutex);
|
||||
mutex_destroy(&dev->clientlist_mutex);
|
||||
mutex_destroy(&dev->filelist_mutex);
|
||||
mutex_destroy(&dev->struct_mutex);
|
||||
drm_legacy_destroy_members(dev);
|
||||
err:
|
||||
drm_managed_release(dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(drm_dev_init);
|
||||
@ -763,20 +777,8 @@ void drm_dev_fini(struct drm_device *dev)
|
||||
if (drm_core_check_feature(dev, DRIVER_GEM))
|
||||
drm_gem_destroy(dev);
|
||||
|
||||
drm_legacy_ctxbitmap_cleanup(dev);
|
||||
drm_legacy_remove_map_hash(dev);
|
||||
drm_fs_inode_free(dev->anon_inode);
|
||||
|
||||
drm_minor_free(dev, DRM_MINOR_PRIMARY);
|
||||
drm_minor_free(dev, DRM_MINOR_RENDER);
|
||||
|
||||
put_device(dev->dev);
|
||||
|
||||
mutex_destroy(&dev->master_mutex);
|
||||
mutex_destroy(&dev->clientlist_mutex);
|
||||
mutex_destroy(&dev->filelist_mutex);
|
||||
mutex_destroy(&dev->struct_mutex);
|
||||
drm_legacy_destroy_members(dev);
|
||||
}
|
||||
EXPORT_SYMBOL(drm_dev_fini);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user