diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2008-08-23 06:48:38 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-10-12 07:36:54 -0400 |
commit | bfa8a273bb91078ea193ab94c717889928f3b925 (patch) | |
tree | 3be9718a35023adec6e87343dc1efce3e60778a8 | |
parent | 601e9444f249d219009ec05674268d90f6f1cdcb (diff) |
V4L/DVB (8787): v4l2-dev: cleanups and add video_drvdata helper function
Cleanup v4l2-dev.[ch], add/improve comments and add a new helper
function: video_drvdata() that can get the private driver data from
a file struct.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/v4l2-dev.c | 13 | ||||
-rw-r--r-- | include/media/v4l2-dev.h | 35 |
2 files changed, 27 insertions, 21 deletions
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c index ff219df4b725..1ec0a1a8fb73 100644 --- a/drivers/media/video/v4l2-dev.c +++ b/drivers/media/video/v4l2-dev.c | |||
@@ -42,6 +42,7 @@ static ssize_t show_index(struct device *cd, | |||
42 | struct device_attribute *attr, char *buf) | 42 | struct device_attribute *attr, char *buf) |
43 | { | 43 | { |
44 | struct video_device *vfd = container_of(cd, struct video_device, dev); | 44 | struct video_device *vfd = container_of(cd, struct video_device, dev); |
45 | |||
45 | return sprintf(buf, "%i\n", vfd->index); | 46 | return sprintf(buf, "%i\n", vfd->index); |
46 | } | 47 | } |
47 | 48 | ||
@@ -49,6 +50,7 @@ static ssize_t show_name(struct device *cd, | |||
49 | struct device_attribute *attr, char *buf) | 50 | struct device_attribute *attr, char *buf) |
50 | { | 51 | { |
51 | struct video_device *vfd = container_of(cd, struct video_device, dev); | 52 | struct video_device *vfd = container_of(cd, struct video_device, dev); |
53 | |||
52 | return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name); | 54 | return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name); |
53 | } | 55 | } |
54 | 56 | ||
@@ -60,10 +62,7 @@ static struct device_attribute video_device_attrs[] = { | |||
60 | 62 | ||
61 | struct video_device *video_device_alloc(void) | 63 | struct video_device *video_device_alloc(void) |
62 | { | 64 | { |
63 | struct video_device *vfd; | 65 | return kzalloc(sizeof(struct video_device), GFP_KERNEL); |
64 | |||
65 | vfd = kzalloc(sizeof(*vfd), GFP_KERNEL); | ||
66 | return vfd; | ||
67 | } | 66 | } |
68 | EXPORT_SYMBOL(video_device_alloc); | 67 | EXPORT_SYMBOL(video_device_alloc); |
69 | 68 | ||
@@ -263,7 +262,7 @@ int video_register_device_index(struct video_device *vfd, int type, int nr, | |||
263 | 262 | ||
264 | /* pick a minor number */ | 263 | /* pick a minor number */ |
265 | mutex_lock(&videodev_lock); | 264 | mutex_lock(&videodev_lock); |
266 | if (nr >= 0 && nr < end-base) { | 265 | if (nr >= 0 && nr < end-base) { |
267 | /* use the one the driver asked for */ | 266 | /* use the one the driver asked for */ |
268 | i = base + nr; | 267 | i = base + nr; |
269 | if (NULL != video_device[i]) { | 268 | if (NULL != video_device[i]) { |
@@ -295,7 +294,7 @@ int video_register_device_index(struct video_device *vfd, int type, int nr, | |||
295 | } | 294 | } |
296 | 295 | ||
297 | /* sysfs class */ | 296 | /* sysfs class */ |
298 | memset(&vfd->dev, 0x00, sizeof(vfd->dev)); | 297 | memset(&vfd->dev, 0, sizeof(vfd->dev)); |
299 | vfd->dev.class = &video_class; | 298 | vfd->dev.class = &video_class; |
300 | vfd->dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor); | 299 | vfd->dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor); |
301 | if (vfd->parent) | 300 | if (vfd->parent) |
@@ -312,8 +311,8 @@ int video_register_device_index(struct video_device *vfd, int type, int nr, | |||
312 | fail_minor: | 311 | fail_minor: |
313 | mutex_lock(&videodev_lock); | 312 | mutex_lock(&videodev_lock); |
314 | video_device[vfd->minor] = NULL; | 313 | video_device[vfd->minor] = NULL; |
315 | vfd->minor = -1; | ||
316 | mutex_unlock(&videodev_lock); | 314 | mutex_unlock(&videodev_lock); |
315 | vfd->minor = -1; | ||
317 | return ret; | 316 | return ret; |
318 | } | 317 | } |
319 | EXPORT_SYMBOL(video_register_device_index); | 318 | EXPORT_SYMBOL(video_register_device_index); |
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index 1d4df571060b..fb92e3d22d7e 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h | |||
@@ -9,16 +9,14 @@ | |||
9 | #ifndef _V4L2_DEV_H | 9 | #ifndef _V4L2_DEV_H |
10 | #define _V4L2_DEV_H | 10 | #define _V4L2_DEV_H |
11 | 11 | ||
12 | #define OBSOLETE_DEVDATA 1 /* to be removed soon */ | ||
13 | |||
14 | #include <linux/poll.h> | 12 | #include <linux/poll.h> |
15 | #include <linux/fs.h> | 13 | #include <linux/fs.h> |
16 | #include <linux/device.h> | 14 | #include <linux/device.h> |
17 | #include <linux/mutex.h> | 15 | #include <linux/mutex.h> |
18 | #include <linux/compiler.h> /* need __user */ | ||
19 | #include <linux/videodev2.h> | 16 | #include <linux/videodev2.h> |
20 | 17 | ||
21 | #define VIDEO_MAJOR 81 | 18 | #define VIDEO_MAJOR 81 |
19 | |||
22 | /* Minor device allocation */ | 20 | /* Minor device allocation */ |
23 | #define MINOR_VFL_TYPE_GRABBER_MIN 0 | 21 | #define MINOR_VFL_TYPE_GRABBER_MIN 0 |
24 | #define MINOR_VFL_TYPE_GRABBER_MAX 63 | 22 | #define MINOR_VFL_TYPE_GRABBER_MAX 63 |
@@ -71,20 +69,25 @@ struct video_device | |||
71 | const struct v4l2_ioctl_ops *ioctl_ops; | 69 | const struct v4l2_ioctl_ops *ioctl_ops; |
72 | }; | 70 | }; |
73 | 71 | ||
74 | /* Class-dev to video-device */ | 72 | /* dev to video-device */ |
75 | #define to_video_device(cd) container_of(cd, struct video_device, dev) | 73 | #define to_video_device(cd) container_of(cd, struct video_device, dev) |
76 | 74 | ||
77 | /* Version 2 functions */ | 75 | /* Register and unregister devices. Note that if video_register_device fails, |
76 | the release() callback of the video_device structure is *not* called, so | ||
77 | the caller is responsible for freeing any data. Usually that means that | ||
78 | you call video_device_release() on failure. */ | ||
78 | int __must_check video_register_device(struct video_device *vfd, int type, int nr); | 79 | int __must_check video_register_device(struct video_device *vfd, int type, int nr); |
79 | int __must_check video_register_device_index(struct video_device *vfd, int type, int nr, | 80 | int __must_check video_register_device_index(struct video_device *vfd, |
80 | int index); | 81 | int type, int nr, int index); |
81 | void video_unregister_device(struct video_device *); | 82 | void video_unregister_device(struct video_device *vfd); |
82 | 83 | ||
83 | /* helper functions to alloc / release struct video_device, the | 84 | /* helper functions to alloc/release struct video_device, the |
84 | later can be used for video_device->release() */ | 85 | latter can also be used for video_device->release(). */ |
85 | struct video_device * __must_check video_device_alloc(void); | 86 | struct video_device * __must_check video_device_alloc(void); |
87 | |||
86 | /* this release function frees the vfd pointer */ | 88 | /* this release function frees the vfd pointer */ |
87 | void video_device_release(struct video_device *vfd); | 89 | void video_device_release(struct video_device *vfd); |
90 | |||
88 | /* this release function does nothing, use when the video_device is a | 91 | /* this release function does nothing, use when the video_device is a |
89 | static global struct. Note that having a static video_device is | 92 | static global struct. Note that having a static video_device is |
90 | a dubious construction at best. */ | 93 | a dubious construction at best. */ |
@@ -101,9 +104,13 @@ static inline void video_set_drvdata(struct video_device *dev, void *data) | |||
101 | dev_set_drvdata(&dev->dev, data); | 104 | dev_set_drvdata(&dev->dev, data); |
102 | } | 105 | } |
103 | 106 | ||
104 | #ifdef OBSOLETE_DEVDATA /* to be removed soon */ | 107 | struct video_device *video_devdata(struct file *file); |
105 | /* Obsolete stuff - Still needed for radio devices and obsolete drivers */ | 108 | |
106 | extern struct video_device* video_devdata(struct file*); | 109 | /* Combine video_get_drvdata and video_devdata as this is |
107 | #endif | 110 | used very often. */ |
111 | static inline void *video_drvdata(struct file *file) | ||
112 | { | ||
113 | return video_get_drvdata(video_devdata(file)); | ||
114 | } | ||
108 | 115 | ||
109 | #endif /* _V4L2_DEV_H */ | 116 | #endif /* _V4L2_DEV_H */ |