V4L/DVB (4958): Fix namespace conflict between w9968cf.c on MIPS
[safe/jmp/linux-2.6] / drivers / media / video / v4l1-compat.c
index d679ca2..8a13e59 100644 (file)
@@ -16,7 +16,6 @@
  *
  */
 
-#include <linux/config.h>
 
 #include <linux/init.h>
 #include <linux/module.h>
@@ -32,6 +31,7 @@
 #include <linux/errno.h>
 #include <linux/slab.h>
 #include <linux/videodev.h>
+#include <media/v4l2-common.h>
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
@@ -305,9 +305,8 @@ v4l_compat_translate_ioctl(struct inode         *inode,
        {
                struct video_capability *cap = arg;
 
-               cap2 = kmalloc(sizeof(*cap2),GFP_KERNEL);
+               cap2 = kzalloc(sizeof(*cap2),GFP_KERNEL);
                memset(cap, 0, sizeof(*cap));
-               memset(cap2, 0, sizeof(*cap2));
                memset(&fbuf2, 0, sizeof(fbuf2));
 
                err = drv(inode, file, VIDIOC_QUERYCAP, cap2);
@@ -350,6 +349,9 @@ v4l_compat_translate_ioctl(struct inode         *inode,
        {
                struct video_buffer     *buffer = arg;
 
+               memset(buffer, 0, sizeof(*buffer));
+               memset(&fbuf2, 0, sizeof(fbuf2));
+
                err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
                if (err < 0) {
                        dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n",err);
@@ -362,7 +364,7 @@ v4l_compat_translate_ioctl(struct inode         *inode,
                switch (fbuf2.fmt.pixelformat) {
                case V4L2_PIX_FMT_RGB332:
                        buffer->depth = 8;
-                               break;
+                       break;
                case V4L2_PIX_FMT_RGB555:
                        buffer->depth = 15;
                        break;
@@ -378,9 +380,13 @@ v4l_compat_translate_ioctl(struct inode         *inode,
                default:
                        buffer->depth = 0;
                }
-               if (0 != fbuf2.fmt.bytesperline)
+               if (fbuf2.fmt.bytesperline) {
                        buffer->bytesperline = fbuf2.fmt.bytesperline;
-               else {
+                       if (!buffer->depth && buffer->width)
+                               buffer->depth   = ((fbuf2.fmt.bytesperline<<3)
+                                                 + (buffer->width-1) )
+                                                 /buffer->width;
+               } else {
                        buffer->bytesperline =
                                (buffer->width * buffer->depth + 7) & 7;
                        buffer->bytesperline >>= 3;
@@ -422,9 +428,8 @@ v4l_compat_translate_ioctl(struct inode         *inode,
        {
                struct video_window     *win = arg;
 
-               fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
+               fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
                memset(win,0,sizeof(*win));
-               memset(fmt2,0,sizeof(*fmt2));
 
                fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
                err = drv(inode, file, VIDIOC_G_FMT, fmt2);
@@ -461,8 +466,7 @@ v4l_compat_translate_ioctl(struct inode         *inode,
                struct video_window     *win = arg;
                int err1,err2;
 
-               fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
-               memset(fmt2,0,sizeof(*fmt2));
+               fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
                fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                drv(inode, file, VIDIOC_STREAMOFF, &fmt2->type);
                err1 = drv(inode, file, VIDIOC_G_FMT, fmt2);
@@ -595,14 +599,17 @@ v4l_compat_translate_ioctl(struct inode         *inode,
                pict->whiteness = get_v4l_control(inode, file,
                                                  V4L2_CID_WHITENESS, drv);
 
-               fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
-               memset(fmt2,0,sizeof(*fmt2));
+               fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
                fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                err = drv(inode, file, VIDIOC_G_FMT, fmt2);
                if (err < 0) {
                        dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n",err);
                        break;
                }
+
+               pict->depth   = ((fmt2->fmt.pix.bytesperline<<3)
+                                + (fmt2->fmt.pix.width-1) )
+                                /fmt2->fmt.pix.width;
                pict->palette = pixelformat_to_palette(
                        fmt2->fmt.pix.pixelformat);
                break;
@@ -610,6 +617,7 @@ v4l_compat_translate_ioctl(struct inode         *inode,
        case VIDIOCSPICT: /*  set tone controls & partial capture format  */
        {
                struct video_picture    *pict = arg;
+               memset(&fbuf2, 0, sizeof(fbuf2));
 
                set_v4l_control(inode, file,
                                V4L2_CID_BRIGHTNESS, pict->brightness, drv);
@@ -622,8 +630,7 @@ v4l_compat_translate_ioctl(struct inode         *inode,
                set_v4l_control(inode, file,
                                V4L2_CID_WHITENESS, pict->whiteness, drv);
 
-               fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
-               memset(fmt2,0,sizeof(*fmt2));
+               fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
                fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                err = drv(inode, file, VIDIOC_G_FMT, fmt2);
                if (err < 0)
@@ -703,12 +710,22 @@ v4l_compat_translate_ioctl(struct inode         *inode,
        }
        case VIDIOCSTUNER: /*  select a tuner input  */
        {
-               err = 0;
+               struct video_tuner      *tun = arg;
+               struct v4l2_tuner       t;
+               memset(&t,0,sizeof(t));
+
+               t.index=tun->tuner;
+
+               err = drv(inode, file, VIDIOC_S_INPUT, &t);
+               if (err < 0)
+                       dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n",err);
+
                break;
        }
        case VIDIOCGFREQ: /*  get frequency  */
        {
-               int *freq = arg;
+               unsigned long *freq = arg;
+               memset(&freq2,0,sizeof(freq2));
 
                freq2.tuner = 0;
                err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
@@ -720,9 +737,9 @@ v4l_compat_translate_ioctl(struct inode         *inode,
        }
        case VIDIOCSFREQ: /*  set frequency  */
        {
-               int *freq = arg;
+               unsigned long *freq = arg;
+               memset(&freq2,0,sizeof(freq2));
 
-               freq2.tuner = 0;
                drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
                freq2.frequency = *freq;
                err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2);
@@ -733,6 +750,7 @@ v4l_compat_translate_ioctl(struct inode         *inode,
        case VIDIOCGAUDIO: /*  get audio properties/controls  */
        {
                struct video_audio      *aud = arg;
+               memset(&aud2,0,sizeof(aud2));
 
                err = drv(inode, file, VIDIOC_G_AUDIO, &aud2);
                if (err < 0) {
@@ -846,9 +864,8 @@ v4l_compat_translate_ioctl(struct inode         *inode,
        {
                struct video_mmap       *mm = arg;
 
-               fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
+               fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
                memset(&buf2,0,sizeof(buf2));
-               memset(fmt2,0,sizeof(*fmt2));
 
                fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                err = drv(inode, file, VIDIOC_G_FMT, fmt2);
@@ -894,6 +911,7 @@ v4l_compat_translate_ioctl(struct inode         *inode,
        {
                int                     *i = arg;
 
+               memset(&buf2,0,sizeof(buf2));
                buf2.index = *i;
                buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
@@ -942,8 +960,7 @@ v4l_compat_translate_ioctl(struct inode         *inode,
        {
                struct vbi_format      *fmt = arg;
 
-               fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
-               memset(fmt2, 0, sizeof(*fmt2));
+               fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
                fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
 
                err = drv(inode, file, VIDIOC_G_FMT, fmt2);
@@ -951,6 +968,10 @@ v4l_compat_translate_ioctl(struct inode         *inode,
                        dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err);
                        break;
                }
+               if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) {
+                       err = -EINVAL;
+                       break;
+               }
                memset(fmt, 0, sizeof(*fmt));
                fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
                fmt->sampling_rate    = fmt2->fmt.vbi.sampling_rate;
@@ -960,14 +981,18 @@ v4l_compat_translate_ioctl(struct inode         *inode,
                fmt->start[1]         = fmt2->fmt.vbi.start[1];
                fmt->count[1]         = fmt2->fmt.vbi.count[1];
                fmt->flags            = fmt2->fmt.vbi.flags & 0x03;
-                break;
+               break;
        }
        case VIDIOCSVBIFMT:
        {
                struct vbi_format      *fmt = arg;
 
-               fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
-               memset(fmt2, 0, sizeof(*fmt2));
+               if (VIDEO_PALETTE_RAW != fmt->sample_format) {
+                       err = -EINVAL;
+                       break;
+               }
+
+               fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
 
                fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
                fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
@@ -986,7 +1011,7 @@ v4l_compat_translate_ioctl(struct inode         *inode,
 
                if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
                    fmt2->fmt.vbi.sampling_rate    != fmt->sampling_rate    ||
-                   VIDEO_PALETTE_RAW              != fmt->sample_format    ||
+                   fmt2->fmt.vbi.sample_format    != V4L2_PIX_FMT_GREY     ||
                    fmt2->fmt.vbi.start[0]         != fmt->start[0]         ||
                    fmt2->fmt.vbi.count[0]         != fmt->count[0]         ||
                    fmt2->fmt.vbi.start[1]         != fmt->start[1]         ||