int v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev) { fh->vdev = vdev; INIT_LIST_HEAD(&fh->list); set_bit(V4L2_FL_USES_V4L2_FH, &fh->vdev->flags); /* * fh->events only needs to be initialized if the driver * supports the VIDIOC_SUBSCRIBE_EVENT ioctl. */ if (vdev->ioctl_ops && vdev->ioctl_ops->vidioc_subscribe_event) return v4l2_event_init(fh); fh->events = NULL; return 0; }
static int uvc_v4l2_open(struct file *file) { struct video_device *vdev = video_devdata(file); struct uvc_device *uvc = video_get_drvdata(vdev); struct uvc_file_handle *handle; int ret; handle = kzalloc(sizeof(*handle), GFP_KERNEL); if (handle == NULL) return -ENOMEM; ret = v4l2_fh_init(&handle->vfh, vdev); if (ret < 0) goto error; ret = v4l2_event_init(&handle->vfh); if (ret < 0) goto error; ret = v4l2_event_alloc(&handle->vfh, 8); if (ret < 0) goto error; v4l2_fh_add(&handle->vfh); handle->device = &uvc->video; file->private_data = &handle->vfh; uvc_function_connect(uvc); return 0; error: v4l2_fh_exit(&handle->vfh); return ret; }
static int subdev_open(struct file *file) { struct video_device *vdev = video_devdata(file); struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); struct v4l2_subdev_fh *subdev_fh; #if defined(CONFIG_MEDIA_CONTROLLER) struct media_entity *entity = NULL; #endif int ret; if (!sd->initialized) return -EAGAIN; subdev_fh = kzalloc(sizeof(*subdev_fh), GFP_KERNEL); if (subdev_fh == NULL) return -ENOMEM; ret = subdev_fh_init(subdev_fh, sd); if (ret) { kfree(subdev_fh); return ret; } ret = v4l2_fh_init(&subdev_fh->vfh, vdev); if (ret) goto err; if (sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS) { ret = v4l2_event_init(&subdev_fh->vfh); if (ret) goto err; ret = v4l2_event_alloc(&subdev_fh->vfh, sd->nevents); if (ret) goto err; } v4l2_fh_add(&subdev_fh->vfh); file->private_data = &subdev_fh->vfh; #if defined(CONFIG_MEDIA_CONTROLLER) if (sd->v4l2_dev->mdev) { entity = media_entity_get(&sd->entity); if (!entity) { ret = -EBUSY; goto err; } } #endif ret = v4l2_subdev_call(sd, file, open, subdev_fh); if (ret < 0 && ret != -ENOIOCTLCMD) goto err; return 0; err: #if defined(CONFIG_MEDIA_CONTROLLER) if (entity) media_entity_put(entity); #endif v4l2_fh_del(&subdev_fh->vfh); v4l2_fh_exit(&subdev_fh->vfh); subdev_fh_free(subdev_fh); kfree(subdev_fh); return ret; }