Skip to contentSkip to conversation

Annoying problem with minors and video_register_device()

DISCUSSION Andy Walls 1 participant 1 message Sep 22, 2008 Media (V4L/DVB)

lore
Share & tools
lore

Andy Walls

author
#0 lore raw

Description:

I have machine with a CX23416 (ivtv) and CX23418 (cx18) based card. The following commands yield the video device node names as I'd prefer to see them:

# modprobe cx18 cx18_first_minor=1
# modprobe ivtv ivtv_first_minor=0
# ls -al /dev/video*
lrwxrwxrwx  1 root root      6 2008-09-21 19:37 /dev/video -> video0
crw-rw----+ 1 root root 81,  0 2008-09-21 19:37 /dev/video0
crw-rw----+ 1 root root 81,  1 2008-09-21 19:37 /dev/video1
crw-rw----+ 1 root root 81, 24 2008-09-21 19:37 /dev/video24
crw-rw----+ 1 root root 81, 25 2008-09-21 19:37 /dev/video25
crw-rw----+ 1 root root 81, 32 2008-09-21 19:37 /dev/video32
crw-rw----+ 1 root root 81, 33 2008-09-21 19:37 /dev/video33

If I leave off the module options, I get this:

# modprobe cx18
# modprobe ivtv
# ls -al /dev/video*
lrwxrwxrwx  1 root root      6 2008-09-21 19:43 /dev/video -> video0
crw-rw----+ 1 root root 81,  0 2008-09-21 19:43 /dev/video0
crw-rw----+ 1 root root 81,  1 2008-09-21 19:44 /dev/video1
crw-rw----+ 1 root root 81,  2 2008-09-21 19:44 /dev/video2
crw-rw----+ 1 root root 81, 24 2008-09-21 19:43 /dev/video24
crw-rw----+ 1 root root 81,  3 2008-09-21 19:44 /dev/video3
crw-rw----+ 1 root root 81, 32 2008-09-21 19:43 /dev/video32

/dev/video2 and /dev/video3 aren't following the convention.

The problem is video_register_device() either gives you the minor for which the driver asked or it can auto assign the first available but only starting at an offset 0.

Perhaps video_register_device() could be modified so that the 3rd argument, nr, if less than 0, could be interpreted as -(offset+1). Offset would be the offset from the base at which auto assignment of a minor could start. The case of nr being passed in as -1 is then a backwards compatible case. In the case of nr greater than or equal to 0, nothing different would be done so things remain backward compatible.

So near the middle/bottom of video_register_device_index() one would have:

        if (nr >= 0 && nr < end-base) {
                /* use the one the driver asked for */
                i = base + nr;
                if (NULL != video_device[i]) {
                        mutex_unlock(&videodev_lock);
                        return -ENFILE;
                }
        } else {
-               /* use first free */
-               for (i = base; i < end; i++)
+               if (nr >= 0)
+                       nr = -1;
+               /* use first free from offset -nr - 1 */
+               for (i = base - nr - 1; i < end; i++)
                        if (NULL == video_device[i])
                                break;
-               if (i == end) {
+               if (i >= end) {
                        mutex_unlock(&videodev_lock);
                        return -ENFILE;
                }
        }

Of course the drivers (ivtv and cx18 in my case) would have to be modified to use this.

Any comments? Is it not worth solving such a rare case when a workaround with a module parameter exists?

Regards,
Andy

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list