[V4L] races in v4l read + write in 2.4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hi,

would anybody object to me adding a semaphore to the video_device structure ?
It would be taken by read & write in the v4l layer. This would cure races in 
the usb v4l devices.

The problem is, that, although opening is exvlusive in v4l, threads can share 
fds. Thus read & write must be protected.

On a related note: v4l open has an SMP race condition. Please test the 
attached fix.

	Regards
		Oliver
--- drivers/media/video/videodev.c.alt	Sun Oct 29 20:42:54 2000
+++ drivers/media/video/videodev.c	Sun Oct 29 20:49:49 2000
@@ -30,16 +30,17 @@

 #include <asm/uaccess.h>
 #include <asm/system.h>
+#include <asm/bitops.h>

 #include <linux/kmod.h>


-#define VIDEO_NUM_DEVICES	256
+#define VIDEO_NUM_DEVICES	256

 /*
- *	Active devices
+ *	Active devices
  */
-
+
 static struct video_device *video_device[VIDEO_NUM_DEVICES];
@@ -145,10 +146,10 @@
 	unsigned int minor = MINOR(inode->i_rdev);
 	int err;
 	struct video_device *vfl;
-
+
 	if(minor>=VIDEO_NUM_DEVICES)
 		return -ENODEV;
-
+
 	vfl=video_device[minor];
 	if(vfl==NULL) {
 		char modname[20];
@@ -159,16 +160,15 @@
 		if (vfl==NULL)
 			return -ENODEV;
 	}
-	if(vfl->busy)
+	if(test_and_set_bit(0,&(vfl->busy)))
 		return -EBUSY;
-	vfl->busy=1;		/* In case vfl->open sleeps */
-
+
 	if(vfl->open)
 	{
 		err=vfl->open(vfl,0);	/* Tell the device it is open */
 		if(err)
 		{
-			vfl->busy=0;
+			clear_bit(0,&(vfl->busy));
 			return err;
 		}
 	}

[Index of Archives]     [Linux DVB]     [Video Disk Recorder]     [Asterisk]     [Photo]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Free Photo Albums]     [Fedora Users]     [Fedora Women]     [ALSA Users]     [ALSA Devel]     [Linux USB]

Powered by Linux