[media] vb2: fix vb2_thread_stop race conditions
authorHans Verkuil <hans.verkuil@cisco.com>
Mon, 19 Jan 2015 09:16:18 +0000 (06:16 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Wed, 21 Jan 2015 23:07:26 +0000 (21:07 -0200)
commit6cf11ee6300f38b7cfc43af9b7be2afaa5e05869
treed6df278332bd72f37c6d6f38586d1fc2a7b57cb5
parent42d74e4fe6508308abc1baac95ba36ad0cc5143e
[media] vb2: fix vb2_thread_stop race conditions

The locking scheme inside the vb2 thread is unsafe when stopping the
thread. In particular kthread_stop was called *after* internal data
structures were cleaned up instead of doing that before. In addition,
internal vb2 functions were called after threadio->stop was set to
true and vb2_internal_streamoff was called. This is also not allowed.

All this led to a variety of race conditions and kernel warnings and/or
oopses.

Fixed by moving the kthread_stop call up before the cleanup takes
place, and by checking threadio->stop before calling internal vb2
queuing operations.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Cc: <stable@vger.kernel.org> # for v3.16 and up
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/v4l2-core/videobuf2-core.c