Commit a0001a28 authored by Hans de Goede's avatar Hans de Goede Committed by Mauro Carvalho Chehab

V4L/DVB (11972): gspca - main: Skip disabled controls.

Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarJean-Francois Moine <moinejf@free.fr>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 3d48f7d0
...@@ -983,43 +983,54 @@ static int vidioc_querycap(struct file *file, void *priv, ...@@ -983,43 +983,54 @@ static int vidioc_querycap(struct file *file, void *priv,
return ret; return ret;
} }
static const struct ctrl *get_ctrl(struct gspca_dev *gspca_dev,
int id)
{
const struct ctrl *ctrls;
int i;
for (i = 0, ctrls = gspca_dev->sd_desc->ctrls;
i < gspca_dev->sd_desc->nctrls;
i++, ctrls++) {
if (gspca_dev->ctrl_dis & (1 << i))
continue;
if (id == ctrls->qctrl.id)
return ctrls;
}
return NULL;
}
static int vidioc_queryctrl(struct file *file, void *priv, static int vidioc_queryctrl(struct file *file, void *priv,
struct v4l2_queryctrl *q_ctrl) struct v4l2_queryctrl *q_ctrl)
{ {
struct gspca_dev *gspca_dev = priv; struct gspca_dev *gspca_dev = priv;
int i, ix; const struct ctrl *ctrls;
int i;
u32 id; u32 id;
ix = -1; ctrls = NULL;
id = q_ctrl->id; id = q_ctrl->id;
if (id & V4L2_CTRL_FLAG_NEXT_CTRL) { if (id & V4L2_CTRL_FLAG_NEXT_CTRL) {
id &= V4L2_CTRL_ID_MASK; id &= V4L2_CTRL_ID_MASK;
id++; id++;
for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) {
if (gspca_dev->sd_desc->ctrls[i].qctrl.id < id) if (gspca_dev->ctrl_dis & (1 << i))
continue; continue;
if (ix < 0) { if (ctrls->qctrl.id < id)
ix = i;
continue; continue;
} if (ctrls != NULL) {
if (gspca_dev->sd_desc->ctrls[i].qctrl.id if (gspca_dev->sd_desc->ctrls[i].qctrl.id
> gspca_dev->sd_desc->ctrls[ix].qctrl.id) > ctrls->qctrl.id)
continue; continue;
ix = i;
} }
ctrls = &gspca_dev->sd_desc->ctrls[i];
} }
for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { } else {
if (id == gspca_dev->sd_desc->ctrls[i].qctrl.id) { ctrls = get_ctrl(gspca_dev, id);
ix = i;
break;
}
} }
if (ix < 0) if (ctrls == NULL)
return -EINVAL; return -EINVAL;
memcpy(q_ctrl, &gspca_dev->sd_desc->ctrls[ix].qctrl, memcpy(q_ctrl, ctrls, sizeof *q_ctrl);
sizeof *q_ctrl);
if (gspca_dev->ctrl_dis & (1 << ix))
q_ctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
return 0; return 0;
} }
...@@ -1028,15 +1039,12 @@ static int vidioc_s_ctrl(struct file *file, void *priv, ...@@ -1028,15 +1039,12 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
{ {
struct gspca_dev *gspca_dev = priv; struct gspca_dev *gspca_dev = priv;
const struct ctrl *ctrls; const struct ctrl *ctrls;
int i, ret; int ret;
for (i = 0, ctrls = gspca_dev->sd_desc->ctrls; ctrls = get_ctrl(gspca_dev, ctrl->id);
i < gspca_dev->sd_desc->nctrls; if (ctrls == NULL)
i++, ctrls++) {
if (ctrl->id != ctrls->qctrl.id)
continue;
if (gspca_dev->ctrl_dis & (1 << i))
return -EINVAL; return -EINVAL;
if (ctrl->value < ctrls->qctrl.minimum if (ctrl->value < ctrls->qctrl.minimum
|| ctrl->value > ctrls->qctrl.maximum) || ctrl->value > ctrls->qctrl.maximum)
return -ERANGE; return -ERANGE;
...@@ -1049,25 +1057,19 @@ static int vidioc_s_ctrl(struct file *file, void *priv, ...@@ -1049,25 +1057,19 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
ret = -ENODEV; ret = -ENODEV;
mutex_unlock(&gspca_dev->usb_lock); mutex_unlock(&gspca_dev->usb_lock);
return ret; return ret;
}
return -EINVAL;
} }
static int vidioc_g_ctrl(struct file *file, void *priv, static int vidioc_g_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl) struct v4l2_control *ctrl)
{ {
struct gspca_dev *gspca_dev = priv; struct gspca_dev *gspca_dev = priv;
const struct ctrl *ctrls; const struct ctrl *ctrls;
int i, ret; int ret;
for (i = 0, ctrls = gspca_dev->sd_desc->ctrls; ctrls = get_ctrl(gspca_dev, ctrl->id);
i < gspca_dev->sd_desc->nctrls; if (ctrls == NULL)
i++, ctrls++) {
if (ctrl->id != ctrls->qctrl.id)
continue;
if (gspca_dev->ctrl_dis & (1 << i))
return -EINVAL; return -EINVAL;
if (mutex_lock_interruptible(&gspca_dev->usb_lock)) if (mutex_lock_interruptible(&gspca_dev->usb_lock))
return -ERESTARTSYS; return -ERESTARTSYS;
if (gspca_dev->present) if (gspca_dev->present)
...@@ -1076,8 +1078,6 @@ static int vidioc_g_ctrl(struct file *file, void *priv, ...@@ -1076,8 +1078,6 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
ret = -ENODEV; ret = -ENODEV;
mutex_unlock(&gspca_dev->usb_lock); mutex_unlock(&gspca_dev->usb_lock);
return ret; return ret;
}
return -EINVAL;
} }
/*fixme: have an audio flag in gspca_dev?*/ /*fixme: have an audio flag in gspca_dev?*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment