Skip to content

Commit 6494d35

Browse files
ribaldamchehab
authored andcommitted
media: v4l2-core: Introduce v4l2_query_ext_ctrl_to_v4l2_queryctrl
We use this logic in a couple of places. Refactor into a function. No functional change expected from this patch. Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 0d75129 commit 6494d35

3 files changed

Lines changed: 44 additions & 47 deletions

File tree

drivers/media/v4l2-core/v4l2-ctrls-api.c

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,39 +1157,48 @@ int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_query_ext_ctr
11571157
}
11581158
EXPORT_SYMBOL(v4l2_query_ext_ctrl);
11591159

1160-
/* Implement VIDIOC_QUERYCTRL */
1161-
int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc)
1160+
void v4l2_query_ext_ctrl_to_v4l2_queryctrl(struct v4l2_queryctrl *to,
1161+
const struct v4l2_query_ext_ctrl *from)
11621162
{
1163-
struct v4l2_query_ext_ctrl qec = { qc->id };
1164-
int rc;
1163+
to->id = from->id;
1164+
to->type = from->type;
1165+
to->flags = from->flags;
1166+
strscpy(to->name, from->name, sizeof(to->name));
11651167

1166-
rc = v4l2_query_ext_ctrl(hdl, &qec);
1167-
if (rc)
1168-
return rc;
1169-
1170-
qc->id = qec.id;
1171-
qc->type = qec.type;
1172-
qc->flags = qec.flags;
1173-
strscpy(qc->name, qec.name, sizeof(qc->name));
1174-
switch (qc->type) {
1168+
switch (from->type) {
11751169
case V4L2_CTRL_TYPE_INTEGER:
11761170
case V4L2_CTRL_TYPE_BOOLEAN:
11771171
case V4L2_CTRL_TYPE_MENU:
11781172
case V4L2_CTRL_TYPE_INTEGER_MENU:
11791173
case V4L2_CTRL_TYPE_STRING:
11801174
case V4L2_CTRL_TYPE_BITMASK:
1181-
qc->minimum = qec.minimum;
1182-
qc->maximum = qec.maximum;
1183-
qc->step = qec.step;
1184-
qc->default_value = qec.default_value;
1175+
to->minimum = from->minimum;
1176+
to->maximum = from->maximum;
1177+
to->step = from->step;
1178+
to->default_value = from->default_value;
11851179
break;
11861180
default:
1187-
qc->minimum = 0;
1188-
qc->maximum = 0;
1189-
qc->step = 0;
1190-
qc->default_value = 0;
1181+
to->minimum = 0;
1182+
to->maximum = 0;
1183+
to->step = 0;
1184+
to->default_value = 0;
11911185
break;
11921186
}
1187+
}
1188+
EXPORT_SYMBOL(v4l2_query_ext_ctrl_to_v4l2_queryctrl);
1189+
1190+
/* Implement VIDIOC_QUERYCTRL */
1191+
int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc)
1192+
{
1193+
struct v4l2_query_ext_ctrl qec = { qc->id };
1194+
int rc;
1195+
1196+
rc = v4l2_query_ext_ctrl(hdl, &qec);
1197+
if (rc)
1198+
return rc;
1199+
1200+
v4l2_query_ext_ctrl_to_v4l2_queryctrl(qc, &qec);
1201+
11931202
return 0;
11941203
}
11951204
EXPORT_SYMBOL(v4l2_queryctrl);

drivers/media/v4l2-core/v4l2-ioctl.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,32 +2304,8 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
23042304
ret = ops->vidioc_query_ext_ctrl(file, fh, &qec);
23052305
if (ret)
23062306
return ret;
2307-
2308-
p->id = qec.id;
2309-
p->type = qec.type;
2310-
p->flags = qec.flags;
2311-
strscpy(p->name, qec.name, sizeof(p->name));
2312-
switch (p->type) {
2313-
case V4L2_CTRL_TYPE_INTEGER:
2314-
case V4L2_CTRL_TYPE_BOOLEAN:
2315-
case V4L2_CTRL_TYPE_MENU:
2316-
case V4L2_CTRL_TYPE_INTEGER_MENU:
2317-
case V4L2_CTRL_TYPE_STRING:
2318-
case V4L2_CTRL_TYPE_BITMASK:
2319-
p->minimum = qec.minimum;
2320-
p->maximum = qec.maximum;
2321-
p->step = qec.step;
2322-
p->default_value = qec.default_value;
2323-
break;
2324-
default:
2325-
p->minimum = 0;
2326-
p->maximum = 0;
2327-
p->step = 0;
2328-
p->default_value = 0;
2329-
break;
2330-
}
2331-
2332-
return 0;
2307+
v4l2_query_ext_ctrl_to_v4l2_queryctrl(p, &qec);
2308+
return ret;
23332309
}
23342310

23352311
static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops,

include/media/v4l2-ctrls.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,18 @@ v4l2_ctrl_request_hdl_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
14321432
*/
14331433
int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
14341434

1435+
/**
1436+
* v4l2_query_ext_ctrl_to_v4l2_queryctrl - Convert a qec to qe.
1437+
*
1438+
* @to: The v4l2_queryctrl to write to.
1439+
* @from: The v4l2_query_ext_ctrl to read from.
1440+
*
1441+
* This function is a helper to convert a v4l2_query_ext_ctrl into a
1442+
* v4l2_queryctrl.
1443+
*/
1444+
void v4l2_query_ext_ctrl_to_v4l2_queryctrl(struct v4l2_queryctrl *to,
1445+
const struct v4l2_query_ext_ctrl *from);
1446+
14351447
/**
14361448
* v4l2_query_ext_ctrl - Helper function to implement
14371449
* :ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl

0 commit comments

Comments
 (0)