Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
[sfrench/cifs-2.6.git] / drivers / media / video / usbvideo / usbvideo.c
index d34d8c8b73767bb0bab4b94c38f01ff22f1d4a55..5d363be7bc735762475576cb9e7dc6db43f04b80 100644 (file)
@@ -20,7 +20,6 @@
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/mm.h>
-#include <linux/smp_lock.h>
 #include <linux/vmalloc.h>
 #include <linux/init.h>
 #include <linux/spinlock.h>
@@ -628,24 +627,21 @@ EXPORT_SYMBOL(usbvideo_HexDump);
 /* ******************************************************************** */
 
 /* XXX: this piece of crap really wants some error handling.. */
-static void usbvideo_ClientIncModCount(struct uvd *uvd)
+static int usbvideo_ClientIncModCount(struct uvd *uvd)
 {
        if (uvd == NULL) {
                err("%s: uvd == NULL", __FUNCTION__);
-               return;
+               return -EINVAL;
        }
        if (uvd->handle == NULL) {
                err("%s: uvd->handle == NULL", __FUNCTION__);
-               return;
-       }
-       if (uvd->handle->md_module == NULL) {
-               err("%s: uvd->handle->md_module == NULL", __FUNCTION__);
-               return;
+               return -EINVAL;
        }
        if (!try_module_get(uvd->handle->md_module)) {
                err("%s: try_module_get() == 0", __FUNCTION__);
-               return;
+               return -ENODEV;
        }
+       return 0;
 }
 
 static void usbvideo_ClientDecModCount(struct uvd *uvd)
@@ -712,8 +708,6 @@ int usbvideo_register(
        cams->num_cameras = num_cams;
        cams->cam = (struct uvd *) &cams[1];
        cams->md_module = md;
-       if (cams->md_module == NULL)
-               warn("%s: module == NULL!", __FUNCTION__);
        mutex_init(&cams->lock);        /* to 1 == available */
 
        for (i = 0; i < num_cams; i++) {
@@ -958,7 +952,6 @@ static const struct file_operations usbvideo_fops = {
 static const struct video_device usbvideo_template = {
        .owner =      THIS_MODULE,
        .type =       VID_TYPE_CAPTURE,
-       .hardware =   VID_HARDWARE_CPIA,
        .fops =       &usbvideo_fops,
 };
 
@@ -1041,6 +1034,11 @@ int usbvideo_RegisterVideoDevice(struct uvd *uvd)
                info("%s: iface=%d. endpoint=$%02x paletteBits=$%08lx",
                     __FUNCTION__, uvd->iface, uvd->video_endp, uvd->paletteBits);
        }
+       if (uvd->dev == NULL) {
+               err("%s: uvd->dev == NULL", __FUNCTION__);
+               return -EINVAL;
+       }
+       uvd->vdev.dev=&(uvd->dev->dev);
        if (video_register_device(&uvd->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
                err("%s: video_register_device failed", __FUNCTION__);
                return -EPIPE;
@@ -1048,10 +1046,6 @@ int usbvideo_RegisterVideoDevice(struct uvd *uvd)
        if (uvd->debug > 1) {
                info("%s: video_register_device() successful", __FUNCTION__);
        }
-       if (uvd->dev == NULL) {
-               err("%s: uvd->dev == NULL", __FUNCTION__);
-               return -EINVAL;
-       }
 
        info("%s on /dev/video%d: canvas=%s videosize=%s",
             (uvd->handle != NULL) ? uvd->handle->drvName : "???",
@@ -1119,7 +1113,8 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
        if (uvd->debug > 1)
                info("%s($%p)", __FUNCTION__, dev);
 
-       usbvideo_ClientIncModCount(uvd);
+       if (0 < usbvideo_ClientIncModCount(uvd))
+               return -ENODEV;
        mutex_lock(&uvd->lock);
 
        if (uvd->user) {