Skip to content

Commit 2cc107d

Browse files
David Herrmanndanvet
authored andcommitted
drm: cleanup drm_core_{init,exit}()
Various cleanups to the DRM core initialization and exit handlers: - Register chrdev last: Once register_chrdev() returns, open() will succeed on the given chrdevs. This is usually not an issue, as no chardevs are registered, yet. However, nodes can be created by user-space via mknod(2), even though such major/minor combinations are unknown to the kernel. Avoid calling into drm_stub_open() in those cases. Again, drm_stub_open() would just bail out as the inode is unknown, but it's really non-obvious if you hack on drm_stub_open(). - Unify error-paths into just one label. All the error-path helpers can be called even though the constructors were not called yet, or failed. Hence, just call all cleanups unconditionally. - Call into drm_global_release(). This is a no-op, but provides debugging helpers in case there're GLOBALS left on module unload. This function was unused until now. - Use DRM_ERROR() instead of printk(), and also print the error-code on failure (even if it is static!). - Don't throw away error-codes of register_chrdev()! - Don't hardcode -1 as errno. This is just plain wrong. - Order exit-handlers in the exact reverse order of initialization (except if the order actually matters for syncing-reasons, which is not the case here, though). v2: - Call drm_core_exit() directly from the init-error-handler. Requires to drop __exit annotation, though. Signed-off-by: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: http://patchwork.freedesktop.org/patch/msgid/20160901124837.680-7-dh.herrmann@gmail.com
1 parent 82d5e73 commit 2cc107d

1 file changed

Lines changed: 22 additions & 26 deletions

File tree

‎drivers/gpu/drm/drm_drv.c‎

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -820,52 +820,48 @@ static const struct file_operations drm_stub_fops = {
820820
.llseek = noop_llseek,
821821
};
822822

823+
static void drm_core_exit(void)
824+
{
825+
unregister_chrdev(DRM_MAJOR, "drm");
826+
debugfs_remove(drm_debugfs_root);
827+
drm_sysfs_destroy();
828+
idr_destroy(&drm_minors_idr);
829+
drm_connector_ida_destroy();
830+
drm_global_release();
831+
}
832+
823833
static int __init drm_core_init(void)
824834
{
825-
int ret = -ENOMEM;
835+
int ret;
826836

827837
drm_global_init();
828838
drm_connector_ida_init();
829839
idr_init(&drm_minors_idr);
830840

831-
if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
832-
goto err_p1;
833-
834841
ret = drm_sysfs_init();
835842
if (ret < 0) {
836-
printk(KERN_ERR "DRM: Error creating drm class.\n");
837-
goto err_p2;
843+
DRM_ERROR("Cannot create DRM class: %d\n", ret);
844+
goto error;
838845
}
839846

840847
drm_debugfs_root = debugfs_create_dir("dri", NULL);
841848
if (!drm_debugfs_root) {
842-
DRM_ERROR("Cannot create /sys/kernel/debug/dri\n");
843-
ret = -1;
844-
goto err_p3;
849+
ret = -ENOMEM;
850+
DRM_ERROR("Cannot create debugfs-root: %d\n", ret);
851+
goto error;
845852
}
846853

854+
ret = register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops);
855+
if (ret < 0)
856+
goto error;
857+
847858
DRM_INFO("Initialized\n");
848859
return 0;
849-
err_p3:
850-
drm_sysfs_destroy();
851-
err_p2:
852-
unregister_chrdev(DRM_MAJOR, "drm");
853860

854-
idr_destroy(&drm_minors_idr);
855-
err_p1:
861+
error:
862+
drm_core_exit();
856863
return ret;
857864
}
858865

859-
static void __exit drm_core_exit(void)
860-
{
861-
debugfs_remove(drm_debugfs_root);
862-
drm_sysfs_destroy();
863-
864-
unregister_chrdev(DRM_MAJOR, "drm");
865-
866-
drm_connector_ida_destroy();
867-
idr_destroy(&drm_minors_idr);
868-
}
869-
870866
module_init(drm_core_init);
871867
module_exit(drm_core_exit);

0 commit comments

Comments
 (0)