[Linux-uvc-devel] [PATCH] device open counter
Linux UVC driver and tools
Brought to you by:
pinchartl
|
From: Alexandre B. <di...@fr...> - 2006-01-28 06:19:13
|
Hello,
I wrote a quick patch to prevent device open more than once. This will prevent
kernel crash with the current driver.
--- uvc/uvcvideo.c 2006-01-28 04:39:39.000000000 +0100
+++ uvc2/uvcvideo.c 2006-01-28 04:30:48.000000000 +0100
@@ -295,6 +295,7 @@
};
struct uvc_video_device {
+ int count;
struct uvc_device *dev;
struct video_device *vdev;
@@ -1543,6 +1544,7 @@
video->streaming->cur_format = format;
video->streaming->cur_frame = frame;
+ video->count = 0;
return 0;
}
@@ -1868,13 +1870,24 @@
video = video_get_drvdata(vdev);
if (video->dev->state & UVC_DEV_DISCONNECTED) {
+ uvc_printk(KERN_DEBUG, "uvc_v4l2_open failed: disconnected\n");
up(&dev_sem);
return -ENODEV;
}
+ if (video->count > 0) {
+ uvc_printk(KERN_DEBUG, "uvc_v4l2_open failed: count = %u\n", video->count);
+ up(&dev_sem);
+ return -EBUSY;
+ }
+
+ video->count++;
+
kref_get(&video->dev->kref);
up(&dev_sem);
+ uvc_printk(KERN_DEBUG, "uvc_v4l2_open done\n");
+
return 0;
}
@@ -1891,7 +1904,11 @@
uvc_printk(KERN_DEBUG, "uvc_v4l2_release: Unable to free buffers.\n");
up(&video->queue.lock);
+ down(&dev_sem);
kref_put(&video->dev->kref, uvc_delete);
+ video->count--;
+ up(&dev_sem);
+
uvc_printk(KERN_DEBUG, "< uvc_v4l2_release\n");
return 0;
}
--
Alexandre
|