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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 EBCC8C7618F for ; Mon, 15 Jul 2019 14:32:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C49F9217D9 for ; Mon, 15 Jul 2019 14:32:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563201167; bh=FmIxg1E8fnpZETo8KkhHgz61ED8/wVXUeRug/IqXC5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=sweJA+y6FG0SeUlLlj1TAmYXOh9rdKYYQne+4zRRsT3kT6hdJHxM+3o9fJNbZ3rai kOYCK7hmRGl8UNM+eGFm8wrWVa4Ix/a7ifgV8ehRQ6zotirtzudIBgSnWXDM42a3oF HqmJUU1Nq8pu3UM6kxDpQqHZ28ipMMfuz0vTFMhs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391900AbfGOOcq (ORCPT ); Mon, 15 Jul 2019 10:32:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:48154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391898AbfGOOcp (ORCPT ); Mon, 15 Jul 2019 10:32:45 -0400 Received: from sasha-vm.mshome.net (unknown [73.61.17.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B7052086C; Mon, 15 Jul 2019 14:32:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563201164; bh=FmIxg1E8fnpZETo8KkhHgz61ED8/wVXUeRug/IqXC5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CEl/G/FXgl3rLBygc6wfmLvCMBMCLjQMkjL7y3yCwScsMIlAe3WhVcBQ9ZUrLHFOO WUTfGTf6dJc2QN8RRwfHNjSxsXGuC1slLqPwWNc64BbNdmx3LUcnMYN81YaKukiEnr GM9GZUTSLFWqkadDAbcjFNt9OhlPQj4IR2ZgDOGE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Marco Felsch , Lucas Stach , Philipp Zabel , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 067/105] media: coda: fix last buffer handling in V4L2_ENC_CMD_STOP Date: Mon, 15 Jul 2019 10:28:01 -0400 Message-Id: <20190715142839.9896-67-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190715142839.9896-1-sashal@kernel.org> References: <20190715142839.9896-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Marco Felsch [ 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 2e1472fadc2c..5b87c488ee11 100644 --- a/drivers/media/platform/coda/coda-common.c +++ b/drivers/media/platform/coda/coda-common.c @@ -932,6 +932,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