[PATCH v1 1/6] drm/mediatek: put "event" in critical section

Bibby Hsieh
2019-11-28T02:45:14Z

The state->base.event variable would be access by thread context
in mtk_drm_crtc_atomic_begin() or by interrupt context in
mtk_drm_crtc_finish_page_flip(), so each part should be a critical
section. Fix it.

Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")

Signed-off-by: Bibby Hsieh <bibby.hsieh@mediatek.com>
---
drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
index 29d0582e90e9..71f4089a8117 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
@@ -483,12 +483,15 @@ static void mtk_drm_crtc_atomic_begin(struct drm_crtc *crtc,
if (mtk_crtc->event && state->base.event)
DRM_ERROR("new event while there is still a pending event\n");

+ spin_lock_irq(&crtc->dev->event_lock);
if (state->base.event) {
state->base.event->pipe = drm_crtc_index(crtc);
WARN_ON(drm_crtc_vblank_get(crtc) != 0);
+ WARN_ON(mtk_crtc->event);
mtk_crtc->event = state->base.event;
state->base.event = NULL;
}
+ spin_unlock_irq(&crtc->dev->event_lock);
}

static void mtk_drm_crtc_atomic_flush(struct drm_crtc *crtc,
--
2.18.0