]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
media: coda: fix last buffer handling in V4L2_ENC_CMD_STOP
authorMarco Felsch <m.felsch@pengutronix.de>
Tue, 18 Jun 2019 16:45:11 +0000 (12:45 -0400)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1839036
[ 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 <m.felsch@pengutronix.de>
[l.stach@pengutronix.de: switch to flush_work, reword commit message]
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/media/platform/coda/coda-common.c

index 2e1472fadc2c2d17da8b87faf90866098ea41d6f..5b87c488ee111d3ce886ee4f9bf3ca0cdef4b756 100644 (file)
@@ -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,