]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdgpu: Switch private_obj initialization to atomic_create_state
authorMaxime Ripard <mripard@kernel.org>
Tue, 24 Feb 2026 16:10:26 +0000 (17:10 +0100)
committerMaxime Ripard <mripard@kernel.org>
Fri, 20 Mar 2026 09:03:02 +0000 (10:03 +0100)
The amdgpu driver relies on a drm_private_obj, that is initialized by
allocating and initializing a state, and then passing it to
drm_private_obj_init.

Since we're gradually moving away from that pattern to the more
established one relying on a atomic_create_state implementation, let's
migrate this instance to the new pattern.

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Link: https://patch.msgid.link/20260224-drm-private-obj-reset-v5-1-5a72f8ec9934@kernel.org
Signed-off-by: Maxime Ripard <mripard@kernel.org>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

index dfe95c9b8746d507559cd6b4871ee98e0b315928..d44701cbde6d406bb6ec82afe8c754f00745038a 100644 (file)
@@ -4844,14 +4844,37 @@ static void dm_atomic_destroy_state(struct drm_private_obj *obj,
        kfree(dm_state);
 }
 
+static struct drm_private_state *
+dm_atomic_create_state(struct drm_private_obj *obj)
+{
+       struct amdgpu_device *adev = drm_to_adev(obj->dev);
+       struct dm_atomic_state *dm_state;
+       struct dc_state *context;
+
+       dm_state = kzalloc_obj(*dm_state);
+       if (!dm_state)
+               return ERR_PTR(-ENOMEM);
+
+       context = dc_state_create_current_copy(adev->dm.dc);
+       if (!context) {
+               kfree(dm_state);
+               return ERR_PTR(-ENOMEM);
+       }
+
+       __drm_atomic_helper_private_obj_create_state(obj, &dm_state->base);
+       dm_state->context = context;
+
+       return &dm_state->base;
+}
+
 static struct drm_private_state_funcs dm_atomic_state_funcs = {
+       .atomic_create_state = dm_atomic_create_state,
        .atomic_duplicate_state = dm_atomic_duplicate_state,
        .atomic_destroy_state = dm_atomic_destroy_state,
 };
 
 static int amdgpu_dm_mode_config_init(struct amdgpu_device *adev)
 {
-       struct dm_atomic_state *state;
        int r;
 
        adev->mode_info.mode_config_initialized = true;
@@ -4871,42 +4894,23 @@ static int amdgpu_dm_mode_config_init(struct amdgpu_device *adev)
        /* indicates support for immediate flip */
        adev_to_drm(adev)->mode_config.async_page_flip = true;
 
-       state = kzalloc_obj(*state);
-       if (!state)
-               return -ENOMEM;
-
-       state->context = dc_state_create_current_copy(adev->dm.dc);
-       if (!state->context) {
-               kfree(state);
-               return -ENOMEM;
-       }
-
        drm_atomic_private_obj_init(adev_to_drm(adev),
                                    &adev->dm.atomic_obj,
-                                   &state->base,
+                                   NULL,
                                    &dm_atomic_state_funcs);
 
        r = amdgpu_display_modeset_create_props(adev);
-       if (r) {
-               dc_state_release(state->context);
-               kfree(state);
+       if (r)
                return r;
-       }
 
 #ifdef AMD_PRIVATE_COLOR
-       if (amdgpu_dm_create_color_properties(adev)) {
-               dc_state_release(state->context);
-               kfree(state);
+       if (amdgpu_dm_create_color_properties(adev))
                return -ENOMEM;
-       }
 #endif
 
        r = amdgpu_dm_audio_init(adev);
-       if (r) {
-               dc_state_release(state->context);
-               kfree(state);
+       if (r)
                return r;
-       }
 
        return 0;
 }