[PATCH RFC 04/12] drm/i915/display: Switch to drmm_mode_config_init() and drop manual cleanup

Kory Maincent
2026-04-09T17:09:13Z

Replace drm_mode_config_init() with drmm_mode_config_init() in
intel_mode_config_init(). The managed variant automatically registers
drm_mode_config_cleanup() with devres, so drivers must no longer call it
directly.

Since intel_mode_config_cleanup() was solely a wrapper combining
intel_atomic_global_obj_cleanup() and drm_mode_config_cleanup(), and the
latter is now handled by DRM core, remove it entirely. Instead, register
intel_atomic_global_obj_cleanup() as a devres action so it still runs just
before drm_mode_config_cleanup() during teardown, preserving the correct
cleanup ordering.

Change intel_mode_config_init() to return int to propagate any error from
drmm_mode_config_init().

Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
.../gpu/drm/i915/display/intel_display_driver.c | 37 ++++++++++++++--------
1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display_driver.c b/drivers/gpu/drm/i915/display/intel_display_driver.c
index 23bfecc983e8d..d02393053cef4 100644
--- a/drivers/gpu/drm/i915/display/intel_display_driver.c
+++ b/drivers/gpu/drm/i915/display/intel_display_driver.c
@@ -12,6 +12,7 @@
#include <drm/display/drm_dp_mst_helper.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_client_event.h>
+#include <drm/drm_managed.h>
#include <drm/drm_mode_config.h>
#include <drm/drm_privacy_screen_consumer.h>
#include <drm/drm_print.h>
@@ -48,6 +49,7 @@
#include "intel_fbdev.h"
#include "intel_fdi.h"
#include "intel_flipq.h"
+#include "intel_global_state.h"
#include "intel_gmbus.h"
#include "intel_hdcp.h"
#include "intel_hotplug.h"
@@ -111,13 +113,28 @@ static const struct drm_mode_config_helper_funcs intel_mode_config_funcs = {
.atomic_commit_setup = drm_dp_mst_atomic_setup_commit,
};

-static void intel_mode_config_init(struct intel_display *display)
+static void intel_atomic_global_obj_cleanup_action(struct drm_device *drm, void *data)
+{
+ intel_atomic_global_obj_cleanup((struct intel_display *)data);
+}
+
+static int intel_mode_config_init(struct intel_display *display)
{
struct drm_mode_config *mode_config = &display->drm->mode_config;
+ int ret;
+
+ ret = drmm_mode_config_init(display->drm);
+ if (ret)
+ return ret;

- drm_mode_config_init(display->drm);
INIT_LIST_HEAD(&display->global.obj_list);

+ ret = drmm_add_action_or_reset(display->drm,
+ intel_atomic_global_obj_cleanup_action,
+ display);
+ if (ret)
+ return ret;
+
mode_config->min_width = 0;
mode_config->min_height = 0;

@@ -148,12 +165,8 @@ static void intel_mode_config_init(struct intel_display *display)
}

intel_cursor_mode_config_init(display);
-}

-static void intel_mode_config_cleanup(struct intel_display *display)
-{
- intel_atomic_global_obj_cleanup(display);
- drm_mode_config_cleanup(display->drm);
+ return 0;
}

static void intel_plane_possible_crtcs_init(struct intel_display *display)
@@ -255,7 +268,9 @@ int intel_display_driver_probe_noirq(struct intel_display *display)

intel_dmc_init(display);

- intel_mode_config_init(display);
+ ret = intel_mode_config_init(display);
+ if (ret)
+ goto cleanup_wq_unordered;

ret = intel_cdclk_init(display);
if (ret)
@@ -456,7 +471,7 @@ int intel_display_driver_probe_nogem(struct intel_display *display)

ret = intel_crtc_init(display);
if (ret)
- goto err_mode_config;
+ return ret;

intel_plane_possible_crtcs_init(display);
intel_dpll_init(display);
@@ -497,8 +512,6 @@ int intel_display_driver_probe_nogem(struct intel_display *display)

err_hdcp:
intel_hdcp_component_fini(display);
-err_mode_config:
- intel_mode_config_cleanup(display);

return ret;
}
@@ -618,8 +631,6 @@ void intel_display_driver_remove_noirq(struct intel_display *display)

intel_hdcp_component_fini(display);

- intel_mode_config_cleanup(display);
-
intel_dp_tunnel_mgr_cleanup(display);

intel_overlay_cleanup(display);

--
2.43.0