patch-2.4.21 linux-2.4.21/drivers/media/video/cpia_usb.c
Next file: linux-2.4.21/drivers/media/video/meye.c
Previous file: linux-2.4.21/drivers/media/video/cpia_pp.c
Back to the patch index
Back to the overall index
- Lines: 150
- Date:
2003-06-13 07:51:34.000000000 -0700
- Orig file:
linux-2.4.20/drivers/media/video/cpia_usb.c
- Orig date:
2002-11-28 15:53:13.000000000 -0800
diff -urN linux-2.4.20/drivers/media/video/cpia_usb.c linux-2.4.21/drivers/media/video/cpia_usb.c
@@ -21,11 +21,13 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+/* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */
+/* #define _CPIA_DEBUG_ 1 */
+
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/wait.h>
-#include <linux/sched.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
@@ -100,10 +102,11 @@
cpia_usb_streamStop,
cpia_usb_streamRead,
cpia_usb_close,
- 0
+ 0,
+ THIS_MODULE
};
-static struct cam_data *cam_list;
+static LIST_HEAD(cam_list);
static spinlock_t cam_list_lock_usb;
static void cpia_usb_complete(struct urb *urb)
@@ -456,12 +459,14 @@
{
struct usb_cpia *ucpia = (struct usb_cpia *) privdata;
- ucpia->open = 0;
+ if(!ucpia)
+ return -ENODEV;
- cpia_usb_free_resources(ucpia, 1);
+ ucpia->open = 0;
- if (!ucpia->present)
- kfree(ucpia);
+ /* ucpia->present = 0 protects against trying to reset the
+ * alt setting if camera is physically disconnected while open */
+ cpia_usb_free_resources(ucpia, ucpia->present);
return 0;
}
@@ -540,7 +545,7 @@
}
spin_lock( &cam_list_lock_usb );
- cpia_add_to_list(cam_list, cam);
+ list_add( &cam->cam_data_list, &cam_list );
spin_unlock( &cam_list_lock_usb );
return cam;
@@ -555,6 +560,7 @@
vfree(ucpia->buffers[0]);
ucpia->buffers[0] = NULL;
fail_alloc_0:
+ kfree(ucpia);
return NULL;
}
@@ -578,76 +584,57 @@
id_table: cpia_id_table,
};
-/* don't use dev, it may be NULL! (see usb_cpia_cleanup) */
-/* _disconnect from usb_cpia_cleanup is not necessary since usb_deregister */
-/* will do it for us as well as passing a udev structure - jerdfelt */
static void cpia_disconnect(struct usb_device *udev, void *ptr)
{
struct cam_data *cam = (struct cam_data *) ptr;
struct usb_cpia *ucpia = (struct usb_cpia *) cam->lowlevel_data;
spin_lock( &cam_list_lock_usb );
- cpia_remove_from_list(cam);
+ list_del(&cam->cam_data_list);
spin_unlock( &cam_list_lock_usb );
- /* Don't even try to reset the altsetting if we're disconnected */
- cpia_usb_free_resources(ucpia, 0);
-
ucpia->present = 0;
-
cpia_unregister_camera(cam);
+ if(ucpia->open)
+ cpia_usb_close(cam->lowlevel_data);
ucpia->curbuff->status = FRAME_ERROR;
-
if (waitqueue_active(&ucpia->wq_stream))
wake_up_interruptible(&ucpia->wq_stream);
-
usb_driver_release_interface(&cpia_driver,
&udev->actconfig->interface[0]);
-
ucpia->curbuff = ucpia->workbuff = NULL;
-
if (ucpia->buffers[2]) {
vfree(ucpia->buffers[2]);
ucpia->buffers[2] = NULL;
}
-
if (ucpia->buffers[1]) {
vfree(ucpia->buffers[1]);
ucpia->buffers[1] = NULL;
}
-
if (ucpia->buffers[0]) {
vfree(ucpia->buffers[0]);
ucpia->buffers[0] = NULL;
}
- if (!ucpia->open) {
- kfree(ucpia);
- cam->lowlevel_data = NULL;
- }
+ cam->lowlevel_data = NULL;
+ kfree(ucpia);
}
static int __init usb_cpia_init(void)
{
- cam_list = NULL;
+ printk(KERN_INFO "%s v%d.%d.%d\n",ABOUT,
+ CPIA_USB_MAJ_VER,CPIA_USB_MIN_VER,CPIA_USB_PATCH_VER);
+
spin_lock_init(&cam_list_lock_usb);
return usb_register(&cpia_driver);
}
static void __exit usb_cpia_cleanup(void)
{
-/*
- struct cam_data *cam;
-
- while ((cam = cam_list) != NULL)
- cpia_disconnect(NULL, cam);
-*/
-
usb_deregister(&cpia_driver);
}
-
module_init (usb_cpia_init);
module_exit (usb_cpia_cleanup);
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)