From: Ville Syrjälä <[email protected]> The vblank event lifetime/ownership is a mess. Various bits of code examine the event's internals to determine whether they think they own the event (and thus should free it) or not. Mistakes are very likely to happen here.
Simplify this down to a simple rule: "Unconsumed crtc_state->event is owned by the crtc_state, and freed from its destructor". The one slight exception is drm_atomic_helper_page_flip() because the event is allocated and owned by the caller. Thus the crtc_state must relinquish ownership of the event before returning with an error or we get a double free. Quickly smoke tested with kms_flip and kms_atomic* on a TGL, and ran the new kunits of course. Assisted by Claude Sonnet 5.5. Ville Syrjälä (4): drm: Add drm_event_release_completion() drm/atomic-helper: Detach the caller's event on page flip failure drm/atomic: Free unconsumed events in the CRTC state destructor drm/tests: Test event ownership in atomic states drivers/gpu/drm/drm_atomic_helper.c | 41 +++- drivers/gpu/drm/drm_atomic_state_helper.c | 29 ++- drivers/gpu/drm/drm_atomic_uapi.c | 24 +-- drivers/gpu/drm/drm_file.c | 28 ++- .../gpu/drm/tests/drm_atomic_commit_test.c | 201 +++++++++++++++++- include/drm/drm_atomic.h | 15 -- include/drm/drm_file.h | 1 + 7 files changed, 277 insertions(+), 62 deletions(-) -- 2.56.0
