[media] usbvision: 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>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
This commit is contained in:
Hans Verkuil 2015-03-09 13:34:12 -03:00 committed by Mauro Carvalho Chehab
parent 65b88c0be1
commit 2aa689dd80
2 changed files with 28 additions and 46 deletions

View File

@ -471,7 +471,7 @@ static int vidioc_g_register(struct file *file, void *priv,
/* NT100x has a 8-bit register space */ /* NT100x has a 8-bit register space */
err_code = usbvision_read_reg(usbvision, reg->reg&0xff); err_code = usbvision_read_reg(usbvision, reg->reg&0xff);
if (err_code < 0) { if (err_code < 0) {
dev_err(&usbvision->vdev->dev, dev_err(&usbvision->vdev.dev,
"%s: VIDIOC_DBG_G_REGISTER failed: error %d\n", "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n",
__func__, err_code); __func__, err_code);
return err_code; return err_code;
@ -490,7 +490,7 @@ static int vidioc_s_register(struct file *file, void *priv,
/* NT100x has a 8-bit register space */ /* NT100x has a 8-bit register space */
err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val); err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val);
if (err_code < 0) { if (err_code < 0) {
dev_err(&usbvision->vdev->dev, dev_err(&usbvision->vdev.dev,
"%s: VIDIOC_DBG_S_REGISTER failed: error %d\n", "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n",
__func__, err_code); __func__, err_code);
return err_code; return err_code;
@ -1157,7 +1157,7 @@ static int usbvision_radio_open(struct file *file)
if (mutex_lock_interruptible(&usbvision->v4l2_lock)) if (mutex_lock_interruptible(&usbvision->v4l2_lock))
return -ERESTARTSYS; return -ERESTARTSYS;
if (usbvision->user) { if (usbvision->user) {
dev_err(&usbvision->rdev->dev, dev_err(&usbvision->rdev.dev,
"%s: Someone tried to open an already opened USBVision Radio!\n", "%s: Someone tried to open an already opened USBVision Radio!\n",
__func__); __func__);
err_code = -EBUSY; err_code = -EBUSY;
@ -1280,7 +1280,7 @@ static struct video_device usbvision_video_template = {
.fops = &usbvision_fops, .fops = &usbvision_fops,
.ioctl_ops = &usbvision_ioctl_ops, .ioctl_ops = &usbvision_ioctl_ops,
.name = "usbvision-video", .name = "usbvision-video",
.release = video_device_release, .release = video_device_release_empty,
.tvnorms = USBVISION_NORMS, .tvnorms = USBVISION_NORMS,
}; };
@ -1312,58 +1312,46 @@ static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = {
static struct video_device usbvision_radio_template = { static struct video_device usbvision_radio_template = {
.fops = &usbvision_radio_fops, .fops = &usbvision_radio_fops,
.name = "usbvision-radio", .name = "usbvision-radio",
.release = video_device_release, .release = video_device_release_empty,
.ioctl_ops = &usbvision_radio_ioctl_ops, .ioctl_ops = &usbvision_radio_ioctl_ops,
}; };
static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision, static void usbvision_vdev_init(struct usb_usbvision *usbvision,
struct video_device *vdev_template, struct video_device *vdev,
char *name) const struct video_device *vdev_template,
const char *name)
{ {
struct usb_device *usb_dev = usbvision->dev; struct usb_device *usb_dev = usbvision->dev;
struct video_device *vdev;
if (usb_dev == NULL) { if (usb_dev == NULL) {
dev_err(&usbvision->dev->dev, dev_err(&usbvision->dev->dev,
"%s: usbvision->dev is not set\n", __func__); "%s: usbvision->dev is not set\n", __func__);
return NULL; return;
} }
vdev = video_device_alloc();
if (NULL == vdev)
return NULL;
*vdev = *vdev_template; *vdev = *vdev_template;
vdev->lock = &usbvision->v4l2_lock; vdev->lock = &usbvision->v4l2_lock;
vdev->v4l2_dev = &usbvision->v4l2_dev; vdev->v4l2_dev = &usbvision->v4l2_dev;
snprintf(vdev->name, sizeof(vdev->name), "%s", name); snprintf(vdev->name, sizeof(vdev->name), "%s", name);
video_set_drvdata(vdev, usbvision); video_set_drvdata(vdev, usbvision);
return vdev;
} }
/* unregister video4linux devices */ /* unregister video4linux devices */
static void usbvision_unregister_video(struct usb_usbvision *usbvision) static void usbvision_unregister_video(struct usb_usbvision *usbvision)
{ {
/* Radio Device: */ /* Radio Device: */
if (usbvision->rdev) { if (video_is_registered(&usbvision->rdev)) {
PDEBUG(DBG_PROBE, "unregister %s [v4l2]", PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
video_device_node_name(usbvision->rdev)); video_device_node_name(&usbvision->rdev));
if (video_is_registered(usbvision->rdev)) video_unregister_device(&usbvision->rdev);
video_unregister_device(usbvision->rdev);
else
video_device_release(usbvision->rdev);
usbvision->rdev = NULL;
} }
/* Video Device: */ /* Video Device: */
if (usbvision->vdev) { if (video_is_registered(&usbvision->vdev)) {
PDEBUG(DBG_PROBE, "unregister %s [v4l2]", PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
video_device_node_name(usbvision->vdev)); video_device_node_name(&usbvision->vdev));
if (video_is_registered(usbvision->vdev)) video_unregister_device(&usbvision->vdev);
video_unregister_device(usbvision->vdev);
else
video_device_release(usbvision->vdev);
usbvision->vdev = NULL;
} }
} }
@ -1371,28 +1359,22 @@ static void usbvision_unregister_video(struct usb_usbvision *usbvision)
static int usbvision_register_video(struct usb_usbvision *usbvision) static int usbvision_register_video(struct usb_usbvision *usbvision)
{ {
/* Video Device: */ /* Video Device: */
usbvision->vdev = usbvision_vdev_init(usbvision, usbvision_vdev_init(usbvision, &usbvision->vdev,
&usbvision_video_template, &usbvision_video_template, "USBVision Video");
"USBVision Video"); if (video_register_device(&usbvision->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
if (usbvision->vdev == NULL)
goto err_exit;
if (video_register_device(usbvision->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
goto err_exit; goto err_exit;
printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n", printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n",
usbvision->nr, video_device_node_name(usbvision->vdev)); usbvision->nr, video_device_node_name(&usbvision->vdev));
/* Radio Device: */ /* Radio Device: */
if (usbvision_device_data[usbvision->dev_model].radio) { if (usbvision_device_data[usbvision->dev_model].radio) {
/* usbvision has radio */ /* usbvision has radio */
usbvision->rdev = usbvision_vdev_init(usbvision, usbvision_vdev_init(usbvision, &usbvision->rdev,
&usbvision_radio_template, &usbvision_radio_template, "USBVision Radio");
"USBVision Radio"); if (video_register_device(&usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0)
if (usbvision->rdev == NULL)
goto err_exit;
if (video_register_device(usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0)
goto err_exit; goto err_exit;
printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n", printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n",
usbvision->nr, video_device_node_name(usbvision->rdev)); usbvision->nr, video_device_node_name(&usbvision->rdev));
} }
/* all done */ /* all done */
return 0; return 0;
@ -1461,7 +1443,7 @@ static void usbvision_release(struct usb_usbvision *usbvision)
usbvision->initialized = 0; usbvision->initialized = 0;
usbvision_remove_sysfs(usbvision->vdev); usbvision_remove_sysfs(&usbvision->vdev);
usbvision_unregister_video(usbvision); usbvision_unregister_video(usbvision);
kfree(usbvision->alt_max_pkt_size); kfree(usbvision->alt_max_pkt_size);
@ -1611,7 +1593,7 @@ static int usbvision_probe(struct usb_interface *intf,
usbvision_configure_video(usbvision); usbvision_configure_video(usbvision);
usbvision_register_video(usbvision); usbvision_register_video(usbvision);
usbvision_create_sysfs(usbvision->vdev); usbvision_create_sysfs(&usbvision->vdev);
PDEBUG(DBG_PROBE, "success"); PDEBUG(DBG_PROBE, "success");
return 0; return 0;

View File

@ -357,8 +357,8 @@ extern struct usb_device_id usbvision_table[];
struct usb_usbvision { struct usb_usbvision {
struct v4l2_device v4l2_dev; struct v4l2_device v4l2_dev;
struct video_device *vdev; /* Video Device */ struct video_device vdev; /* Video Device */
struct video_device *rdev; /* Radio Device */ struct video_device rdev; /* Radio Device */
/* i2c Declaration Section*/ /* i2c Declaration Section*/
struct i2c_adapter i2c_adap; struct i2c_adapter i2c_adap;