Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] v4l: vsp1: Fix race condition when stopping pipeline

When stopping the pipeline the driver waits for the pipeline state to be
set to VSP1_PIPELINE_STOPPED but fails to lock the pipe irqlock to read
the state variable protected by the lock. Fix it.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Laurent Pinchart and committed by
Mauro Carvalho Chehab
1c991fee 139c9286

+14 -3
+14 -3
drivers/media/platform/vsp1/vsp1_video.c
··· 514 514 pipe->buffers_ready = 0; 515 515 } 516 516 517 + bool vsp1_pipeline_stopped(struct vsp1_pipeline *pipe) 518 + { 519 + unsigned long flags; 520 + bool stopped; 521 + 522 + spin_lock_irqsave(&pipe->irqlock, flags); 523 + stopped = pipe->state == VSP1_PIPELINE_STOPPED, 524 + spin_unlock_irqrestore(&pipe->irqlock, flags); 525 + 526 + return stopped; 527 + } 528 + 517 529 static int vsp1_pipeline_stop(struct vsp1_pipeline *pipe) 518 530 { 519 531 struct vsp1_entity *entity; ··· 537 525 pipe->state = VSP1_PIPELINE_STOPPING; 538 526 spin_unlock_irqrestore(&pipe->irqlock, flags); 539 527 540 - ret = wait_event_timeout(pipe->wq, pipe->state == VSP1_PIPELINE_STOPPED, 528 + ret = wait_event_timeout(pipe->wq, vsp1_pipeline_stopped(pipe), 541 529 msecs_to_jiffies(500)); 542 530 ret = ret == 0 ? -ETIMEDOUT : 0; 543 531 ··· 753 741 if (pipe == NULL) 754 742 continue; 755 743 756 - ret = wait_event_timeout(pipe->wq, 757 - pipe->state == VSP1_PIPELINE_STOPPED, 744 + ret = wait_event_timeout(pipe->wq, vsp1_pipeline_stopped(pipe), 758 745 msecs_to_jiffies(500)); 759 746 if (ret == 0) 760 747 dev_warn(vsp1->dev, "pipeline %u stop timeout\n",