diff options
author | Brandon Philips <brandon@ifup.org> | 2008-06-24 21:58:25 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-07-20 06:28:39 -0400 |
commit | 8373a3e512c8ea8e93981d42b0d1efb252be17fa (patch) | |
tree | bef7482f3f00d40b675072a33f5728e03e07aa42 /drivers/media/video/videodev.c | |
parent | 2bc93aa304f10bf94c377a487b09df75eaf88ab6 (diff) |
V4L/DVB (8389): videodev: simplify get_index()
Use Hans Verkuil's suggested method of implementing get_index which doesn't
depend on class_for_each_device and instead uses the video_device array. This
simplifies the code and reduces its memory footprint.
Signed-off-by: Brandon Philips <bphilips@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/videodev.c')
-rw-r--r-- | drivers/media/video/videodev.c | 65 |
1 files changed, 17 insertions, 48 deletions
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c index c24d91897099..bf12b5f850e2 100644 --- a/drivers/media/video/videodev.c +++ b/drivers/media/video/videodev.c | |||
@@ -2011,25 +2011,8 @@ out: | |||
2011 | } | 2011 | } |
2012 | EXPORT_SYMBOL(video_ioctl2); | 2012 | EXPORT_SYMBOL(video_ioctl2); |
2013 | 2013 | ||
2014 | struct index_info { | ||
2015 | struct device *dev; | ||
2016 | unsigned int used[VIDEO_NUM_DEVICES]; | ||
2017 | }; | ||
2018 | |||
2019 | static int __fill_index_info(struct device *cd, void *data) | ||
2020 | { | ||
2021 | struct index_info *info = data; | ||
2022 | struct video_device *vfd = container_of(cd, struct video_device, | ||
2023 | class_dev); | ||
2024 | |||
2025 | if (info->dev == vfd->dev) | ||
2026 | info->used[vfd->index] = 1; | ||
2027 | |||
2028 | return 0; | ||
2029 | } | ||
2030 | |||
2031 | /** | 2014 | /** |
2032 | * assign_index - assign stream number based on parent device | 2015 | * get_index - assign stream number based on parent device |
2033 | * @vdev: video_device to assign index number to, vdev->dev should be assigned | 2016 | * @vdev: video_device to assign index number to, vdev->dev should be assigned |
2034 | * @num: -1 if auto assign, requested number otherwise | 2017 | * @num: -1 if auto assign, requested number otherwise |
2035 | * | 2018 | * |
@@ -2039,44 +2022,30 @@ static int __fill_index_info(struct device *cd, void *data) | |||
2039 | */ | 2022 | */ |
2040 | static int get_index(struct video_device *vdev, int num) | 2023 | static int get_index(struct video_device *vdev, int num) |
2041 | { | 2024 | { |
2042 | struct index_info *info; | 2025 | u32 used = 0; |
2043 | int i; | 2026 | int i; |
2044 | int ret = 0; | ||
2045 | 2027 | ||
2046 | if (num >= VIDEO_NUM_DEVICES) | 2028 | if (num >= 32) { |
2029 | printk(KERN_ERR "videodev: %s num is too large\n", __func__); | ||
2047 | return -EINVAL; | 2030 | return -EINVAL; |
2048 | |||
2049 | info = kzalloc(sizeof(*info), GFP_KERNEL); | ||
2050 | if (!info) | ||
2051 | return -ENOMEM; | ||
2052 | |||
2053 | info->dev = vdev->dev; | ||
2054 | |||
2055 | ret = class_for_each_device(&video_class, info, | ||
2056 | __fill_index_info); | ||
2057 | |||
2058 | if (ret < 0) | ||
2059 | goto out; | ||
2060 | |||
2061 | if (num >= 0) { | ||
2062 | if (!info->used[num]) | ||
2063 | ret = num; | ||
2064 | else | ||
2065 | ret = -ENFILE; | ||
2066 | |||
2067 | goto out; | ||
2068 | } | 2031 | } |
2069 | 2032 | ||
2070 | for (i = 0; i < VIDEO_NUM_DEVICES; i++) { | 2033 | for (i = 0; i < VIDEO_NUM_DEVICES; i++) { |
2071 | if (info->used[i]) | 2034 | if (video_device[i] != NULL && |
2072 | continue; | 2035 | video_device[i] != vdev && |
2073 | ret = i; | 2036 | video_device[i]->dev == vdev->dev) { |
2074 | goto out; | 2037 | used |= 1 << video_device[i]->index; |
2038 | } | ||
2075 | } | 2039 | } |
2076 | 2040 | ||
2077 | out: | 2041 | if (num >= 0) { |
2078 | kfree(info); | 2042 | if (used & (1 << num)) |
2079 | return ret; | 2043 | return -ENFILE; |
2044 | return num; | ||
2045 | } | ||
2046 | |||
2047 | i = ffz(used); | ||
2048 | return i >= 32 ? -ENFILE : i; | ||
2080 | } | 2049 | } |
2081 | 2050 | ||
2082 | static const struct file_operations video_fops; | 2051 | static const struct file_operations video_fops; |