media: cropcap/g_selection split
[sfrench/cifs-2.6.git] / drivers / media / usb / cx231xx / cx231xx-video.c
index f7fcd733a2ca8de24360a30fc5e08a6d80902589..34b55e6699717526cba0b68b6cda18af5d5baaf7 100644 (file)
@@ -1169,7 +1169,7 @@ int cx231xx_enum_input(struct file *file, void *priv,
        i->index = n;
        i->type = V4L2_INPUT_TYPE_CAMERA;
 
-       strcpy(i->name, iname[INPUT(n)->type]);
+       strscpy(i->name, iname[INPUT(n)->type], sizeof(i->name));
 
        if ((CX231XX_VMUX_TELEVISION == INPUT(n)->type) ||
            (CX231XX_VMUX_CABLE == INPUT(n)->type))
@@ -1244,7 +1244,7 @@ int cx231xx_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
        if (0 != t->index)
                return -EINVAL;
 
-       strcpy(t->name, "Tuner");
+       strscpy(t->name, "Tuner", sizeof(t->name));
 
        t->type = V4L2_TUNER_ANALOG_TV;
        t->capability = V4L2_TUNER_CAP_NORM;
@@ -1354,22 +1354,22 @@ int cx231xx_g_chip_info(struct file *file, void *fh,
        case 0: /* Cx231xx - internal registers */
                return 0;
        case 1: /* AFE - read byte */
-               strlcpy(chip->name, "AFE (byte)", sizeof(chip->name));
+               strscpy(chip->name, "AFE (byte)", sizeof(chip->name));
                return 0;
        case 2: /* Video Block - read byte */
-               strlcpy(chip->name, "Video (byte)", sizeof(chip->name));
+               strscpy(chip->name, "Video (byte)", sizeof(chip->name));
                return 0;
        case 3: /* I2S block - read byte */
-               strlcpy(chip->name, "I2S (byte)", sizeof(chip->name));
+               strscpy(chip->name, "I2S (byte)", sizeof(chip->name));
                return 0;
        case 4: /* AFE - read dword */
-               strlcpy(chip->name, "AFE (dword)", sizeof(chip->name));
+               strscpy(chip->name, "AFE (dword)", sizeof(chip->name));
                return 0;
        case 5: /* Video Block - read dword */
-               strlcpy(chip->name, "Video (dword)", sizeof(chip->name));
+               strscpy(chip->name, "Video (dword)", sizeof(chip->name));
                return 0;
        case 6: /* I2S Block - read dword */
-               strlcpy(chip->name, "I2S (dword)", sizeof(chip->name));
+               strscpy(chip->name, "I2S (dword)", sizeof(chip->name));
                return 0;
        }
        return -EINVAL;
@@ -1389,7 +1389,7 @@ int cx231xx_g_register(struct file *file, void *priv,
                ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
                                (u16)reg->reg, value, 4);
                reg->val = value[0] | value[1] << 8 |
-                       value[2] << 16 | value[3] << 24;
+                       value[2] << 16 | (u32)value[3] << 24;
                reg->size = 4;
                break;
        case 1: /* AFE - read byte */
@@ -1492,17 +1492,35 @@ static int vidioc_cropcap(struct file *file, void *priv,
        if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
 
-       cc->bounds.left = 0;
-       cc->bounds.top = 0;
-       cc->bounds.width = dev->width;
-       cc->bounds.height = dev->height;
-       cc->defrect = cc->bounds;
        cc->pixelaspect.numerator = is_50hz ? 54 : 11;
        cc->pixelaspect.denominator = is_50hz ? 59 : 10;
 
        return 0;
 }
 
+static int vidioc_g_selection(struct file *file, void *priv,
+                             struct v4l2_selection *s)
+{
+       struct cx231xx_fh *fh = priv;
+       struct cx231xx *dev = fh->dev;
+
+       if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               return -EINVAL;
+
+       switch (s->target) {
+       case V4L2_SEL_TGT_CROP_BOUNDS:
+       case V4L2_SEL_TGT_CROP_DEFAULT:
+               s->r.left = 0;
+               s->r.top = 0;
+               s->r.width = dev->width;
+               s->r.height = dev->height;
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
 static int vidioc_streamon(struct file *file, void *priv,
                           enum v4l2_buf_type type)
 {
@@ -1553,8 +1571,8 @@ int cx231xx_querycap(struct file *file, void *priv,
        struct cx231xx_fh *fh = priv;
        struct cx231xx *dev = fh->dev;
 
-       strlcpy(cap->driver, "cx231xx", sizeof(cap->driver));
-       strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card));
+       strscpy(cap->driver, "cx231xx", sizeof(cap->driver));
+       strscpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card));
        usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
 
        if (vdev->vfl_type == VFL_TYPE_RADIO)
@@ -1583,7 +1601,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
        if (unlikely(f->index >= ARRAY_SIZE(format)))
                return -EINVAL;
 
-       strlcpy(f->description, format[f->index].name, sizeof(f->description));
+       strscpy(f->description, format[f->index].name, sizeof(f->description));
        f->pixelformat = format[f->index].fourcc;
 
        return 0;
@@ -1716,7 +1734,7 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
        if (t->index)
                return -EINVAL;
 
-       strcpy(t->name, "Radio");
+       strscpy(t->name, "Radio", sizeof(t->name));
 
        call_all(dev, tuner, g_tuner, t);
 
@@ -2094,6 +2112,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
        .vidioc_try_fmt_vbi_cap        = vidioc_try_fmt_vbi_cap,
        .vidioc_s_fmt_vbi_cap          = vidioc_s_fmt_vbi_cap,
        .vidioc_cropcap                = vidioc_cropcap,
+       .vidioc_g_selection            = vidioc_g_selection,
        .vidioc_reqbufs                = vidioc_reqbufs,
        .vidioc_querybuf               = vidioc_querybuf,
        .vidioc_qbuf                   = vidioc_qbuf,
@@ -2204,10 +2223,10 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
 
        if (dev->sd_cx25840) {
                v4l2_ctrl_add_handler(&dev->ctrl_handler,
-                               dev->sd_cx25840->ctrl_handler, NULL);
+                               dev->sd_cx25840->ctrl_handler, NULL, true);
                v4l2_ctrl_add_handler(&dev->radio_ctrl_handler,
                                dev->sd_cx25840->ctrl_handler,
-                               v4l2_ctrl_radio_filter);
+                               v4l2_ctrl_radio_filter, true);
        }
 
        if (dev->ctrl_handler.error)
@@ -2242,7 +2261,8 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
 
        /* Initialize VBI template */
        cx231xx_vbi_template = cx231xx_video_template;
-       strcpy(cx231xx_vbi_template.name, "cx231xx-vbi");
+       strscpy(cx231xx_vbi_template.name, "cx231xx-vbi",
+               sizeof(cx231xx_vbi_template.name));
 
        /* Allocate and fill vbi video_device struct */
        cx231xx_vdev_init(dev, &dev->vbi_dev, &cx231xx_vbi_template, "vbi");