[media] zr364xx: embed video_device and register it at the end of probe
Embed the video_device struct instead of allocating it and register it as the last thing in probe(). Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
parent
f7dd6c247f
commit
2b99251f17
1 changed files with 16 additions and 30 deletions
|
@ -173,7 +173,7 @@ static const struct zr364xx_fmt formats[] = {
|
||||||
struct zr364xx_camera {
|
struct zr364xx_camera {
|
||||||
struct usb_device *udev; /* save off the usb device pointer */
|
struct usb_device *udev; /* save off the usb device pointer */
|
||||||
struct usb_interface *interface;/* the interface for this device */
|
struct usb_interface *interface;/* the interface for this device */
|
||||||
struct video_device *vdev; /* v4l video device */
|
struct video_device vdev; /* v4l video device */
|
||||||
int nb;
|
int nb;
|
||||||
struct zr364xx_bufferi buffer;
|
struct zr364xx_bufferi buffer;
|
||||||
int skip;
|
int skip;
|
||||||
|
@ -1322,9 +1322,7 @@ static void zr364xx_destroy(struct zr364xx_camera *cam)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mutex_lock(&cam->open_lock);
|
mutex_lock(&cam->open_lock);
|
||||||
if (cam->vdev)
|
video_unregister_device(&cam->vdev);
|
||||||
video_unregister_device(cam->vdev);
|
|
||||||
cam->vdev = NULL;
|
|
||||||
|
|
||||||
/* stops the read pipe if it is running */
|
/* stops the read pipe if it is running */
|
||||||
if (cam->b_acquire)
|
if (cam->b_acquire)
|
||||||
|
@ -1346,7 +1344,6 @@ static void zr364xx_destroy(struct zr364xx_camera *cam)
|
||||||
cam->pipe->transfer_buffer = NULL;
|
cam->pipe->transfer_buffer = NULL;
|
||||||
mutex_unlock(&cam->open_lock);
|
mutex_unlock(&cam->open_lock);
|
||||||
kfree(cam);
|
kfree(cam);
|
||||||
cam = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* release the camera */
|
/* release the camera */
|
||||||
|
@ -1466,7 +1463,7 @@ static struct video_device zr364xx_template = {
|
||||||
.name = DRIVER_DESC,
|
.name = DRIVER_DESC,
|
||||||
.fops = &zr364xx_fops,
|
.fops = &zr364xx_fops,
|
||||||
.ioctl_ops = &zr364xx_ioctl_ops,
|
.ioctl_ops = &zr364xx_ioctl_ops,
|
||||||
.release = video_device_release,
|
.release = video_device_release_empty,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1557,19 +1554,11 @@ static int zr364xx_probe(struct usb_interface *intf,
|
||||||
}
|
}
|
||||||
/* save the init method used by this camera */
|
/* save the init method used by this camera */
|
||||||
cam->method = id->driver_info;
|
cam->method = id->driver_info;
|
||||||
|
cam->vdev = zr364xx_template;
|
||||||
cam->vdev = video_device_alloc();
|
cam->vdev.parent = &intf->dev;
|
||||||
if (cam->vdev == NULL) {
|
video_set_drvdata(&cam->vdev, cam);
|
||||||
dev_err(&udev->dev, "cam->vdev: out of memory !\n");
|
|
||||||
kfree(cam);
|
|
||||||
cam = NULL;
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
memcpy(cam->vdev, &zr364xx_template, sizeof(zr364xx_template));
|
|
||||||
cam->vdev->parent = &intf->dev;
|
|
||||||
video_set_drvdata(cam->vdev, cam);
|
|
||||||
if (debug)
|
if (debug)
|
||||||
cam->vdev->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
|
cam->vdev.debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
|
||||||
|
|
||||||
cam->udev = udev;
|
cam->udev = udev;
|
||||||
|
|
||||||
|
@ -1636,37 +1625,34 @@ static int zr364xx_probe(struct usb_interface *intf,
|
||||||
|
|
||||||
if (!cam->read_endpoint) {
|
if (!cam->read_endpoint) {
|
||||||
dev_err(&intf->dev, "Could not find bulk-in endpoint\n");
|
dev_err(&intf->dev, "Could not find bulk-in endpoint\n");
|
||||||
video_device_release(cam->vdev);
|
|
||||||
kfree(cam);
|
kfree(cam);
|
||||||
cam = NULL;
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* v4l */
|
/* v4l */
|
||||||
INIT_LIST_HEAD(&cam->vidq.active);
|
INIT_LIST_HEAD(&cam->vidq.active);
|
||||||
cam->vidq.cam = cam;
|
cam->vidq.cam = cam;
|
||||||
err = video_register_device(cam->vdev, VFL_TYPE_GRABBER, -1);
|
|
||||||
if (err) {
|
|
||||||
dev_err(&udev->dev, "video_register_device failed\n");
|
|
||||||
video_device_release(cam->vdev);
|
|
||||||
kfree(cam);
|
|
||||||
cam = NULL;
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
usb_set_intfdata(intf, cam);
|
usb_set_intfdata(intf, cam);
|
||||||
|
|
||||||
/* load zr364xx board specific */
|
/* load zr364xx board specific */
|
||||||
err = zr364xx_board_init(cam);
|
err = zr364xx_board_init(cam);
|
||||||
if (err) {
|
if (err) {
|
||||||
spin_lock_init(&cam->slock);
|
kfree(cam);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock_init(&cam->slock);
|
spin_lock_init(&cam->slock);
|
||||||
|
|
||||||
|
err = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1);
|
||||||
|
if (err) {
|
||||||
|
dev_err(&udev->dev, "video_register_device failed\n");
|
||||||
|
kfree(cam);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
dev_info(&udev->dev, DRIVER_DESC " controlling device %s\n",
|
dev_info(&udev->dev, DRIVER_DESC " controlling device %s\n",
|
||||||
video_device_node_name(cam->vdev));
|
video_device_node_name(&cam->vdev));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue