ChangeSet 1.855.9.6, 2002/10/31 23:43:47-08:00, jtyner@cs.ucr.edu [PATCH] USB vicam.c: minor fixes This patch fixes some things that have failed to go in as part of other patches that have been rejected. Namely, this adds the forgotten up call in the read function, removes the usb_put_dev (since there is no usb_get_dev), and also moves the allocation and freeing of the image and frame buffers to the open and close calls only. diff -Nru a/drivers/usb/media/vicam.c b/drivers/usb/media/vicam.c --- a/drivers/usb/media/vicam.c Tue Nov 5 16:10:39 2002 +++ b/drivers/usb/media/vicam.c Tue Nov 5 16:10:40 2002 @@ -761,23 +761,19 @@ return -EBUSY; } + cam->raw_image = kmalloc(VICAM_MAX_READ_SIZE, GFP_KERNEL); if (!cam->raw_image) { - cam->raw_image = kmalloc(VICAM_MAX_READ_SIZE, GFP_KERNEL); - if (!cam->raw_image) { - up(&cam->busy_lock); - return -ENOMEM; - } + up(&cam->busy_lock); + return -ENOMEM; } + cam->framebuf = rvmalloc(VICAM_MAX_FRAME_SIZE * VICAM_FRAMES); if (!cam->framebuf) { - cam->framebuf = - rvmalloc(VICAM_MAX_FRAME_SIZE * VICAM_FRAMES); - if (!cam->framebuf) { - kfree(cam->raw_image); - up(&cam->busy_lock); - return -ENOMEM; - } + kfree(cam->raw_image); + up(&cam->busy_lock); + return -ENOMEM; } + // First upload firmware, then turn the camera on if (!cam->is_initialized) { @@ -805,6 +801,9 @@ DBG("close\n"); set_camera_power(cam, 0); + kfree(cam->raw_image); + rvfree(cam->framebuf, VICAM_MAX_FRAME_SIZE * VICAM_FRAMES); + cam->open_count--; return 0; @@ -989,6 +988,7 @@ if (*ppos >= VICAM_MAX_FRAME_SIZE) { *ppos = 0; + up(&cam->busy_lock); return 0; } @@ -1038,15 +1038,6 @@ if (down_interruptible(&cam->busy_lock)) return -EINTR; - if (!cam->framebuf) { /* we do lazy allocation */ - cam->framebuf = - rvmalloc(VICAM_MAX_FRAME_SIZE * VICAM_FRAMES); - if (!cam->framebuf) { - up(&cam->busy_lock); - return -ENOMEM; - } - } - pos = (unsigned long)cam->framebuf; while (size > 0) { page = kvirt_to_pa(pos); @@ -1319,7 +1310,6 @@ struct vicam_camera *cam = dev_get_drvdata(&intf->dev); dev_set_drvdata ( &intf->dev, NULL ); - usb_put_dev(cam->udev); cam->udev = NULL; @@ -1328,12 +1318,6 @@ #ifdef CONFIG_PROC_FS vicam_destroy_proc_entry(cam); #endif - - if (cam->raw_image) - kfree(cam->raw_image); - if (cam->framebuf) - rvfree(cam->framebuf, - VICAM_MAX_FRAME_SIZE * VICAM_FRAMES); kfree(cam);