aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/v4l2-device.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/v4l2-device.c')
-rw-r--r--drivers/media/video/v4l2-device.c58
1 files changed, 38 insertions, 20 deletions
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index 8a4b74f3129f..94aa485ade52 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -26,48 +26,66 @@
26 26
27int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) 27int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
28{ 28{
29 if (dev == NULL || v4l2_dev == NULL) 29 if (v4l2_dev == NULL)
30 return -EINVAL; 30 return -EINVAL;
31 /* Warn if we apparently re-register a device */ 31
32 WARN_ON(dev_get_drvdata(dev) != NULL);
33 INIT_LIST_HEAD(&v4l2_dev->subdevs); 32 INIT_LIST_HEAD(&v4l2_dev->subdevs);
34 spin_lock_init(&v4l2_dev->lock); 33 spin_lock_init(&v4l2_dev->lock);
35 v4l2_dev->dev = dev; 34 v4l2_dev->dev = dev;
36 snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s", 35 if (dev == NULL) {
36 /* If dev == NULL, then name must be filled in by the caller */
37 WARN_ON(!v4l2_dev->name[0]);
38 return 0;
39 }
40
41 /* Set name to driver name + device name if it is empty. */
42 if (!v4l2_dev->name[0])
43 snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s",
37 dev->driver->name, dev_name(dev)); 44 dev->driver->name, dev_name(dev));
45 if (dev_get_drvdata(dev))
46 v4l2_warn(v4l2_dev, "Non-NULL drvdata on register\n");
38 dev_set_drvdata(dev, v4l2_dev); 47 dev_set_drvdata(dev, v4l2_dev);
39 return 0; 48 return 0;
40} 49}
41EXPORT_SYMBOL_GPL(v4l2_device_register); 50EXPORT_SYMBOL_GPL(v4l2_device_register);
42 51
52void v4l2_device_disconnect(struct v4l2_device *v4l2_dev)
53{
54 if (v4l2_dev->dev) {
55 dev_set_drvdata(v4l2_dev->dev, NULL);
56 v4l2_dev->dev = NULL;
57 }
58}
59EXPORT_SYMBOL_GPL(v4l2_device_disconnect);
60
43void v4l2_device_unregister(struct v4l2_device *v4l2_dev) 61void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
44{ 62{
45 struct v4l2_subdev *sd, *next; 63 struct v4l2_subdev *sd, *next;
46 64
47 if (v4l2_dev == NULL || v4l2_dev->dev == NULL) 65 if (v4l2_dev == NULL)
48 return; 66 return;
49 dev_set_drvdata(v4l2_dev->dev, NULL); 67 v4l2_device_disconnect(v4l2_dev);
50 /* unregister subdevs */ 68
69 /* Unregister subdevs */
51 list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) 70 list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list)
52 v4l2_device_unregister_subdev(sd); 71 v4l2_device_unregister_subdev(sd);
53
54 v4l2_dev->dev = NULL;
55} 72}
56EXPORT_SYMBOL_GPL(v4l2_device_unregister); 73EXPORT_SYMBOL_GPL(v4l2_device_unregister);
57 74
58int v4l2_device_register_subdev(struct v4l2_device *dev, struct v4l2_subdev *sd) 75int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
76 struct v4l2_subdev *sd)
59{ 77{
60 /* Check for valid input */ 78 /* Check for valid input */
61 if (dev == NULL || sd == NULL || !sd->name[0]) 79 if (v4l2_dev == NULL || sd == NULL || !sd->name[0])
62 return -EINVAL; 80 return -EINVAL;
63 /* Warn if we apparently re-register a subdev */ 81 /* Warn if we apparently re-register a subdev */
64 WARN_ON(sd->dev != NULL); 82 WARN_ON(sd->v4l2_dev != NULL);
65 if (!try_module_get(sd->owner)) 83 if (!try_module_get(sd->owner))
66 return -ENODEV; 84 return -ENODEV;
67 sd->dev = dev; 85 sd->v4l2_dev = v4l2_dev;
68 spin_lock(&dev->lock); 86 spin_lock(&v4l2_dev->lock);
69 list_add_tail(&sd->list, &dev->subdevs); 87 list_add_tail(&sd->list, &v4l2_dev->subdevs);
70 spin_unlock(&dev->lock); 88 spin_unlock(&v4l2_dev->lock);
71 return 0; 89 return 0;
72} 90}
73EXPORT_SYMBOL_GPL(v4l2_device_register_subdev); 91EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
@@ -75,12 +93,12 @@ EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
75void v4l2_device_unregister_subdev(struct v4l2_subdev *sd) 93void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
76{ 94{
77 /* return if it isn't registered */ 95 /* return if it isn't registered */
78 if (sd == NULL || sd->dev == NULL) 96 if (sd == NULL || sd->v4l2_dev == NULL)
79 return; 97 return;
80 spin_lock(&sd->dev->lock); 98 spin_lock(&sd->v4l2_dev->lock);
81 list_del(&sd->list); 99 list_del(&sd->list);
82 spin_unlock(&sd->dev->lock); 100 spin_unlock(&sd->v4l2_dev->lock);
83 sd->dev = NULL; 101 sd->v4l2_dev = NULL;
84 module_put(sd->owner); 102 module_put(sd->owner);
85} 103}
86EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev); 104EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);