Commit 9dd0627d authored by Sakari Ailus's avatar Sakari Ailus Committed by Mauro Carvalho Chehab

media: uvcvideo: Avoid NULL pointer dereference at the end of streaming

The UVC video driver converts the timestamp from hardware specific unit
to one known by the kernel at the time when the buffer is dequeued. This
is fine in general, but the streamoff operation consists of the
following steps (among other things):

1. uvc_video_clock_cleanup --- the hardware clock sample array is
   released and the pointer to the array is set to NULL,

2. buffers in active state are returned to the user and

3. buf_finish callback is called on buffers that are prepared.
   buf_finish includes calling uvc_video_clock_update that accesses the
   hardware clock sample array.

The above is serialised by a queue specific mutex. Address the problem
by skipping the clock conversion if the hardware clock sample array is
already released.

Fixes: 9c0863b1 ("[media] vb2: call buf_finish from __queue_cancel")
Reported-by: default avatarChiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
Tested-by: default avatarChiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 47bb1179
...@@ -676,6 +676,14 @@ void uvc_video_clock_update(struct uvc_streaming *stream, ...@@ -676,6 +676,14 @@ void uvc_video_clock_update(struct uvc_streaming *stream,
if (!uvc_hw_timestamps_param) if (!uvc_hw_timestamps_param)
return; return;
/*
* We will get called from __vb2_queue_cancel() if there are buffers
* done but not dequeued by the user, but the sample array has already
* been released at that time. Just bail out in that case.
*/
if (!clock->samples)
return;
spin_lock_irqsave(&clock->lock, flags); spin_lock_irqsave(&clock->lock, flags);
if (clock->count < clock->size) if (clock->count < clock->size)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment