media: v4l2-core: hold videodev_lock until dev reg, finishes

commit 1ed4477f2ea4743e7c5e1f9f3722152d14e6eeb1 upstream.

After the new V4L2 device node was registered, some additional
initialization was done before the device node was marked as
'registered'. During the time between creating the device node
and marking it as 'registered' it was possible to open the
device node, which would return -ENODEV since the 'registered'
flag was not yet set.

Hold the videodev_lock mutex from just before the device node
is registered until the 'registered' flag is set. Since v4l2_open
will take the same lock, it will wait until this registration
process is finished. This resolves this race condition.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: <stable@vger.kernel.org>      # for vi4.18 and up
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 1ea3de272f5cc7603610b96316f9ed07bec6c2d0)
[Vegard: fix conflict due to missing commit
 baa057e29b5824b3727e2eb643e513ba5e35aea0 ("media: v4l2-dev: use
 pr_foo() for printing messages")]
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
1 file changed