diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2009-02-14 15:31:01 +0100 |
---|---|---|
committer | Hans Verkuil <hverkuil@xs4all.nl> | 2009-02-14 15:31:01 +0100 |
commit | add4cca4f1bb659d08d75b45f57b226325a34a6b (patch) | |
tree | f3713fe6b7cc6da53ad98543b6b54b73a5f9fd70 /linux/drivers | |
parent | c02991ae9384f6940ac34f853f5191b7bcf1f453 (diff) | |
download | mediapointer-dvb-s2-add4cca4f1bb659d08d75b45f57b226325a34a6b.tar.gz mediapointer-dvb-s2-add4cca4f1bb659d08d75b45f57b226325a34a6b.tar.bz2 |
v4l2-dev: remove limit of 32 devices per driver in get_index()
From: Hans Verkuil <hverkuil@xs4all.nl>
get_index() had a limitation of 32 devices per driver. This was
unnecessarily strict and has been replaced with the maximum number
of devices. That should really satisfy anyone!
Priority: normal
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Diffstat (limited to 'linux/drivers')
-rw-r--r-- | linux/drivers/media/video/v4l2-dev.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/linux/drivers/media/video/v4l2-dev.c b/linux/drivers/media/video/v4l2-dev.c index 9e34e9ec2..e6dc1279a 100644 --- a/linux/drivers/media/video/v4l2-dev.c +++ b/linux/drivers/media/video/v4l2-dev.c @@ -326,37 +326,38 @@ static const struct file_operations v4l2_fops = { */ static int get_index(struct video_device *vdev, int num) { - u32 used = 0; - const int max_index = sizeof(used) * 8 - 1; + /* This can be static since this function is called with the global + videodev_lock held. */ + static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES); int i; - /* Currently a single v4l driver instance cannot create more than - 32 devices. - Increase to u64 or an array of u32 if more are needed. */ - if (num > max_index) { + if (num >= VIDEO_NUM_DEVICES) { printk(KERN_ERR "videodev: %s num is too large\n", __func__); return -EINVAL; } - /* Some drivers do not set the parent. In that case always return 0. */ + /* Some drivers do not set the parent. In that case always return + num or 0. */ if (vdev->parent == NULL) - return 0; + return num >= 0 ? num : 0; + + bitmap_zero(used, VIDEO_NUM_DEVICES); for (i = 0; i < VIDEO_NUM_DEVICES; i++) { if (video_device[i] != NULL && video_device[i]->parent == vdev->parent) { - used |= 1 << video_device[i]->index; + set_bit(video_device[i]->index, used); } } if (num >= 0) { - if (used & (1 << num)) + if (test_bit(num, used)) return -ENFILE; return num; } - i = ffz(used); - return i > max_index ? -ENFILE : i; + i = find_first_zero_bit(used, VIDEO_NUM_DEVICES); + return i == VIDEO_NUM_DEVICES ? -ENFILE : i; } int video_register_device(struct video_device *vdev, int type, int nr) |