V4L/DVB (12722): v4l2-dev: replace 'kernel number' by 'device node number'.

The term 'kernel number' is very vague, so replace it with the somewhat more
descriptive term 'device node number'.

In one place the local variable 'nr' was used to create the device node number
of the new device name. This has been replaced with the vdev->num field to
more clearly mark this as being the device node number and not the minor
number.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Hans Verkuil 2009-09-06 07:13:14 -03:00 committed by Mauro Carvalho Chehab
parent 7ae0cd9bc7
commit 22e221258b
2 changed files with 24 additions and 22 deletions

View File

@ -486,14 +486,14 @@ VFL_TYPE_RADIO: radioX for radio tuners
VFL_TYPE_VTX: vtxX for teletext devices (deprecated, don't use)
The last argument gives you a certain amount of control over the device
kernel number used (i.e. the X in videoX). Normally you will pass -1 to
device node number used (i.e. the X in videoX). Normally you will pass -1 to
let the v4l2 framework pick the first free number. But if a driver creates
many devices, then it can be useful to have different video devices in
separate ranges. For example, video capture devices start at 0, video
output devices start at 16.
So you can use the last argument to specify a minimum kernel number and
the v4l2 framework will try to pick the first free number that is equal
So you can use the last argument to specify a minimum device node number
and the v4l2 framework will try to pick the first free number that is equal
or higher to what you passed. If that fails, then it will just pick the
first free number.
@ -513,7 +513,7 @@ After the device was successfully registered, then you can use these fields:
- vfl_type: the device type passed to video_register_device.
- minor: the assigned device minor number.
- num: the device kernel number (i.e. the X in videoX).
- num: the device node number (i.e. the X in videoX).
- index: the device index number.
If the registration failed, then you need to call video_device_release()

View File

@ -66,7 +66,7 @@ static struct device_attribute video_device_attrs[] = {
*/
static struct video_device *video_device[VIDEO_NUM_DEVICES];
static DEFINE_MUTEX(videodev_lock);
static DECLARE_BITMAP(video_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES);
static DECLARE_BITMAP(devnode_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES);
struct video_device *video_device_alloc(void)
{
@ -119,8 +119,8 @@ static void v4l2_device_release(struct device *cd)
the release() callback. */
vdev->cdev = NULL;
/* Mark minor as free */
clear_bit(vdev->num, video_nums[vdev->vfl_type]);
/* Mark device node number as free */
clear_bit(vdev->num, devnode_nums[vdev->vfl_type]);
mutex_unlock(&videodev_lock);
@ -338,13 +338,14 @@ static int get_index(struct video_device *vdev)
* video_register_device - register video4linux devices
* @vdev: video device structure we want to register
* @type: type of device to register
* @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
* @nr: which device node number (0 == /dev/video0, 1 == /dev/video1, ...
* -1 == first free)
*
* The registration code assigns minor numbers based on the type
* requested. -ENFILE is returned in all the device slots for this
* category are full. If not then the minor field is set and the
* driver initialize function is called (if non %NULL).
* The registration code assigns minor numbers and device node numbers
* based on the requested type and registers the new device node with
* the kernel.
* An error is returned if no free minor or device node number could be
* found, or if the registration of the device node failed.
*
* Zero is returned on success.
*
@ -401,7 +402,7 @@ int video_register_device(struct video_device *vdev, int type, int nr)
if (vdev->v4l2_dev && vdev->v4l2_dev->dev)
vdev->parent = vdev->v4l2_dev->dev;
/* Part 2: find a free minor, kernel number and device index. */
/* Part 2: find a free minor, device node number and device index. */
#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
/* Keep the ranges for the first four types for historical
* reasons.
@ -432,21 +433,22 @@ int video_register_device(struct video_device *vdev, int type, int nr)
}
#endif
/* Pick a minor number */
/* Pick a device node number */
mutex_lock(&videodev_lock);
nr = find_next_zero_bit(video_nums[type], minor_cnt, nr == -1 ? 0 : nr);
nr = find_next_zero_bit(devnode_nums[type], minor_cnt, nr == -1 ? 0 : nr);
if (nr == minor_cnt)
nr = find_first_zero_bit(video_nums[type], minor_cnt);
nr = find_first_zero_bit(devnode_nums[type], minor_cnt);
if (nr == minor_cnt) {
printk(KERN_ERR "could not get a free kernel number\n");
printk(KERN_ERR "could not get a free device node number\n");
mutex_unlock(&videodev_lock);
return -ENFILE;
}
#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
/* 1-on-1 mapping of kernel number to minor number */
/* 1-on-1 mapping of device node number to minor number */
i = nr;
#else
/* The kernel number and minor numbers are independent */
/* The device node number and minor numbers are independent, so
we just find the first free minor number. */
for (i = 0; i < VIDEO_NUM_DEVICES; i++)
if (video_device[i] == NULL)
break;
@ -458,7 +460,7 @@ int video_register_device(struct video_device *vdev, int type, int nr)
#endif
vdev->minor = i + minor_offset;
vdev->num = nr;
set_bit(nr, video_nums[type]);
set_bit(nr, devnode_nums[type]);
/* Should not happen since we thought this minor was free */
WARN_ON(video_device[vdev->minor] != NULL);
vdev->index = get_index(vdev);
@ -492,7 +494,7 @@ int video_register_device(struct video_device *vdev, int type, int nr)
vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
if (vdev->parent)
vdev->dev.parent = vdev->parent;
dev_set_name(&vdev->dev, "%s%d", name_base, nr);
dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num);
ret = device_register(&vdev->dev);
if (ret < 0) {
printk(KERN_ERR "%s: device_register failed\n", __func__);
@ -512,7 +514,7 @@ int video_register_device(struct video_device *vdev, int type, int nr)
mutex_lock(&videodev_lock);
if (vdev->cdev)
cdev_del(vdev->cdev);
clear_bit(vdev->num, video_nums[type]);
clear_bit(vdev->num, devnode_nums[type]);
mutex_unlock(&videodev_lock);
/* Mark this video device as never having been registered. */
vdev->minor = -1;