{
        struct v4l2_fh *fh = file->private_data;
        struct mxc_jpeg_ctx *ctx = mxc_jpeg_fh_to_ctx(fh);
+       unsigned long flags;
        int ret;
 
        ret = v4l2_m2m_ioctl_try_decoder_cmd(file, fh, cmd);
        if (!vb2_is_streaming(v4l2_m2m_get_src_vq(fh->m2m_ctx)))
                return 0;
 
+       spin_lock_irqsave(&ctx->mxc_jpeg->hw_lock, flags);
        ret = v4l2_m2m_ioctl_decoder_cmd(file, priv, cmd);
+       spin_unlock_irqrestore(&ctx->mxc_jpeg->hw_lock, flags);
        if (ret < 0)
                return ret;
 
 {
        struct v4l2_fh *fh = file->private_data;
        struct mxc_jpeg_ctx *ctx = mxc_jpeg_fh_to_ctx(fh);
+       unsigned long flags;
        int ret;
 
        ret = v4l2_m2m_ioctl_try_encoder_cmd(file, fh, cmd);
            !vb2_is_streaming(v4l2_m2m_get_dst_vq(fh->m2m_ctx)))
                return 0;
 
+       spin_lock_irqsave(&ctx->mxc_jpeg->hw_lock, flags);
        ret = v4l2_m2m_ioctl_encoder_cmd(file, fh, cmd);
+       spin_unlock_irqrestore(&ctx->mxc_jpeg->hw_lock, flags);
        if (ret < 0)
                return 0;