From ec1b93751c03c69ce1925ad7cf6d95c2d12a91d1 Mon Sep 17 00:00:00 2001 From: Amine Najahi Date: Wed, 2 Sep 2020 12:51:21 -0400 Subject: [PATCH] disp: msm: sde: fix race condition in scheduler idle function Currently driver reads CTL status register before checking pending kickoff counter. This can lead to a register access violation when there is a race condition between the ESD and commit thread. This change checks pending kickoff counter before reading CTL status register. Change-Id: I5828b580c16d075df19eb349ee88d8b7da47941e Signed-off-by: Amine Najahi --- msm/sde/sde_encoder_phys_cmd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/msm/sde/sde_encoder_phys_cmd.c b/msm/sde/sde_encoder_phys_cmd.c index bee9a593..eac76f95 100644 --- a/msm/sde/sde_encoder_phys_cmd.c +++ b/msm/sde/sde_encoder_phys_cmd.c @@ -704,6 +704,8 @@ static bool _sde_encoder_phys_cmd_is_scheduler_idle( struct sde_encoder_phys_cmd *cmd_enc = to_sde_encoder_phys_cmd(phys_enc); struct sde_hw_ctl *ctl = phys_enc->hw_ctl; + enum frame_trigger_mode_type frame_trigger_mode = + phys_enc->frame_trigger_mode; if (sde_encoder_phys_cmd_is_master(phys_enc)) wr_ptr_wait_success = cmd_enc->wr_ptr_wait_success; @@ -713,11 +715,12 @@ static bool _sde_encoder_phys_cmd_is_scheduler_idle( * due to irq latency with POSTED start */ if (wr_ptr_wait_success && - (phys_enc->frame_trigger_mode == FRAME_DONE_WAIT_POSTED_START) && - ctl->ops.get_scheduler_status && - (ctl->ops.get_scheduler_status(ctl) & BIT(0)) && - atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0) && - phys_enc->parent_ops.handle_frame_done) { + (frame_trigger_mode == FRAME_DONE_WAIT_POSTED_START) && + ctl->ops.get_scheduler_status && + phys_enc->parent_ops.handle_frame_done && + atomic_read(&phys_enc->pending_kickoff_cnt) > 0 && + (ctl->ops.get_scheduler_status(ctl) & BIT(0)) && + atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0)) { spin_lock_irqsave(phys_enc->enc_spinlock, lock_flags); phys_enc->parent_ops.handle_frame_done(