Skip to content

Commit 427c4a0

Browse files
committed
drm/vc4: crtc: Rework a bit the CRTC state code
The current CRTC state reset hook in vc4 allocates a vc4_crtc_state structure as a drm_crtc_state, and relies on the fact that vc4_crtc_state embeds drm_crtc_state as its first member, and therefore can be safely cast. However, this is pretty fragile especially since there's no check for this in place, and we're going to need to access vc4_crtc_state member at reset so this looks like a good occasion to make it more robust. Fixes: 6d6e500 ("drm/vc4: Allocate the right amount of space for boot-time CRTC state.") Signed-off-by: Maxime Ripard <[email protected]> Tested-by: Dave Stevenson <[email protected]> Reviewed-by: Dave Stevenson <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent de19456 commit 427c4a0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/gpu/drm/vc4/vc4_crtc.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,11 +852,18 @@ void vc4_crtc_destroy_state(struct drm_crtc *crtc,
852852

853853
void vc4_crtc_reset(struct drm_crtc *crtc)
854854
{
855+
struct vc4_crtc_state *vc4_crtc_state;
856+
855857
if (crtc->state)
856858
vc4_crtc_destroy_state(crtc, crtc->state);
857-
crtc->state = kzalloc(sizeof(struct vc4_crtc_state), GFP_KERNEL);
858-
if (crtc->state)
859-
__drm_atomic_helper_crtc_reset(crtc, crtc->state);
859+
860+
vc4_crtc_state = kzalloc(sizeof(*vc4_crtc_state), GFP_KERNEL);
861+
if (!vc4_crtc_state) {
862+
crtc->state = NULL;
863+
return;
864+
}
865+
866+
__drm_atomic_helper_crtc_reset(crtc, &vc4_crtc_state->base);
860867
}
861868

862869
static const struct drm_crtc_funcs vc4_crtc_funcs = {

0 commit comments

Comments
 (0)