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
> ctrls->qctrl.id)
continue;
} }
if (gspca_dev->sd_desc->ctrls[i].qctrl.id ctrls = &gspca_dev->sd_desc->ctrls[i];
> gspca_dev->sd_desc->ctrls[ix].qctrl.id)
continue;
ix = i;
}
}
for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) {
if (id == gspca_dev->sd_desc->ctrls[i].qctrl.id) {
ix = i;
break;
} }
} else {
ctrls = get_ctrl(gspca_dev, id);
} }
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,56 +1039,45 @@ static int vidioc_s_ctrl(struct file *file, void *priv, ...@@ -1028,56 +1039,45 @@ 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++) { return -EINVAL;
if (ctrl->id != ctrls->qctrl.id)
continue; if (ctrl->value < ctrls->qctrl.minimum
if (gspca_dev->ctrl_dis & (1 << i)) || ctrl->value > ctrls->qctrl.maximum)
return -EINVAL; return -ERANGE;
if (ctrl->value < ctrls->qctrl.minimum PDEBUG(D_CONF, "set ctrl [%08x] = %d", ctrl->id, ctrl->value);
|| ctrl->value > ctrls->qctrl.maximum) if (mutex_lock_interruptible(&gspca_dev->usb_lock))
return -ERANGE; return -ERESTARTSYS;
PDEBUG(D_CONF, "set ctrl [%08x] = %d", ctrl->id, ctrl->value); if (gspca_dev->present)
if (mutex_lock_interruptible(&gspca_dev->usb_lock)) ret = ctrls->set(gspca_dev, ctrl->value);
return -ERESTARTSYS; else
if (gspca_dev->present) ret = -ENODEV;
ret = ctrls->set(gspca_dev, ctrl->value); mutex_unlock(&gspca_dev->usb_lock);
else return ret;
ret = -ENODEV;
mutex_unlock(&gspca_dev->usb_lock);
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++) { return -EINVAL;
if (ctrl->id != ctrls->qctrl.id)
continue; if (mutex_lock_interruptible(&gspca_dev->usb_lock))
if (gspca_dev->ctrl_dis & (1 << i)) return -ERESTARTSYS;
return -EINVAL; if (gspca_dev->present)
if (mutex_lock_interruptible(&gspca_dev->usb_lock)) ret = ctrls->get(gspca_dev, &ctrl->value);
return -ERESTARTSYS; else
if (gspca_dev->present) ret = -ENODEV;
ret = ctrls->get(gspca_dev, &ctrl->value); mutex_unlock(&gspca_dev->usb_lock);
else return ret;
ret = -ENODEV;
mutex_unlock(&gspca_dev->usb_lock);
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