All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Oded Gabbay <ogabbay@kernel.org>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
	Hans de Goede <hdegoede@redhat.com>
Cc: "open list:AMD KFD" <dri-devel@lists.freedesktop.org>
Subject: [PATCH 3/6] drm: Refactor drm_core_init error path
Date: Sun, 8 Sep 2024 14:10:30 +0200	[thread overview]
Message-ID: <3a659ed0-4072-4f01-9676-65d6b1a42678@gmail.com> (raw)
In-Reply-To: <499229fd-5344-4799-85bf-93e4b3b45eca@gmail.com>

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 <hkallweit1@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



  parent reply	other threads:[~2024-09-08 12:10 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-08 12:04 [PATCH 0/6] drm: Series with core improvements/refactorings Heiner Kallweit
2024-09-08 12:08 ` [PATCH 1/6] drm/sysfs: Remove version attribute Heiner Kallweit
2024-09-22 14:55   ` Dmitry Baryshkov
2024-09-30 10:49     ` Heiner Kallweit
2024-10-01 10:01       ` Dmitry Baryshkov
2024-10-01 11:07         ` Heiner Kallweit
2024-10-01 11:26           ` Dmitry Baryshkov
2024-09-08 12:09 ` [PATCH 2/6] drm/sysfs: Drop unused drm_class_device_(un)register Heiner Kallweit
2024-09-22 14:57   ` Dmitry Baryshkov
2024-09-08 12:10 ` Heiner Kallweit [this message]
2024-09-22 14:58   ` [PATCH 3/6] drm: Refactor drm_core_init error path Dmitry Baryshkov
2024-09-08 12:11 ` [PATCH 4/6] drm: Change drm_class from pointer to const struct class Heiner Kallweit
2024-09-22 15:11   ` Dmitry Baryshkov
2024-11-02 21:33     ` Heiner Kallweit
2024-11-03 23:59       ` Greg Kroah-Hartman
2024-09-08 12:12 ` [PATCH 5/6] drm: Add __init annotations Heiner Kallweit
2024-09-22 15:12   ` Dmitry Baryshkov
2024-09-08 12:14 ` [PATCH 6/6] drm: drm/sysfs: Remove device type drm_minor Heiner Kallweit
2024-09-22 15:17   ` Dmitry Baryshkov
2024-10-19 15:18 ` [PATCH 0/6] drm: Series with core improvements/refactorings Dmitry Baryshkov
2024-10-20 21:00   ` Heiner Kallweit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3a659ed0-4072-4f01-9676-65d6b1a42678@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=airlied@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hdegoede@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=ogabbay@kernel.org \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.