From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8788DC76186 for ; Wed, 24 Jul 2019 20:06:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 58C68205C9 for ; Wed, 24 Jul 2019 20:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563998769; bh=m30fGW7Z45idQ7eK1BrPE7brW3ZBvJ4KcDs4k+XYoR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=IP+NwqF7ZiixRDgWMMg07742MkG5DFR78R+OlrxEhPIP1PKV7D/q/mMWPFdoyDSOB Ql0vk0cqwCq8sOxIUeIUvJfGnRPUcBrgVQ/mDIXlgY7Y+eD7OE2PPnUeSlppN9lXWb GUpJSdyeiuLcumyRzhsci1ZObttLA3IsIzUib42E= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392745AbfGXUFu (ORCPT ); Wed, 24 Jul 2019 16:05:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:57622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392737AbfGXUFt (ORCPT ); Wed, 24 Jul 2019 16:05:49 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 306FC205C9; Wed, 24 Jul 2019 20:05:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563998748; bh=m30fGW7Z45idQ7eK1BrPE7brW3ZBvJ4KcDs4k+XYoR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FMkSbMT1gTHfJ2cb2rKuRzScCtksz/J4lSwR6iMgxRNHLXIKeHtKgK7UWXi2UX64L cfdbALVTUG/7p6bTg2g6J5Pg1E8sCOexQdg1vYuT5HKVezzjBlOhqeXgKSaAPjdvLD 4VUcmmLK4A8lQ15+zNq3/8uQNy+/EZDoloBALBQI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marco Felsch , Lucas Stach , Philipp Zabel , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.19 100/271] media: coda: fix last buffer handling in V4L2_ENC_CMD_STOP Date: Wed, 24 Jul 2019 21:19:29 +0200 Message-Id: <20190724191703.793802825@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit f3775f89852d167990b0d718587774cf00d22ac2 ] coda_encoder_cmd() is racy, as the last scheduled picture run worker can still be in-flight while the ENC_CMD_STOP command is issued. Depending on the exact timing the sequence numbers might already be changed, but the last buffer might not have been put on the destination queue yet. In this case the current implementation would prematurely wake the destination queue with last_buffer_dequeued=true, causing userspace to call streamoff before the last buffer is handled. Close this race window by synchronizing with the pic_run_worker before doing the sequence check. Signed-off-by: Marco Felsch [l.stach@pengutronix.de: switch to flush_work, reword commit message] Signed-off-by: Lucas Stach Signed-off-by: Philipp Zabel Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/coda/coda-common.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c index 19d92edcc981..4b0220f40b42 100644 --- a/drivers/media/platform/coda/coda-common.c +++ b/drivers/media/platform/coda/coda-common.c @@ -997,6 +997,8 @@ static int coda_encoder_cmd(struct file *file, void *fh, /* Set the stream-end flag on this context */ ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; + flush_work(&ctx->pic_run_work); + /* If there is no buffer in flight, wake up */ if (!ctx->streamon_out || ctx->qsequence == ctx->osequence) { dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, -- 2.20.1