Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3784616ybi; Mon, 29 Jul 2019 12:33:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWeQ/iyubHAZ2YQ+h6P5UCmYTZQOO8gCFSKAEln6UpwJpugH41w1M+p7n1VRI4EP3qHOIj X-Received: by 2002:a63:2264:: with SMTP id t36mr99086137pgm.87.1564428836416; Mon, 29 Jul 2019 12:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564428836; cv=none; d=google.com; s=arc-20160816; b=SIJDc2NbXeEmkfgRLD/ZGNrG7OdhqKmRNn8qizRQJdFvvf5ZU1N/JBDs87uMg2EWMM Jkf5rUHOjAn5KJ6g5RzpDy0xXBU094bZMmjSR55VqKY6qYdPmQfOIMpFqc81dkYF+MHs z2tF+8x+3SbBY89zlYGi/14J6OHYLYi2zwy0I1Or4RvFoG920tZZYqngjPxGW+ffGg4N +MzuDEXI+7Cs965mlPtfF0whp14madPe1x4KKn+AfwvgCIlTCQJu4SF9P6R+fYguycaz 4JHuFDBQsbUHaxuseT/SJSf3OPYlI/HEaaznxILANScyYKaqS8d4ojrIpYOqes1t6LWZ 0FIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=h84k7usfaAzGx2Lcad73xy6aolWb8qJrRa9WqUtp/OA=; b=IjtIAYmvE2GeaatO0Vx31Yr2qPChgOe27HkajUqhGmRqW63lToXKehNdu2y3VGYmKN SC7L48Ds5I8b2o6kU+PdNYBtN69ct2cIqrK00XNwowJxI9TgXpVH53UoMQresxAip64y v3I/m/NOdAOGSgX9tTb3NaK/ZDBnSP6aJ5dMyz6lKUpcBNH8H80fsWf28r1qunCCOEys r5v64VprGVFT5S9LoBoVkUZ/gfXpjIFHyLXdRd4WCW5OcFbClHlqyFsm7UPGJNRBWo4/ ddkJWnEYHTI3npURFNyM8sNQe702LUNd5Ii3zhd4218YvsXuj68Uc85Kh/KRRGfmReZ1 299g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v3H1LbPv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t62si26503011pgd.175.2019.07.29.12.33.40; Mon, 29 Jul 2019 12:33:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v3H1LbPv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729839AbfG2T0y (ORCPT + 99 others); Mon, 29 Jul 2019 15:26:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:39330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729831AbfG2T0w (ORCPT ); Mon, 29 Jul 2019 15:26:52 -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 E1F2421655; Mon, 29 Jul 2019 19:26:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428411; bh=Th9uGvkZvs6hjOlKwzt2L5qfRyOhG8Rf+28gOkDNjkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v3H1LbPvyScFHRzq2Fb5bo5bWA0dbPQsalaw2jh1EZ6Gf7MT6fq99VFpY0XXPyNBW 58D1RTpUaerT1rNMY1czmtHLcLXzNWNRQHEz5/Yy1xaOUmIUeQtHTUE2TGW/JScebn j+3ORTWLQNJifLPEIdgU2/nk2Vd9KbODVs42S6Ak= 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.14 068/293] media: coda: fix last buffer handling in V4L2_ENC_CMD_STOP Date: Mon, 29 Jul 2019 21:19:19 +0200 Message-Id: <20190729190829.876691158@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 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