upstream: [media] vb2: fix race condition between REQBUFS and QBUF/PREPARE_BUF
authorHans Verkuil <hans.verkuil@cisco.com>
Fri, 13 Dec 2013 16:13:40 +0000 (13:13 -0300)
committerChanho Park <chanho61.park@samsung.com>
Tue, 18 Nov 2014 02:52:51 +0000 (11:52 +0900)
commit791129f2d3fc9058c596ee7e994f08fc2445cf0d
treed66f9e95218220333ae8cf738c5a1631f40cb1c8
parenta5e94b241ab5205f5cfaf1662e2554d18b007cc7
upstream: [media] vb2: fix race condition between REQBUFS and QBUF/PREPARE_BUF

When preparing a buffer the queue lock is released for a short while
if the memory mode is USERPTR (see __buf_prepare for the details), which
would allow a race with a REQBUFS which can free the buffers. Removing the
buffers from underneath __buf_prepare is obviously a bad idea, so we
check if any of the buffers is in the state PREPARING, and if so we
just return -EAGAIN.

If this happens, then the application does something really strange. The
REQBUFS call can be retried safely, since this situation is transient.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/media/v4l2-core/videobuf2-core.c