Merge branch 'master' into upstream
[sfrench/cifs-2.6.git] / drivers / media / video / videodev.c
index b26ebaff226f49182537c0a350ff4189969eaddf..479a0675cf60bf8ddfc7b6a372077be03063b35a 100644 (file)
@@ -739,13 +739,13 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
        case VIDIOC_DQBUF:
        {
                struct v4l2_buffer *p=arg;
-               if (!vfd->vidioc_qbuf)
+               if (!vfd->vidioc_dqbuf)
                        break;
                ret = check_fmt (vfd, p->type);
                if (ret)
                        break;
 
-               ret=vfd->vidioc_qbuf(file, fh, p);
+               ret=vfd->vidioc_dqbuf(file, fh, p);
                if (!ret)
                        dbgbuf(cmd,vfd,p);
                break;
@@ -760,7 +760,7 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
                ret=vfd->vidioc_overlay(file, fh, *i);
                break;
        }
-#ifdef HAVE_V4L1
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
        /* --- streaming capture ------------------------------------- */
        case VIDIOCGMBUF:
        {
@@ -836,7 +836,7 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
                        break;
                }
 
-               if (index<=0 || index >= vfd->tvnormsize) {
+               if (index<0 || index >= vfd->tvnormsize) {
                        ret=-EINVAL;
                        break;
                }
@@ -1283,9 +1283,29 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
        case VIDIOC_G_PARM:
        {
                struct v4l2_streamparm *p=arg;
-               if (!vfd->vidioc_g_parm)
-                       break;
-               ret=vfd->vidioc_g_parm(file, fh, p);
+               if (vfd->vidioc_g_parm) {
+                       ret=vfd->vidioc_g_parm(file, fh, p);
+               } else {
+                       struct v4l2_standard s;
+
+                       if (!vfd->tvnormsize) {
+                               printk (KERN_WARNING "%s: no TV norms defined!\n",
+                                                       vfd->name);
+                               break;
+                       }
+
+                       if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+                               return -EINVAL;
+
+                       v4l2_video_std_construct(&s, vfd->tvnorms[vfd->current_norm].id,
+                                                vfd->tvnorms[vfd->current_norm].name);
+
+                       memset(p,0,sizeof(*p));
+
+                       p->parm.capture.timeperframe = s.frameperiod;
+                       ret=0;
+               }
+
                dbgarg (cmd, "type=%d\n", p->type);
                break;
        }
@@ -1512,6 +1532,7 @@ int video_register_device(struct video_device *vfd, int type, int nr)
        int i=0;
        int base;
        int end;
+       int ret;
        char *name_base;
 
        switch(type)
@@ -1537,6 +1558,8 @@ int video_register_device(struct video_device *vfd, int type, int nr)
                        name_base = "radio";
                        break;
                default:
+                       printk(KERN_ERR "%s called with unknown type: %d\n",
+                              __FUNCTION__, type);
                        return -1;
        }
 
@@ -1571,9 +1594,18 @@ int video_register_device(struct video_device *vfd, int type, int nr)
        vfd->class_dev.class       = &video_class;
        vfd->class_dev.devt        = MKDEV(VIDEO_MAJOR, vfd->minor);
        sprintf(vfd->class_dev.class_id, "%s%d", name_base, i - base);
-       class_device_register(&vfd->class_dev);
-       class_device_create_file(&vfd->class_dev,
-                               &class_device_attr_name);
+       ret = class_device_register(&vfd->class_dev);
+       if (ret < 0) {
+               printk(KERN_ERR "%s: class_device_register failed\n",
+                      __FUNCTION__);
+               goto fail_minor;
+       }
+       ret = class_device_create_file(&vfd->class_dev, &class_device_attr_name);
+       if (ret < 0) {
+               printk(KERN_ERR "%s: class_device_create_file 'name' failed\n",
+                      __FUNCTION__);
+               goto fail_classdev;
+       }
 
 #if 1
        /* needed until all drivers are fixed */
@@ -1583,6 +1615,15 @@ int video_register_device(struct video_device *vfd, int type, int nr)
                       "http://lwn.net/Articles/36850/\n", vfd->name);
 #endif
        return 0;
+
+fail_classdev:
+       class_device_unregister(&vfd->class_dev);
+fail_minor:
+       mutex_lock(&videodev_lock);
+       video_device[vfd->minor] = NULL;
+       vfd->minor = -1;
+       mutex_unlock(&videodev_lock);
+       return ret;
 }
 
 /**