pr_cont("driver-specific ioctl\n");
 }
 
-static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
+static bool check_ext_ctrls(struct v4l2_ext_controls *c, unsigned long ioctl)
 {
        __u32 i;
 
        for (i = 0; i < c->count; i++)
                c->controls[i].reserved2[0] = 0;
 
-       /* V4L2_CID_PRIVATE_BASE cannot be used as control class
-          when using extended controls.
-          Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
-          is it allowed for backwards compatibility.
-        */
-       if (!allow_priv && c->which == V4L2_CID_PRIVATE_BASE)
-               return 0;
-       if (!c->which)
-               return 1;
+       switch (c->which) {
+       case V4L2_CID_PRIVATE_BASE:
+               /*
+                * V4L2_CID_PRIVATE_BASE cannot be used as control class
+                * when using extended controls.
+                * Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
+                * is it allowed for backwards compatibility.
+                */
+               if (ioctl == VIDIOC_G_CTRL || ioctl == VIDIOC_S_CTRL)
+                       return false;
+               break;
+       case V4L2_CTRL_WHICH_DEF_VAL:
+               /* Default value cannot be changed */
+               if (ioctl == VIDIOC_S_EXT_CTRLS ||
+                   ioctl == VIDIOC_TRY_EXT_CTRLS) {
+                       c->error_idx = c->count;
+                       return false;
+               }
+               return true;
+       case V4L2_CTRL_WHICH_CUR_VAL:
+               return true;
+       case V4L2_CTRL_WHICH_REQUEST_VAL:
+               c->error_idx = c->count;
+               return false;
+       }
+
        /* Check that all controls are from the same control class. */
        for (i = 0; i < c->count; i++) {
                if (V4L2_CTRL_ID2WHICH(c->controls[i].id) != c->which) {
-                       c->error_idx = i;
-                       return 0;
+                       c->error_idx = ioctl == VIDIOC_TRY_EXT_CTRLS ? i :
+                                                                     c->count;
+                       return false;
                }
        }
-       return 1;
+       return true;
 }
 
 static int check_fmt(struct file *file, enum v4l2_buf_type type)
        ctrls.controls = &ctrl;
        ctrl.id = p->id;
        ctrl.value = p->value;
-       if (check_ext_ctrls(&ctrls, 1)) {
+       if (check_ext_ctrls(&ctrls, VIDIOC_G_CTRL)) {
                int ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
 
                if (ret == 0)
        ctrls.controls = &ctrl;
        ctrl.id = p->id;
        ctrl.value = p->value;
-       if (check_ext_ctrls(&ctrls, 1))
+       if (check_ext_ctrls(&ctrls, VIDIOC_S_CTRL))
                return ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
        return -EINVAL;
 }
                                        vfd, vfd->v4l2_dev->mdev, p);
        if (ops->vidioc_g_ext_ctrls == NULL)
                return -ENOTTY;
-       return check_ext_ctrls(p, 0) ? ops->vidioc_g_ext_ctrls(file, fh, p) :
-                                       -EINVAL;
+       return check_ext_ctrls(p, VIDIOC_G_EXT_CTRLS) ?
+                               ops->vidioc_g_ext_ctrls(file, fh, p) : -EINVAL;
 }
 
 static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
                                        vfd, vfd->v4l2_dev->mdev, p);
        if (ops->vidioc_s_ext_ctrls == NULL)
                return -ENOTTY;
-       return check_ext_ctrls(p, 0) ? ops->vidioc_s_ext_ctrls(file, fh, p) :
-                                       -EINVAL;
+       return check_ext_ctrls(p, VIDIOC_S_EXT_CTRLS) ?
+                               ops->vidioc_s_ext_ctrls(file, fh, p) : -EINVAL;
 }
 
 static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
                                          vfd, vfd->v4l2_dev->mdev, p);
        if (ops->vidioc_try_ext_ctrls == NULL)
                return -ENOTTY;
-       return check_ext_ctrls(p, 0) ? ops->vidioc_try_ext_ctrls(file, fh, p) :
-                                       -EINVAL;
+       return check_ext_ctrls(p, VIDIOC_TRY_EXT_CTRLS) ?
+                       ops->vidioc_try_ext_ctrls(file, fh, p) : -EINVAL;
 }
 
 /*