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 reset implementation, let's migrate this instance to the new pattern. Signed-off-by: Maxime Ripard <[email protected]> --- Cc: Harry Wentland <[email protected]> Cc: Leo Li <[email protected]> Cc: Rodrigo Siqueira <[email protected]> Cc: Alex Deucher <[email protected]> Cc: "Christian König" <[email protected]> Cc: [email protected] --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 54 +++++++++++++---------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index 62defeccbb5ca09c89523fc4112d2085bbdbb0a9..1bcbfd814d53bb443b7503ffacb109c900b67b5f 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -4675,18 +4675,43 @@ static void dm_atomic_destroy_state(struct drm_private_obj *obj, dc_state_release(dm_state->context); kfree(dm_state); } +static void dm_atomic_reset(struct drm_private_obj *obj) +{ + struct amdgpu_device *adev = drm_to_adev(obj->dev); + struct dm_atomic_state *dm_state; + struct dc_state *context; + + if (obj->state) { + dm_atomic_destroy_state(obj, obj->state); + obj->state = NULL; + } + + dm_state = kzalloc(sizeof(*dm_state), GFP_KERNEL); + if (!dm_state) + return; + + context = dc_state_create_current_copy(adev->dm.dc); + if (!context) { + kfree(dm_state); + return; + } + + __drm_atomic_helper_private_obj_reset(obj, &dm_state->base); + dm_state->context = context; +} + static struct drm_private_state_funcs dm_atomic_state_funcs = { .atomic_duplicate_state = dm_atomic_duplicate_state, .atomic_destroy_state = dm_atomic_destroy_state, + .reset = dm_atomic_reset, }; 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; adev_to_drm(adev)->mode_config.funcs = (void *)&amdgpu_dm_mode_funcs; @@ -4702,46 +4727,27 @@ static int amdgpu_dm_mode_config_init(struct amdgpu_device *adev) else adev_to_drm(adev)->mode_config.prefer_shadow = 1; /* indicates support for immediate flip */ adev_to_drm(adev)->mode_config.async_page_flip = true; - state = kzalloc(sizeof(*state), GFP_KERNEL); - 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; } #define AMDGPU_DM_DEFAULT_MIN_BACKLIGHT 12 -- 2.51.0
