diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2009-02-14 09:54:23 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-03-30 11:42:50 -0400 |
commit | 3a63e4492fbc7aa7f99d4368822da1382ec6fe03 (patch) | |
tree | d9d50f32757e7acde5f7ce3ecb22866b1cf51023 /drivers/media/video/v4l2-device.c | |
parent | 62cfdacc9431cad7f9093e91b17ea68d684188ae (diff) |
V4L/DVB (10643): v4l2-device: allow a NULL parent device when registering.
Some drivers (e.g. for ISA devices) have no parent device because there
is no associated bus driver. Allow the parent device to be NULL in
those cases when registering v4l2_device.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/v4l2-device.c')
-rw-r--r-- | drivers/media/video/v4l2-device.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c index 8a4b74f3129f..3330ffb7d010 100644 --- a/drivers/media/video/v4l2-device.c +++ b/drivers/media/video/v4l2-device.c | |||
@@ -26,15 +26,24 @@ | |||
26 | 26 | ||
27 | int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) | 27 | int 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 | } |
@@ -44,10 +53,11 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev) | |||
44 | { | 53 | { |
45 | struct v4l2_subdev *sd, *next; | 54 | struct v4l2_subdev *sd, *next; |
46 | 55 | ||
47 | if (v4l2_dev == NULL || v4l2_dev->dev == NULL) | 56 | if (v4l2_dev == NULL) |
48 | return; | 57 | return; |
49 | dev_set_drvdata(v4l2_dev->dev, NULL); | 58 | if (v4l2_dev->dev) |
50 | /* unregister subdevs */ | 59 | dev_set_drvdata(v4l2_dev->dev, NULL); |
60 | /* Unregister subdevs */ | ||
51 | list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) | 61 | list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) |
52 | v4l2_device_unregister_subdev(sd); | 62 | v4l2_device_unregister_subdev(sd); |
53 | 63 | ||
@@ -55,19 +65,20 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev) | |||
55 | } | 65 | } |
56 | EXPORT_SYMBOL_GPL(v4l2_device_unregister); | 66 | EXPORT_SYMBOL_GPL(v4l2_device_unregister); |
57 | 67 | ||
58 | int v4l2_device_register_subdev(struct v4l2_device *dev, struct v4l2_subdev *sd) | 68 | int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, |
69 | struct v4l2_subdev *sd) | ||
59 | { | 70 | { |
60 | /* Check for valid input */ | 71 | /* Check for valid input */ |
61 | if (dev == NULL || sd == NULL || !sd->name[0]) | 72 | if (v4l2_dev == NULL || sd == NULL || !sd->name[0]) |
62 | return -EINVAL; | 73 | return -EINVAL; |
63 | /* Warn if we apparently re-register a subdev */ | 74 | /* Warn if we apparently re-register a subdev */ |
64 | WARN_ON(sd->dev != NULL); | 75 | WARN_ON(sd->dev != NULL); |
65 | if (!try_module_get(sd->owner)) | 76 | if (!try_module_get(sd->owner)) |
66 | return -ENODEV; | 77 | return -ENODEV; |
67 | sd->dev = dev; | 78 | sd->dev = v4l2_dev; |
68 | spin_lock(&dev->lock); | 79 | spin_lock(&v4l2_dev->lock); |
69 | list_add_tail(&sd->list, &dev->subdevs); | 80 | list_add_tail(&sd->list, &v4l2_dev->subdevs); |
70 | spin_unlock(&dev->lock); | 81 | spin_unlock(&v4l2_dev->lock); |
71 | return 0; | 82 | return 0; |
72 | } | 83 | } |
73 | EXPORT_SYMBOL_GPL(v4l2_device_register_subdev); | 84 | EXPORT_SYMBOL_GPL(v4l2_device_register_subdev); |