drm/dp/mst: Handle errors from drm_atomic_get_private_obj_state() correctly
Subsystems (3)
PATCH 1/3 drm/dp/mst: Handle errors from drm_atomic_get_private_obj_state() correctly
From: Ville Syrjälä <[email protected]>
On failure drm_atomic_get_private_obj_state() returns and error pointer instead of NULL. Adjust the checks in the callers to match.
--- drivers/gpu/drm/drm_dp_mst_topology.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_dp_mst_topology.c +4 -4
@@ -2515,8 +2515,8 @@ int drm_dp_atomic_find_vcpi_slots(struct drm_atomic_state *state,int req_slots; topology_state =drm_atomic_get_mst_topology_state (state, mgr); -if (topology_state ==NULL ) -return -ENOMEM ; +if (IS_ERR (topology_state)) +return PTR_ERR (topology_state); port =drm_dp_get_validated_port_ref (mgr, port);if (port ==NULL )
@@ -2555,8 +2555,8 @@ int drm_dp_atomic_release_vcpi_slots(struct drm_atomic_state *state,struct drm_dp_mst_topology_state *topology_state; topology_state =drm_atomic_get_mst_topology_state (state, mgr); -if (topology_state ==NULL ) -return -ENOMEM ; +if (IS_ERR (topology_state)) +return PTR_ERR (topology_state);/* We cannot rely on port->vcpi.num_slots to update * topology_state->avail_slots as the port may not exist if the parent
Signature · 1 line
2.13.0
PATCH 2/3 drm/atomic: Remove pointless private object NULL state check
From: Ville Syrjälä <[email protected]>
We will never add private objects with a NULL state into the atomic state, hence checking for that is pointless.
--- drivers/gpu/drm/drm_atomic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic.c +1 -2
@@ -1013,8 +1013,7 @@ drm_atomic_get_private_obj_state(struct drm_atomic_state *state, void *obj,struct __drm_private_objs_state *arr;for (i =0 ; i < state->num_private_objs; i++) -if (obj == state->private_objs[i].obj && - state->private_objs[i].obj_state) +if (obj == state->private_objs[i].obj)return state->private_objs[i].obj_state; num_objs = state->num_private_objs +1 ;
Signature · 6 lines
2.13.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/3 drm/atomic: Make private objs proper objects
In reply to [email protected]From: Ville Syrjälä <[email protected]>
Make the atomic private object stuff less special by introducing proper base classes for the object and its state. Drivers can embed these in their own appropriate objects, after which these things will work exactly like the plane/crtc/connector states during atomic operations.
v2: Reorder to not depend on drm_dynarray (Daniel)
--- drivers/gpu/drm/drm_atomic.c | 78 ++++++++++++++++------ drivers/gpu/drm/drm_atomic_helper.c | 30 +++++++-- drivers/gpu/drm/drm_dp_mst_topology.c | 63 +++++++++--------- include/drm/drm_atomic.h | 120 +++++++++++++++++++++------------- include/drm/drm_atomic_helper.h | 4 ++ include/drm/drm_dp_mst_helper.h | 10 +++ 6 files changed, 203 insertions(+), 102 deletions(-)
drivers/gpu/drm/drm_atomic.c +59 -19
@@ -187,12 +187,15 @@ void drm_atomic_state_default_clear(struct drm_atomic_state *state) }for (i =0 ; i < state->num_private_objs; i++) { -void *obj_state = state->private_objs[i].obj_state; +struct drm_private_obj *obj = state->private_objs[i].ptr; - state->private_objs[i].funcs->destroy_state (obj_state); - state->private_objs[i].obj =NULL ; - state->private_objs[i].obj_state =NULL ; - state->private_objs[i].funcs =NULL ; +if (!obj) +continue ; + + obj->funcs->atomic_destroy_state (obj, + state->private_objs[i].state); + state->private_objs[i].ptr =NULL ; + state->private_objs[i].state =NULL ; } state->num_private_objs =0 ;
@@ -990,11 +993,44 @@ static void drm_atomic_plane_print_state(struct drm_printer *p, }/** +* drm_atomic_private_obj_init - initialize private object +* @obj: private object +* @state: initial private object state +* @funcs: pointer to the struct of function pointers that identify the object +* type +* +* Initialize the private object, which can be embedded into any +* driver private object that needs its own atomic state. +*/ +void +drm_atomic_private_obj_init (struct drm_private_obj *obj, +struct drm_private_state *state, +const struct drm_private_state_funcs *funcs) +{ +memset (obj,0 ,sizeof (*obj)); + + obj->state = state; + obj->funcs = funcs; +} +EXPORT_SYMBOL (drm_atomic_private_obj_init); + +/** +* drm_atomic_private_obj_fini - finalize private object +* @obj: private object +* +* Finalize the private object. +*/ +void +drm_atomic_private_obj_fini (struct drm_private_obj *obj) +{ + obj->funcs->atomic_destroy_state (obj, obj->state); +} +EXPORT_SYMBOL (drm_atomic_private_obj_fini); + +/** * drm_atomic_get_private_obj_state - get private object state * @state: global atomic state * @obj: private object to get the state for -* @funcs: pointer to the struct of function pointers that identify the object -* type * * This function returns the private object state for the given private object, * allocating the state if needed. It does not grab any locks as the caller is
@@ -1004,17 +1040,18 @@ static void drm_atomic_plane_print_state(struct drm_printer *p,* * Either the allocated state or the error code encoded into a pointer. */ -void * -drm_atomic_get_private_obj_state (struct drm_atomic_state *state,void *obj, -const struct drm_private_state_funcs *funcs) +struct drm_private_state * +drm_atomic_get_private_obj_state (struct drm_atomic_state *state, +struct drm_private_obj *obj) {int index, num_objs, i;size_t size;struct __drm_private_objs_state *arr; +struct drm_private_state *obj_state;for (i =0 ; i < state->num_private_objs; i++) -if (obj == state->private_objs[i].obj) -return state->private_objs[i].obj_state; +if (obj == state->private_objs[i].ptr) +return state->private_objs[i].state; num_objs = state->num_private_objs +1 ; size =sizeof (*state->private_objs) * num_objs;
@@ -1026,18 +1063,21 @@ drm_atomic_get_private_obj_state(struct drm_atomic_state *state, void *obj, index = state->num_private_objs;memset (&state->private_objs[index],0 ,sizeof (*state->private_objs)); - state->private_objs[index].obj_state = funcs->duplicate_state (state, obj); -if (!state->private_objs[index].obj_state) + obj_state = obj->funcs->atomic_duplicate_state (obj); +if (!obj_state)return ERR_PTR (-ENOMEM ); - state->private_objs[index].obj = obj; - state->private_objs[index].funcs = funcs; + state->private_objs[index].state = obj_state; + state->private_objs[index].old_state = obj->state; + state->private_objs[index].new_state = obj_state; + state->private_objs[index].ptr = obj; + state->num_private_objs = num_objs; -DRM_DEBUG_ATOMIC ("Added new private object state %p to %p\n" , - state->private_objs[index].obj_state, state); +DRM_DEBUG_ATOMIC ("Added new private object %p state %p to %p\n" , + obj, obj_state, state); -return state->private_objs[index].obj_state; +return obj_state; }EXPORT_SYMBOL (drm_atomic_get_private_obj_state);
drivers/gpu/drm/drm_atomic_helper.c +26 -4
@@ -2267,8 +2267,8 @@ void drm_atomic_helper_swap_state(struct drm_atomic_state *state,struct drm_plane *plane;struct drm_plane_state *old_plane_state, *new_plane_state;struct drm_crtc_commit *commit; -void *obj, *obj_state; -const struct drm_private_state_funcs *funcs; +struct drm_private_obj *obj; +struct drm_private_state *old_obj_state, *new_obj_state;if (stall) {for_each_new_crtc_in_state (state, crtc, new_crtc_state, i) {
@@ -2330,8 +2330,15 @@ void drm_atomic_helper_swap_state(struct drm_atomic_state *state, plane->state = new_plane_state; } -__for_each_private_obj (state, obj, obj_state, i, funcs) - funcs->swap_state (obj, &state->private_objs[i].obj_state); +for_each_oldnew_private_obj_in_state (state, obj, old_obj_state, new_obj_state, i) { +WARN_ON (obj->state != old_obj_state); + + old_obj_state->state = state; + new_obj_state->state =NULL ; + + state->private_objs[i].state = old_obj_state; + obj->state = new_obj_state; + } }EXPORT_SYMBOL (drm_atomic_helper_swap_state);
@@ -3828,3 +3835,18 @@ int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc,return ret; }EXPORT_SYMBOL (drm_atomic_helper_legacy_gamma_set); + +/** +* __drm_atomic_helper_private_duplicate_state - copy atomic private state +* @obj: CRTC object +* @state: new private object state +* +* Copies atomic state from a private objects's current state and resets inferred values. +* This is useful for drivers that subclass the private state. +*/ +void __drm_atomic_helper_private_obj_duplicate_state (struct drm_private_obj *obj, +struct drm_private_state *state) +{ +memcpy (state, obj->state,sizeof (*state)); +} +EXPORT_SYMBOL (__drm_atomic_helper_private_obj_duplicate_state);
drivers/gpu/drm/drm_dp_mst_topology.c +30 -33
113 lines not on this page · raw message
include/drm/drm_atomic.h +74 -46
169 lines not on this page · raw message
include/drm/drm_atomic_helper.h +4 -0
@@ -33,6 +33,8 @@#include <drm/drm_modeset_helper.h> struct drm_atomic_state ; +struct drm_private_obj ; +struct drm_private_state ;int drm_atomic_helper_check_modeset (struct drm_device *dev,struct drm_atomic_state *state);
@@ -185,6 +187,8 @@ int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, u16 *blue, uint32_t size, struct drm_modeset_acquire_ctx *ctx); +void __drm_atomic_helper_private_obj_duplicate_state (struct drm_private_obj *obj, +struct drm_private_state *state);/** * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC
include/drm/drm_dp_mst_helper.h +10 -0
@@ -404,12 +404,17 @@ struct drm_dp_payload {int vcpi; }; +#define to_dp_mst_topology_state (x) container_of(x, struct drm_dp_mst_topology_state, base) +struct drm_dp_mst_topology_state { +struct drm_private_state base;int avail_slots;struct drm_atomic_state *state;struct drm_dp_mst_topology_mgr *mgr; }; +#define to_dp_mst_topology_mgr (x) container_of(x, struct drm_dp_mst_topology_mgr, base) +/** * struct drm_dp_mst_topology_mgr - DisplayPort MST manager *
@@ -419,6 +424,11 @@ struct drm_dp_mst_topology_state {*/ struct drm_dp_mst_topology_mgr {/** +* @base: Base private object for atomic +*/ +struct drm_private_obj base; + +/** * @dev: device pointer for adding i2c devices etc. */ struct drm_device *dev;
Signature · 6 lines
2.13.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 3/3] drm/atomic: Make private objs proper objects
Quoted 7 lines · On Wed, 12 Jul 2017, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Make the atomic private object stuff less special by introducing proper base classes for the object and its state. Drivers can embed these in their own appropriate objects, after which these things will work exactly like the plane/crtc/connector states during atomic operations.
Quoted 6 lines
v2: Reorder to not depend on
drm_dynarray(Daniel)Cc Dhinakaran Pandiyan <[email protected]>Cc Daniel Vetter <[email protected]>Reviewed-by Daniel Vetter <[email protected]> #v1Signed-off-by Ville Syrjälä <[email protected]>
Stumbled upon an old commit
commit a4370c777406c2810e37fafd166ccddecdb2a60c
Author: Ville Syrjälä <[email protected]> Date: Wed Jul 12 18:51:02 2017 +0300
drm/atomic: Make private objs proper objects
which is this patch.
drivers/gpu/drm/drm_dp_mst_topology.c struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_a · line 3048
Quoted 9 lines
drivers/gpu/drm/drm_dp_mst_topology.c +1
-2@@ -3050,8 +3043,7 @@ struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_astruct drm_device *dev = mgr->dev;WARN_ON (!drm_modeset_is_locked (&dev->mode_config.connection_mutex)); -return drm_atomic_get_private_obj_state (state, mgr, - &mst_state_funcs); +return to_dp_mst_topology_state (drm_atomic_get_private_obj_state (state, &mgr->base)); }EXPORT_SYMBOL (drm_atomic_get_mst_topology_state);
I don't think this combines well with...
include/drm/drm_dp_mst_helper.h struct drm_dp_payload { · line 407
Quoted 9 lines
include/drm/drm_dp_mst_helper.h +1
-0@@ -404,12 +404,17 @@ struct drm_dp_payload {int vcpi; }; +#define to_dp_mst_topology_state (x) container_of(x, struct drm_dp_mst_topology_state, base)
...this in case of error pointers thatdrm_atomic_get_private_obj_state() may return.
Is that right, or am I just ready to 'shutdown -h now' for 2021...?
BR,
Jani.
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
Re: [PATCH 3/3] drm/atomic: Make private objs proper objects
Quoted 45 lines · Jani Nikula
Quoted 7 lines · On Wed, 12 Jul 2017, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Make the atomic private object stuff less special by introducing proper base classes for the object and its state. Drivers can embed these in their own appropriate objects, after which these things will work exactly like the plane/crtc/connector states during atomic operations.
Quoted 6 lines
v2: Reorder to not depend on
drm_dynarray(Daniel)Cc Dhinakaran Pandiyan <[email protected]>Cc Daniel Vetter <[email protected]>Reviewed-by Daniel Vetter <[email protected]> #v1Signed-off-by Ville Syrjälä <[email protected]>Stumbled upon an old commit
commit
a4370c777406c2810e37fafd166ccddecdb2a60cAuthor: Ville Syrjälä <[email protected]> Date: Wed Jul 12 18:51:02 2017 +0300drm/atomic: Make private objs proper objects
which is this patch.
drivers/gpu/drm/drm_dp_mst_topology.c struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_a · line 3048
Quoted 9 lines
drivers/gpu/drm/drm_dp_mst_topology.c +1
-2@@ -3050,8 +3043,7 @@ struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_astruct drm_device *dev = mgr->dev;WARN_ON (!drm_modeset_is_locked (&dev->mode_config.connection_mutex)); -return drm_atomic_get_private_obj_state (state, mgr, - &mst_state_funcs); +return to_dp_mst_topology_state (drm_atomic_get_private_obj_state (state, &mgr->base)); }EXPORT_SYMBOL (drm_atomic_get_mst_topology_state);I don't think this combines well with...
Quoted 8 lines
include/drm/drm_dp_mst_helper.h +0
-0@@ -404,12 +404,17 @@ struct drm_dp_payload {int vcpi; };
Quoted 4 lines
include/drm/drm_dp_mst_helper.h struct drm_dp_payload { · line 407
Quoted 1 line
include/drm/drm_dp_mst_helper.h +1
-0+#define to_dp_mst_topology_state (x) container_of(x, struct drm_dp_mst_topology_state, base)...this in case of error pointers that
drm_atomic_get_private_obj_state()may return.
offsetof(base)==0 so should work in practice.
Signature · 2 lines
Ville Syrjälä Intel
Re: [PATCH 3/3] drm/atomic: Make private objs proper objects
Quoted 46 lines · Ville Syrjälä
Quoted 45 lines · Jani Nikula
Quoted 7 lines · On Wed, 12 Jul 2017, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Make the atomic private object stuff less special by introducing proper base classes for the object and its state. Drivers can embed these in their own appropriate objects, after which these things will work exactly like the plane/crtc/connector states during atomic operations.
Quoted 6 lines
v2: Reorder to not depend on
drm_dynarray(Daniel)Cc Dhinakaran Pandiyan <[email protected]>Cc Daniel Vetter <[email protected]>Reviewed-by Daniel Vetter <[email protected]> #v1Signed-off-by Ville Syrjälä <[email protected]>Stumbled upon an old commit
commit
a4370c777406c2810e37fafd166ccddecdb2a60cAuthor: Ville Syrjälä <[email protected]> Date: Wed Jul 12 18:51:02 2017 +0300drm/atomic: Make private objs proper objects
which is this patch.
drivers/gpu/drm/drm_dp_mst_topology.c struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_a · line 3048
Quoted 9 lines
drivers/gpu/drm/drm_dp_mst_topology.c +1
-2@@ -3050,8 +3043,7 @@ struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_astruct drm_device *dev = mgr->dev;WARN_ON (!drm_modeset_is_locked (&dev->mode_config.connection_mutex)); -return drm_atomic_get_private_obj_state (state, mgr, - &mst_state_funcs); +return to_dp_mst_topology_state (drm_atomic_get_private_obj_state (state, &mgr->base)); }EXPORT_SYMBOL (drm_atomic_get_mst_topology_state);I don't think this combines well with...
Quoted 8 lines
include/drm/drm_dp_mst_helper.h +0
-0@@ -404,12 +404,17 @@ struct drm_dp_payload {int vcpi; };
Quoted 6 lines
Quoted 4 lines
include/drm/drm_dp_mst_helper.h struct drm_dp_payload { · line 407
Quoted 1 line
include/drm/drm_dp_mst_helper.h +1
-0+#define to_dp_mst_topology_state (x) container_of(x, struct drm_dp_mst_topology_state, base)...this in case of error pointers that
drm_atomic_get_private_obj_state()may return.offsetof(base)==0 so should work in practice.
Returning zeros is fine, but error pointers are another matter.
BR,
Jani.
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
Re: [PATCH 3/3] drm/atomic: Make private objs proper objects
Quoted 47 lines · Jani Nikula
Quoted 46 lines · Ville Syrjälä
Quoted 45 lines · Jani Nikula
Quoted 7 lines · On Wed, 12 Jul 2017, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Make the atomic private object stuff less special by introducing proper base classes for the object and its state. Drivers can embed these in their own appropriate objects, after which these things will work exactly like the plane/crtc/connector states during atomic operations.
Quoted 6 lines
v2: Reorder to not depend on
drm_dynarray(Daniel)Cc Dhinakaran Pandiyan <[email protected]>Cc Daniel Vetter <[email protected]>Reviewed-by Daniel Vetter <[email protected]> #v1Signed-off-by Ville Syrjälä <[email protected]>Stumbled upon an old commit
commit
a4370c777406c2810e37fafd166ccddecdb2a60cAuthor: Ville Syrjälä <[email protected]> Date: Wed Jul 12 18:51:02 2017 +0300drm/atomic: Make private objs proper objects
which is this patch.
drivers/gpu/drm/drm_dp_mst_topology.c struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_a · line 3048
Quoted 9 lines
drivers/gpu/drm/drm_dp_mst_topology.c +1
-2@@ -3050,8 +3043,7 @@ struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_astruct drm_device *dev = mgr->dev;WARN_ON (!drm_modeset_is_locked (&dev->mode_config.connection_mutex)); -return drm_atomic_get_private_obj_state (state, mgr, - &mst_state_funcs); +return to_dp_mst_topology_state (drm_atomic_get_private_obj_state (state, &mgr->base)); }EXPORT_SYMBOL (drm_atomic_get_mst_topology_state);I don't think this combines well with...
Quoted 8 lines
include/drm/drm_dp_mst_helper.h +0
-0@@ -404,12 +404,17 @@ struct drm_dp_payload {int vcpi; };
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
include/drm/drm_dp_mst_helper.h struct drm_dp_payload { · line 407
Quoted 1 line
include/drm/drm_dp_mst_helper.h +1
-0+#define to_dp_mst_topology_state (x) container_of(x, struct drm_dp_mst_topology_state, base)...this in case of error pointers that
drm_atomic_get_private_obj_state()may return.offsetof(base)==0 so should work in practice.
Returning zeros is fine, but error pointers are another matter.
Why? This is just 'return ptr-0' so shouldn't matter what you have in that pointer AFAICS.
Signature · 2 lines
Ville Syrjälä Intel
Quoted 9 lines · On Wed, 2017-07-12 at 18:51 +0300, [email protected] wrote:
From: Ville Syrjälä <[email protected]>
On failure
drm_atomic_get_private_obj_state()returns and error pointer instead of NULL. Adjust the checks in the callers to match.Cc Dhinakaran Pandiyan <[email protected]>Cc Harry Wentland <[email protected]>Cc Maarten Lankhorst <[email protected]>
Thanks for fixing this,
Quoted 22 lines
Fixes edb1ed1ab7d3 ("drm/dp: Add DP MST helpers to atomically find and release vcpi slots")Signed-off-by Ville Syrjälä <[email protected]>--- drivers/gpu/drm/drm_dp_mst_topology.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_dp_mst_topology.c +2
-2@@ -2515,8 +2515,8 @@ int drm_dp_atomic_find_vcpi_slots(struct drm_atomic_state *state,int req_slots; topology_state =drm_atomic_get_mst_topology_state (state, mgr); -if (topology_state ==NULL ) -return -ENOMEM ; +if (IS_ERR (topology_state)) +return PTR_ERR (topology_state); port =drm_dp_get_validated_port_ref (mgr, port);if (port ==NULL )
drivers/gpu/drm/drm_dp_mst_topology.c int drm_dp_atomic_release_vcpi_slots(struct drm_atomic_state *state, · line 2562
Quoted 10 lines
drivers/gpu/drm/drm_dp_mst_topology.c +2
-2@@ -2555,8 +2555,8 @@ int drm_dp_atomic_release_vcpi_slots(struct drm_atomic_state *state,struct drm_dp_mst_topology_state *topology_state; topology_state =drm_atomic_get_mst_topology_state (state, mgr); -if (topology_state ==NULL ) -return -ENOMEM ; +if (IS_ERR (topology_state)) +return PTR_ERR (topology_state);/* We cannot rely on port->vcpi.num_slots to update * topology_state->avail_slots as the port may not exist if the parent
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel