diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2015-03-09 12:34:12 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2015-04-02 22:52:21 -0400 |
commit | 2aa689dd80575606a569951467eee6ac98710d33 (patch) | |
tree | 5e3608decb0ff0352c9f334d7c67e93f4a834c66 /drivers/media/usb/usbvision/usbvision-video.c | |
parent | 65b88c0be1f3fff0c652db19d5e13d8448764cf5 (diff) |
[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>
Diffstat (limited to 'drivers/media/usb/usbvision/usbvision-video.c')
-rw-r--r-- | drivers/media/usb/usbvision/usbvision-video.c | 70 |
1 files changed, 26 insertions, 44 deletions
diff --git a/drivers/media/usb/usbvision/usbvision-video.c b/drivers/media/usb/usbvision/usbvision-video.c index cd2fbf11e3b4..2579c874b83b 100644 --- a/drivers/media/usb/usbvision/usbvision-video.c +++ b/drivers/media/usb/usbvision/usbvision-video.c | |||
@@ -471,7 +471,7 @@ static int vidioc_g_register(struct file *file, void *priv, | |||
471 | /* NT100x has a 8-bit register space */ | 471 | /* NT100x has a 8-bit register space */ |
472 | err_code = usbvision_read_reg(usbvision, reg->reg&0xff); | 472 | err_code = usbvision_read_reg(usbvision, reg->reg&0xff); |
473 | if (err_code < 0) { | 473 | if (err_code < 0) { |
474 | dev_err(&usbvision->vdev->dev, | 474 | dev_err(&usbvision->vdev.dev, |
475 | "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n", | 475 | "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n", |
476 | __func__, err_code); | 476 | __func__, err_code); |
477 | return err_code; | 477 | return err_code; |
@@ -490,7 +490,7 @@ static int vidioc_s_register(struct file *file, void *priv, | |||
490 | /* NT100x has a 8-bit register space */ | 490 | /* NT100x has a 8-bit register space */ |
491 | err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val); | 491 | err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val); |
492 | if (err_code < 0) { | 492 | if (err_code < 0) { |
493 | dev_err(&usbvision->vdev->dev, | 493 | dev_err(&usbvision->vdev.dev, |
494 | "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n", | 494 | "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n", |
495 | __func__, err_code); | 495 | __func__, err_code); |
496 | return err_code; | 496 | return err_code; |
@@ -1157,7 +1157,7 @@ static int usbvision_radio_open(struct file *file) | |||
1157 | if (mutex_lock_interruptible(&usbvision->v4l2_lock)) | 1157 | if (mutex_lock_interruptible(&usbvision->v4l2_lock)) |
1158 | return -ERESTARTSYS; | 1158 | return -ERESTARTSYS; |
1159 | if (usbvision->user) { | 1159 | if (usbvision->user) { |
1160 | dev_err(&usbvision->rdev->dev, | 1160 | dev_err(&usbvision->rdev.dev, |
1161 | "%s: Someone tried to open an already opened USBVision Radio!\n", | 1161 | "%s: Someone tried to open an already opened USBVision Radio!\n", |
1162 | __func__); | 1162 | __func__); |
1163 | err_code = -EBUSY; | 1163 | err_code = -EBUSY; |
@@ -1280,7 +1280,7 @@ static struct video_device usbvision_video_template = { | |||
1280 | .fops = &usbvision_fops, | 1280 | .fops = &usbvision_fops, |
1281 | .ioctl_ops = &usbvision_ioctl_ops, | 1281 | .ioctl_ops = &usbvision_ioctl_ops, |
1282 | .name = "usbvision-video", | 1282 | .name = "usbvision-video", |
1283 | .release = video_device_release, | 1283 | .release = video_device_release_empty, |
1284 | .tvnorms = USBVISION_NORMS, | 1284 | .tvnorms = USBVISION_NORMS, |
1285 | }; | 1285 | }; |
1286 | 1286 | ||
@@ -1312,58 +1312,46 @@ static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = { | |||
1312 | static struct video_device usbvision_radio_template = { | 1312 | static struct video_device usbvision_radio_template = { |
1313 | .fops = &usbvision_radio_fops, | 1313 | .fops = &usbvision_radio_fops, |
1314 | .name = "usbvision-radio", | 1314 | .name = "usbvision-radio", |
1315 | .release = video_device_release, | 1315 | .release = video_device_release_empty, |
1316 | .ioctl_ops = &usbvision_radio_ioctl_ops, | 1316 | .ioctl_ops = &usbvision_radio_ioctl_ops, |
1317 | }; | 1317 | }; |
1318 | 1318 | ||
1319 | 1319 | ||
1320 | static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision, | 1320 | static void usbvision_vdev_init(struct usb_usbvision *usbvision, |
1321 | struct video_device *vdev_template, | 1321 | struct video_device *vdev, |
1322 | char *name) | 1322 | const struct video_device *vdev_template, |
1323 | const char *name) | ||
1323 | { | 1324 | { |
1324 | struct usb_device *usb_dev = usbvision->dev; | 1325 | struct usb_device *usb_dev = usbvision->dev; |
1325 | struct video_device *vdev; | ||
1326 | 1326 | ||
1327 | if (usb_dev == NULL) { | 1327 | if (usb_dev == NULL) { |
1328 | dev_err(&usbvision->dev->dev, | 1328 | dev_err(&usbvision->dev->dev, |
1329 | "%s: usbvision->dev is not set\n", __func__); | 1329 | "%s: usbvision->dev is not set\n", __func__); |
1330 | return NULL; | 1330 | return; |
1331 | } | 1331 | } |
1332 | 1332 | ||
1333 | vdev = video_device_alloc(); | ||
1334 | if (NULL == vdev) | ||
1335 | return NULL; | ||
1336 | *vdev = *vdev_template; | 1333 | *vdev = *vdev_template; |
1337 | vdev->lock = &usbvision->v4l2_lock; | 1334 | vdev->lock = &usbvision->v4l2_lock; |
1338 | vdev->v4l2_dev = &usbvision->v4l2_dev; | 1335 | vdev->v4l2_dev = &usbvision->v4l2_dev; |
1339 | snprintf(vdev->name, sizeof(vdev->name), "%s", name); | 1336 | snprintf(vdev->name, sizeof(vdev->name), "%s", name); |
1340 | video_set_drvdata(vdev, usbvision); | 1337 | video_set_drvdata(vdev, usbvision); |
1341 | return vdev; | ||
1342 | } | 1338 | } |
1343 | 1339 | ||
1344 | /* unregister video4linux devices */ | 1340 | /* unregister video4linux devices */ |
1345 | static void usbvision_unregister_video(struct usb_usbvision *usbvision) | 1341 | static void usbvision_unregister_video(struct usb_usbvision *usbvision) |
1346 | { | 1342 | { |
1347 | /* Radio Device: */ | 1343 | /* Radio Device: */ |
1348 | if (usbvision->rdev) { | 1344 | if (video_is_registered(&usbvision->rdev)) { |
1349 | PDEBUG(DBG_PROBE, "unregister %s [v4l2]", | 1345 | PDEBUG(DBG_PROBE, "unregister %s [v4l2]", |
1350 | video_device_node_name(usbvision->rdev)); | 1346 | video_device_node_name(&usbvision->rdev)); |
1351 | if (video_is_registered(usbvision->rdev)) | 1347 | video_unregister_device(&usbvision->rdev); |
1352 | video_unregister_device(usbvision->rdev); | ||
1353 | else | ||
1354 | video_device_release(usbvision->rdev); | ||
1355 | usbvision->rdev = NULL; | ||
1356 | } | 1348 | } |
1357 | 1349 | ||
1358 | /* Video Device: */ | 1350 | /* Video Device: */ |
1359 | if (usbvision->vdev) { | 1351 | if (video_is_registered(&usbvision->vdev)) { |
1360 | PDEBUG(DBG_PROBE, "unregister %s [v4l2]", | 1352 | PDEBUG(DBG_PROBE, "unregister %s [v4l2]", |
1361 | video_device_node_name(usbvision->vdev)); | 1353 | video_device_node_name(&usbvision->vdev)); |
1362 | if (video_is_registered(usbvision->vdev)) | 1354 | video_unregister_device(&usbvision->vdev); |
1363 | video_unregister_device(usbvision->vdev); | ||
1364 | else | ||
1365 | video_device_release(usbvision->vdev); | ||
1366 | usbvision->vdev = NULL; | ||
1367 | } | 1355 | } |
1368 | } | 1356 | } |
1369 | 1357 | ||
@@ -1371,28 +1359,22 @@ static void usbvision_unregister_video(struct usb_usbvision *usbvision) | |||
1371 | static int usbvision_register_video(struct usb_usbvision *usbvision) | 1359 | static int usbvision_register_video(struct usb_usbvision *usbvision) |
1372 | { | 1360 | { |
1373 | /* Video Device: */ | 1361 | /* Video Device: */ |
1374 | usbvision->vdev = usbvision_vdev_init(usbvision, | 1362 | usbvision_vdev_init(usbvision, &usbvision->vdev, |
1375 | &usbvision_video_template, | 1363 | &usbvision_video_template, "USBVision Video"); |
1376 | "USBVision Video"); | 1364 | if (video_register_device(&usbvision->vdev, VFL_TYPE_GRABBER, video_nr) < 0) |
1377 | if (usbvision->vdev == NULL) | ||
1378 | goto err_exit; | ||
1379 | if (video_register_device(usbvision->vdev, VFL_TYPE_GRABBER, video_nr) < 0) | ||
1380 | goto err_exit; | 1365 | goto err_exit; |
1381 | printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n", | 1366 | printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n", |
1382 | usbvision->nr, video_device_node_name(usbvision->vdev)); | 1367 | usbvision->nr, video_device_node_name(&usbvision->vdev)); |
1383 | 1368 | ||
1384 | /* Radio Device: */ | 1369 | /* Radio Device: */ |
1385 | if (usbvision_device_data[usbvision->dev_model].radio) { | 1370 | if (usbvision_device_data[usbvision->dev_model].radio) { |
1386 | /* usbvision has radio */ | 1371 | /* usbvision has radio */ |
1387 | usbvision->rdev = usbvision_vdev_init(usbvision, | 1372 | usbvision_vdev_init(usbvision, &usbvision->rdev, |
1388 | &usbvision_radio_template, | 1373 | &usbvision_radio_template, "USBVision Radio"); |
1389 | "USBVision Radio"); | 1374 | if (video_register_device(&usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0) |
1390 | if (usbvision->rdev == NULL) | ||
1391 | goto err_exit; | ||
1392 | if (video_register_device(usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0) | ||
1393 | goto err_exit; | 1375 | goto err_exit; |
1394 | printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n", | 1376 | printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n", |
1395 | usbvision->nr, video_device_node_name(usbvision->rdev)); | 1377 | usbvision->nr, video_device_node_name(&usbvision->rdev)); |
1396 | } | 1378 | } |
1397 | /* all done */ | 1379 | /* all done */ |
1398 | return 0; | 1380 | return 0; |
@@ -1461,7 +1443,7 @@ static void usbvision_release(struct usb_usbvision *usbvision) | |||
1461 | 1443 | ||
1462 | usbvision->initialized = 0; | 1444 | usbvision->initialized = 0; |
1463 | 1445 | ||
1464 | usbvision_remove_sysfs(usbvision->vdev); | 1446 | usbvision_remove_sysfs(&usbvision->vdev); |
1465 | usbvision_unregister_video(usbvision); | 1447 | usbvision_unregister_video(usbvision); |
1466 | kfree(usbvision->alt_max_pkt_size); | 1448 | kfree(usbvision->alt_max_pkt_size); |
1467 | 1449 | ||
@@ -1611,7 +1593,7 @@ static int usbvision_probe(struct usb_interface *intf, | |||
1611 | usbvision_configure_video(usbvision); | 1593 | usbvision_configure_video(usbvision); |
1612 | usbvision_register_video(usbvision); | 1594 | usbvision_register_video(usbvision); |
1613 | 1595 | ||
1614 | usbvision_create_sysfs(usbvision->vdev); | 1596 | usbvision_create_sysfs(&usbvision->vdev); |
1615 | 1597 | ||
1616 | PDEBUG(DBG_PROBE, "success"); | 1598 | PDEBUG(DBG_PROBE, "success"); |
1617 | return 0; | 1599 | return 0; |