int ret;
 
        spin_lock_irqsave(&pipe->irqlock, flags);
-       pipe->state = VSP1_PIPELINE_STOPPING;
+       if (pipe->state == VSP1_PIPELINE_RUNNING)
+               pipe->state = VSP1_PIPELINE_STOPPING;
        spin_unlock_irqrestore(&pipe->irqlock, flags);
 
        ret = wait_event_timeout(pipe->wq, pipe->state == VSP1_PIPELINE_STOPPED,
 
 void vsp1_pipeline_frame_end(struct vsp1_pipeline *pipe)
 {
+       enum vsp1_pipeline_state state;
        unsigned long flags;
        unsigned int i;
 
 
        spin_lock_irqsave(&pipe->irqlock, flags);
 
+       state = pipe->state;
+       pipe->state = VSP1_PIPELINE_STOPPED;
+
        /* If a stop has been requested, mark the pipeline as stopped and
         * return.
         */
-       if (pipe->state == VSP1_PIPELINE_STOPPING) {
-               pipe->state = VSP1_PIPELINE_STOPPED;
+       if (state == VSP1_PIPELINE_STOPPING) {
                wake_up(&pipe->wq);
                goto done;
        }