[media] uvc: embed video_device
Embed the video_device struct to simplify the error handling and in order to (eventually) get rid of video_device_alloc/release. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
This commit is contained in:
parent
d4352f3639
commit
d8da7513bc
|
@ -1669,10 +1669,6 @@ static void uvc_delete(struct uvc_device *dev)
|
||||||
#ifdef CONFIG_MEDIA_CONTROLLER
|
#ifdef CONFIG_MEDIA_CONTROLLER
|
||||||
uvc_mc_cleanup_entity(entity);
|
uvc_mc_cleanup_entity(entity);
|
||||||
#endif
|
#endif
|
||||||
if (entity->vdev) {
|
|
||||||
video_device_release(entity->vdev);
|
|
||||||
entity->vdev = NULL;
|
|
||||||
}
|
|
||||||
kfree(entity);
|
kfree(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1717,11 +1713,10 @@ static void uvc_unregister_video(struct uvc_device *dev)
|
||||||
atomic_inc(&dev->nstreams);
|
atomic_inc(&dev->nstreams);
|
||||||
|
|
||||||
list_for_each_entry(stream, &dev->streams, list) {
|
list_for_each_entry(stream, &dev->streams, list) {
|
||||||
if (stream->vdev == NULL)
|
if (!video_is_registered(&stream->vdev))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
video_unregister_device(stream->vdev);
|
video_unregister_device(&stream->vdev);
|
||||||
stream->vdev = NULL;
|
|
||||||
|
|
||||||
uvc_debugfs_cleanup_stream(stream);
|
uvc_debugfs_cleanup_stream(stream);
|
||||||
}
|
}
|
||||||
|
@ -1736,7 +1731,7 @@ static void uvc_unregister_video(struct uvc_device *dev)
|
||||||
static int uvc_register_video(struct uvc_device *dev,
|
static int uvc_register_video(struct uvc_device *dev,
|
||||||
struct uvc_streaming *stream)
|
struct uvc_streaming *stream)
|
||||||
{
|
{
|
||||||
struct video_device *vdev;
|
struct video_device *vdev = &stream->vdev;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Initialize the video buffers queue. */
|
/* Initialize the video buffers queue. */
|
||||||
|
@ -1757,12 +1752,6 @@ static int uvc_register_video(struct uvc_device *dev,
|
||||||
uvc_debugfs_init_stream(stream);
|
uvc_debugfs_init_stream(stream);
|
||||||
|
|
||||||
/* Register the device with V4L. */
|
/* Register the device with V4L. */
|
||||||
vdev = video_device_alloc();
|
|
||||||
if (vdev == NULL) {
|
|
||||||
uvc_printk(KERN_ERR, "Failed to allocate video device (%d).\n",
|
|
||||||
ret);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We already hold a reference to dev->udev. The video device will be
|
/* We already hold a reference to dev->udev. The video device will be
|
||||||
* unregistered before the reference is released, so we don't need to
|
* unregistered before the reference is released, so we don't need to
|
||||||
|
@ -1780,15 +1769,12 @@ static int uvc_register_video(struct uvc_device *dev,
|
||||||
/* Set the driver data before calling video_register_device, otherwise
|
/* Set the driver data before calling video_register_device, otherwise
|
||||||
* uvc_v4l2_open might race us.
|
* uvc_v4l2_open might race us.
|
||||||
*/
|
*/
|
||||||
stream->vdev = vdev;
|
|
||||||
video_set_drvdata(vdev, stream);
|
video_set_drvdata(vdev, stream);
|
||||||
|
|
||||||
ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
|
ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
|
uvc_printk(KERN_ERR, "Failed to register video device (%d).\n",
|
||||||
ret);
|
ret);
|
||||||
stream->vdev = NULL;
|
|
||||||
video_device_release(vdev);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1827,7 +1813,7 @@ static int uvc_register_terms(struct uvc_device *dev,
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
term->vdev = stream->vdev;
|
term->vdev = &stream->vdev;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -511,7 +511,7 @@ static int uvc_v4l2_open(struct file *file)
|
||||||
stream->dev->users++;
|
stream->dev->users++;
|
||||||
mutex_unlock(&stream->dev->lock);
|
mutex_unlock(&stream->dev->lock);
|
||||||
|
|
||||||
v4l2_fh_init(&handle->vfh, stream->vdev);
|
v4l2_fh_init(&handle->vfh, &stream->vdev);
|
||||||
v4l2_fh_add(&handle->vfh);
|
v4l2_fh_add(&handle->vfh);
|
||||||
handle->chain = stream->chain;
|
handle->chain = stream->chain;
|
||||||
handle->stream = stream;
|
handle->stream = stream;
|
||||||
|
|
|
@ -443,7 +443,7 @@ struct uvc_stats_stream {
|
||||||
struct uvc_streaming {
|
struct uvc_streaming {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
struct uvc_device *dev;
|
struct uvc_device *dev;
|
||||||
struct video_device *vdev;
|
struct video_device vdev;
|
||||||
struct uvc_video_chain *chain;
|
struct uvc_video_chain *chain;
|
||||||
atomic_t active;
|
atomic_t active;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue