These changes make the error path a little more robust, because exit
steps in drm_core_exit() don't have to ensure any longer that they
work properly even if the associated init step wasn't executed.
In addition these changes allow to annotate a few functions as __exit,
saving some memory if drm is built-in.

Signed-off-by: Heiner Kallweit <hkallwe...@gmail.com>
---
 drivers/accel/drm_accel.c                |  2 +-
 drivers/gpu/drm/drm_drv.c                | 18 ++++++++++++------
 drivers/gpu/drm/drm_panic.c              |  4 ++--
 drivers/gpu/drm/drm_privacy_screen_x86.c |  2 +-
 drivers/gpu/drm/drm_sysfs.c              |  2 --
 5 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c
index aa826033b..25fdbea36 100644
--- a/drivers/accel/drm_accel.c
+++ b/drivers/accel/drm_accel.c
@@ -191,7 +191,7 @@ static const struct file_operations accel_stub_fops = {
        .llseek = noop_llseek,
 };
 
-void accel_core_exit(void)
+void __exit accel_core_exit(void)
 {
        unregister_chrdev(ACCEL_MAJOR, "accel");
        debugfs_remove(accel_debugfs_root);
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index ac30b0ec9..ea59994e5 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -1062,7 +1062,7 @@ static const struct file_operations drm_stub_fops = {
        .llseek = noop_llseek,
 };
 
-static void drm_core_exit(void)
+static void __exit drm_core_exit(void)
 {
        drm_privacy_screen_lookup_exit();
        drm_panic_exit();
@@ -1084,18 +1084,18 @@ static int __init drm_core_init(void)
        ret = drm_sysfs_init();
        if (ret < 0) {
                DRM_ERROR("Cannot create DRM class: %d\n", ret);
-               goto error;
+               goto err_ida;
        }
 
        drm_debugfs_root = debugfs_create_dir("dri", NULL);
 
        ret = register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops);
        if (ret < 0)
-               goto error;
+               goto err_debugfs;
 
        ret = accel_core_init();
        if (ret < 0)
-               goto error;
+               goto err_chrdev;
 
        drm_panic_init();
 
@@ -1106,8 +1106,14 @@ static int __init drm_core_init(void)
        DRM_DEBUG("Initialized\n");
        return 0;
 
-error:
-       drm_core_exit();
+err_chrdev:
+       unregister_chrdev(DRM_MAJOR, "drm");
+err_debugfs:
+       debugfs_remove(drm_debugfs_root);
+       drm_sysfs_destroy();
+err_ida:
+       WARN_ON(!xa_empty(&drm_minors_xa));
+       drm_connector_ida_destroy();
        return ret;
 }
 
diff --git a/drivers/gpu/drm/drm_panic.c b/drivers/gpu/drm/drm_panic.c
index 74412b7bf..d00fdb12d 100644
--- a/drivers/gpu/drm/drm_panic.c
+++ b/drivers/gpu/drm/drm_panic.c
@@ -679,7 +679,7 @@ static void __init drm_panic_qr_init(void)
                                   GFP_KERNEL);
 }
 
-static void drm_panic_qr_exit(void)
+static void __exit drm_panic_qr_exit(void)
 {
        kfree(qrbuf1);
        qrbuf1 = NULL;
@@ -1058,7 +1058,7 @@ void __init drm_panic_init(void)
 /**
  * drm_panic_exit() - Free the resources taken by drm_panic_exit()
  */
-void drm_panic_exit(void)
+void __exit drm_panic_exit(void)
 {
        drm_panic_qr_exit();
 }
diff --git a/drivers/gpu/drm/drm_privacy_screen_x86.c 
b/drivers/gpu/drm/drm_privacy_screen_x86.c
index 72ed40e49..6be96a0cc 100644
--- a/drivers/gpu/drm/drm_privacy_screen_x86.c
+++ b/drivers/gpu/drm/drm_privacy_screen_x86.c
@@ -98,7 +98,7 @@ void __init drm_privacy_screen_lookup_init(void)
        }
 }
 
-void drm_privacy_screen_lookup_exit(void)
+void __exit drm_privacy_screen_lookup_exit(void)
 {
        if (arch_lookup.provider)
                drm_privacy_screen_lookup_remove(&arch_lookup);
diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
index a713f0500..f8577043e 100644
--- a/drivers/gpu/drm/drm_sysfs.c
+++ b/drivers/gpu/drm/drm_sysfs.c
@@ -155,8 +155,6 @@ int drm_sysfs_init(void)
  */
 void drm_sysfs_destroy(void)
 {
-       if (IS_ERR_OR_NULL(drm_class))
-               return;
        drm_sysfs_acpi_unregister();
        class_destroy(drm_class);
        drm_class = NULL;
-- 
2.46.0


Reply via email to