aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/media/video/v4l2-dev.c13
-rw-r--r--include/media/v4l2-dev.h35
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
61struct video_device *video_device_alloc(void) 63struct 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}
68EXPORT_SYMBOL(video_device_alloc); 67EXPORT_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,
312fail_minor: 311fail_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}
319EXPORT_SYMBOL(video_register_device_index); 318EXPORT_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. */
78int __must_check video_register_device(struct video_device *vfd, int type, int nr); 79int __must_check video_register_device(struct video_device *vfd, int type, int nr);
79int __must_check video_register_device_index(struct video_device *vfd, int type, int nr, 80int __must_check video_register_device_index(struct video_device *vfd,
80 int index); 81 int type, int nr, int index);
81void video_unregister_device(struct video_device *); 82void 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(). */
85struct video_device * __must_check video_device_alloc(void); 86struct 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 */
87void video_device_release(struct video_device *vfd); 89void 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 */ 107struct video_device *video_devdata(struct file *file);
105/* Obsolete stuff - Still needed for radio devices and obsolete drivers */ 108
106extern struct video_device* video_devdata(struct file*); 109/* Combine video_get_drvdata and video_devdata as this is
107#endif 110 used very often. */
111static 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 */