diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2015-03-09 12:34:10 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2015-04-02 22:49:49 -0400 |
commit | 65b88c0be1f3fff0c652db19d5e13d8448764cf5 (patch) | |
tree | 360e2f0dc8ef9c7597c203bce478721e5db36cbf | |
parent | 4b30409b1b77975ed6197e3494662eedc7a1e26f (diff) |
[media] tm6000: 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>
-rw-r--r-- | drivers/media/usb/tm6000/tm6000-video.c | 59 | ||||
-rw-r--r-- | drivers/media/usb/tm6000/tm6000.h | 4 |
2 files changed, 17 insertions, 46 deletions
diff --git a/drivers/media/usb/tm6000/tm6000-video.c b/drivers/media/usb/tm6000/tm6000-video.c index 0f14d3ccc7b4..77ce9efe1f24 100644 --- a/drivers/media/usb/tm6000/tm6000-video.c +++ b/drivers/media/usb/tm6000/tm6000-video.c | |||
@@ -1576,7 +1576,7 @@ static struct video_device tm6000_template = { | |||
1576 | .name = "tm6000", | 1576 | .name = "tm6000", |
1577 | .fops = &tm6000_fops, | 1577 | .fops = &tm6000_fops, |
1578 | .ioctl_ops = &video_ioctl_ops, | 1578 | .ioctl_ops = &video_ioctl_ops, |
1579 | .release = video_device_release, | 1579 | .release = video_device_release_empty, |
1580 | .tvnorms = TM6000_STD, | 1580 | .tvnorms = TM6000_STD, |
1581 | }; | 1581 | }; |
1582 | 1582 | ||
@@ -1609,25 +1609,19 @@ static struct video_device tm6000_radio_template = { | |||
1609 | * ------------------------------------------------------------------ | 1609 | * ------------------------------------------------------------------ |
1610 | */ | 1610 | */ |
1611 | 1611 | ||
1612 | static struct video_device *vdev_init(struct tm6000_core *dev, | 1612 | static void vdev_init(struct tm6000_core *dev, |
1613 | struct video_device *vfd, | ||
1613 | const struct video_device | 1614 | const struct video_device |
1614 | *template, const char *type_name) | 1615 | *template, const char *type_name) |
1615 | { | 1616 | { |
1616 | struct video_device *vfd; | ||
1617 | |||
1618 | vfd = video_device_alloc(); | ||
1619 | if (NULL == vfd) | ||
1620 | return NULL; | ||
1621 | |||
1622 | *vfd = *template; | 1617 | *vfd = *template; |
1623 | vfd->v4l2_dev = &dev->v4l2_dev; | 1618 | vfd->v4l2_dev = &dev->v4l2_dev; |
1624 | vfd->release = video_device_release; | 1619 | vfd->release = video_device_release_empty; |
1625 | vfd->lock = &dev->lock; | 1620 | vfd->lock = &dev->lock; |
1626 | 1621 | ||
1627 | snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name); | 1622 | snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name); |
1628 | 1623 | ||
1629 | video_set_drvdata(vfd, dev); | 1624 | video_set_drvdata(vfd, dev); |
1630 | return vfd; | ||
1631 | } | 1625 | } |
1632 | 1626 | ||
1633 | int tm6000_v4l2_register(struct tm6000_core *dev) | 1627 | int tm6000_v4l2_register(struct tm6000_core *dev) |
@@ -1658,62 +1652,46 @@ int tm6000_v4l2_register(struct tm6000_core *dev) | |||
1658 | if (ret) | 1652 | if (ret) |
1659 | goto free_ctrl; | 1653 | goto free_ctrl; |
1660 | 1654 | ||
1661 | dev->vfd = vdev_init(dev, &tm6000_template, "video"); | 1655 | vdev_init(dev, &dev->vfd, &tm6000_template, "video"); |
1662 | 1656 | ||
1663 | if (!dev->vfd) { | 1657 | dev->vfd.ctrl_handler = &dev->ctrl_handler; |
1664 | printk(KERN_INFO "%s: can't register video device\n", | ||
1665 | dev->name); | ||
1666 | ret = -ENOMEM; | ||
1667 | goto free_ctrl; | ||
1668 | } | ||
1669 | dev->vfd->ctrl_handler = &dev->ctrl_handler; | ||
1670 | 1658 | ||
1671 | /* init video dma queues */ | 1659 | /* init video dma queues */ |
1672 | INIT_LIST_HEAD(&dev->vidq.active); | 1660 | INIT_LIST_HEAD(&dev->vidq.active); |
1673 | INIT_LIST_HEAD(&dev->vidq.queued); | 1661 | INIT_LIST_HEAD(&dev->vidq.queued); |
1674 | 1662 | ||
1675 | ret = video_register_device(dev->vfd, VFL_TYPE_GRABBER, video_nr); | 1663 | ret = video_register_device(&dev->vfd, VFL_TYPE_GRABBER, video_nr); |
1676 | 1664 | ||
1677 | if (ret < 0) { | 1665 | if (ret < 0) { |
1678 | printk(KERN_INFO "%s: can't register video device\n", | 1666 | printk(KERN_INFO "%s: can't register video device\n", |
1679 | dev->name); | 1667 | dev->name); |
1680 | video_device_release(dev->vfd); | ||
1681 | dev->vfd = NULL; | ||
1682 | goto free_ctrl; | 1668 | goto free_ctrl; |
1683 | } | 1669 | } |
1684 | 1670 | ||
1685 | printk(KERN_INFO "%s: registered device %s\n", | 1671 | printk(KERN_INFO "%s: registered device %s\n", |
1686 | dev->name, video_device_node_name(dev->vfd)); | 1672 | dev->name, video_device_node_name(&dev->vfd)); |
1687 | 1673 | ||
1688 | if (dev->caps.has_radio) { | 1674 | if (dev->caps.has_radio) { |
1689 | dev->radio_dev = vdev_init(dev, &tm6000_radio_template, | 1675 | vdev_init(dev, &dev->radio_dev, &tm6000_radio_template, |
1690 | "radio"); | 1676 | "radio"); |
1691 | if (!dev->radio_dev) { | 1677 | dev->radio_dev.ctrl_handler = &dev->radio_ctrl_handler; |
1692 | printk(KERN_INFO "%s: can't register radio device\n", | 1678 | ret = video_register_device(&dev->radio_dev, VFL_TYPE_RADIO, |
1693 | dev->name); | ||
1694 | ret = -ENXIO; | ||
1695 | goto unreg_video; | ||
1696 | } | ||
1697 | |||
1698 | dev->radio_dev->ctrl_handler = &dev->radio_ctrl_handler; | ||
1699 | ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO, | ||
1700 | radio_nr); | 1679 | radio_nr); |
1701 | if (ret < 0) { | 1680 | if (ret < 0) { |
1702 | printk(KERN_INFO "%s: can't register radio device\n", | 1681 | printk(KERN_INFO "%s: can't register radio device\n", |
1703 | dev->name); | 1682 | dev->name); |
1704 | video_device_release(dev->radio_dev); | ||
1705 | goto unreg_video; | 1683 | goto unreg_video; |
1706 | } | 1684 | } |
1707 | 1685 | ||
1708 | printk(KERN_INFO "%s: registered device %s\n", | 1686 | printk(KERN_INFO "%s: registered device %s\n", |
1709 | dev->name, video_device_node_name(dev->radio_dev)); | 1687 | dev->name, video_device_node_name(&dev->radio_dev)); |
1710 | } | 1688 | } |
1711 | 1689 | ||
1712 | printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret); | 1690 | printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret); |
1713 | return ret; | 1691 | return ret; |
1714 | 1692 | ||
1715 | unreg_video: | 1693 | unreg_video: |
1716 | video_unregister_device(dev->vfd); | 1694 | video_unregister_device(&dev->vfd); |
1717 | free_ctrl: | 1695 | free_ctrl: |
1718 | v4l2_ctrl_handler_free(&dev->ctrl_handler); | 1696 | v4l2_ctrl_handler_free(&dev->ctrl_handler); |
1719 | v4l2_ctrl_handler_free(&dev->radio_ctrl_handler); | 1697 | v4l2_ctrl_handler_free(&dev->radio_ctrl_handler); |
@@ -1722,19 +1700,12 @@ free_ctrl: | |||
1722 | 1700 | ||
1723 | int tm6000_v4l2_unregister(struct tm6000_core *dev) | 1701 | int tm6000_v4l2_unregister(struct tm6000_core *dev) |
1724 | { | 1702 | { |
1725 | video_unregister_device(dev->vfd); | 1703 | video_unregister_device(&dev->vfd); |
1726 | 1704 | ||
1727 | /* if URB buffers are still allocated free them now */ | 1705 | /* if URB buffers are still allocated free them now */ |
1728 | tm6000_free_urb_buffers(dev); | 1706 | tm6000_free_urb_buffers(dev); |
1729 | 1707 | ||
1730 | if (dev->radio_dev) { | 1708 | video_unregister_device(&dev->radio_dev); |
1731 | if (video_is_registered(dev->radio_dev)) | ||
1732 | video_unregister_device(dev->radio_dev); | ||
1733 | else | ||
1734 | video_device_release(dev->radio_dev); | ||
1735 | dev->radio_dev = NULL; | ||
1736 | } | ||
1737 | |||
1738 | return 0; | 1709 | return 0; |
1739 | } | 1710 | } |
1740 | 1711 | ||
diff --git a/drivers/media/usb/tm6000/tm6000.h b/drivers/media/usb/tm6000/tm6000.h index 08bd0740dd23..f2127944776f 100644 --- a/drivers/media/usb/tm6000/tm6000.h +++ b/drivers/media/usb/tm6000/tm6000.h | |||
@@ -220,8 +220,8 @@ struct tm6000_core { | |||
220 | struct tm6000_fh *resources; /* Points to fh that is streaming */ | 220 | struct tm6000_fh *resources; /* Points to fh that is streaming */ |
221 | bool is_res_read; | 221 | bool is_res_read; |
222 | 222 | ||
223 | struct video_device *vfd; | 223 | struct video_device vfd; |
224 | struct video_device *radio_dev; | 224 | struct video_device radio_dev; |
225 | struct tm6000_dmaqueue vidq; | 225 | struct tm6000_dmaqueue vidq; |
226 | struct v4l2_device v4l2_dev; | 226 | struct v4l2_device v4l2_dev; |
227 | struct v4l2_ctrl_handler ctrl_handler; | 227 | struct v4l2_ctrl_handler ctrl_handler; |