aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/v4l2-dev.c
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2009-09-07 02:40:24 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-09-18 23:19:31 -0400
commit5062cb70c828bd7b2a8223390ae836c5baa250b9 (patch)
tree1a02e1f2b6d35c0a879403be85666b58699329aa /drivers/media/video/v4l2-dev.c
parent581644d9c95dd04aa46267aa0b6b5619d02b02ea (diff)
V4L/DVB (12724): v4l2-dev: add simple wrapper functions around the devnode numbers
There are some subtle differences in the way the devnode numbers are handled depending on whether the FIXED_MINOR_RANGES config option is set. Add some simple wrapper functions to handle that correctly. Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/v4l2-dev.c')
-rw-r--r--drivers/media/video/v4l2-dev.c53
1 files changed, 48 insertions, 5 deletions
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 4e61c77b7634..4715f08157bc 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -68,6 +68,48 @@ static struct video_device *video_device[VIDEO_NUM_DEVICES];
68static DEFINE_MUTEX(videodev_lock); 68static DEFINE_MUTEX(videodev_lock);
69static DECLARE_BITMAP(devnode_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES); 69static DECLARE_BITMAP(devnode_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES);
70 70
71/* Device node utility functions */
72
73/* Note: these utility functions all assume that vfl_type is in the range
74 [0, VFL_TYPE_MAX-1]. */
75
76#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
77/* Return the bitmap corresponding to vfl_type. */
78static inline unsigned long *devnode_bits(int vfl_type)
79{
80 /* Any types not assigned to fixed minor ranges must be mapped to
81 one single bitmap for the purposes of finding a free node number
82 since all those unassigned types use the same minor range. */
83 int idx = (vfl_type > VFL_TYPE_VTX) ? VFL_TYPE_MAX - 1 : vfl_type;
84
85 return devnode_nums[idx];
86}
87#else
88/* Return the bitmap corresponding to vfl_type. */
89static inline unsigned long *devnode_bits(int vfl_type)
90{
91 return devnode_nums[vfl_type];
92}
93#endif
94
95/* Mark device node number vdev->num as used */
96static inline void devnode_set(struct video_device *vdev)
97{
98 set_bit(vdev->num, devnode_bits(vdev->vfl_type));
99}
100
101/* Mark device node number vdev->num as unused */
102static inline void devnode_clear(struct video_device *vdev)
103{
104 clear_bit(vdev->num, devnode_bits(vdev->vfl_type));
105}
106
107/* Try to find a free device node number in the range [from, to> */
108static inline int devnode_find(struct video_device *vdev, int from, int to)
109{
110 return find_next_zero_bit(devnode_bits(vdev->vfl_type), to, from);
111}
112
71struct video_device *video_device_alloc(void) 113struct video_device *video_device_alloc(void)
72{ 114{
73 return kzalloc(sizeof(struct video_device), GFP_KERNEL); 115 return kzalloc(sizeof(struct video_device), GFP_KERNEL);
@@ -120,7 +162,7 @@ static void v4l2_device_release(struct device *cd)
120 vdev->cdev = NULL; 162 vdev->cdev = NULL;
121 163
122 /* Mark device node number as free */ 164 /* Mark device node number as free */
123 clear_bit(vdev->num, devnode_nums[vdev->vfl_type]); 165 devnode_clear(vdev);
124 166
125 mutex_unlock(&videodev_lock); 167 mutex_unlock(&videodev_lock);
126 168
@@ -435,9 +477,9 @@ int video_register_device(struct video_device *vdev, int type, int nr)
435 477
436 /* Pick a device node number */ 478 /* Pick a device node number */
437 mutex_lock(&videodev_lock); 479 mutex_lock(&videodev_lock);
438 nr = find_next_zero_bit(devnode_nums[type], minor_cnt, nr == -1 ? 0 : nr); 480 nr = devnode_find(vdev, nr == -1 ? 0 : nr, minor_cnt);
439 if (nr == minor_cnt) 481 if (nr == minor_cnt)
440 nr = find_first_zero_bit(devnode_nums[type], minor_cnt); 482 nr = devnode_find(vdev, 0, minor_cnt);
441 if (nr == minor_cnt) { 483 if (nr == minor_cnt) {
442 printk(KERN_ERR "could not get a free device node number\n"); 484 printk(KERN_ERR "could not get a free device node number\n");
443 mutex_unlock(&videodev_lock); 485 mutex_unlock(&videodev_lock);
@@ -460,7 +502,8 @@ int video_register_device(struct video_device *vdev, int type, int nr)
460#endif 502#endif
461 vdev->minor = i + minor_offset; 503 vdev->minor = i + minor_offset;
462 vdev->num = nr; 504 vdev->num = nr;
463 set_bit(nr, devnode_nums[type]); 505 devnode_set(vdev);
506
464 /* Should not happen since we thought this minor was free */ 507 /* Should not happen since we thought this minor was free */
465 WARN_ON(video_device[vdev->minor] != NULL); 508 WARN_ON(video_device[vdev->minor] != NULL);
466 vdev->index = get_index(vdev); 509 vdev->index = get_index(vdev);
@@ -514,7 +557,7 @@ cleanup:
514 mutex_lock(&videodev_lock); 557 mutex_lock(&videodev_lock);
515 if (vdev->cdev) 558 if (vdev->cdev)
516 cdev_del(vdev->cdev); 559 cdev_del(vdev->cdev);
517 clear_bit(vdev->num, devnode_nums[type]); 560 devnode_clear(vdev);
518 mutex_unlock(&videodev_lock); 561 mutex_unlock(&videodev_lock);
519 /* Mark this video device as never having been registered. */ 562 /* Mark this video device as never having been registered. */
520 vdev->minor = -1; 563 vdev->minor = -1;