From: Mauro Carvalho Chehab <m.chehab@samsung.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com,
s.nawrocki@samsung.com, ismael.luceno@corp.bluecherry.net,
pete@sensoray.com, sakari.ailus@iki.fi,
Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [REVIEWv3 PATCH 14/35] v4l2-ctrls: prepare for matrix support.
Date: Wed, 12 Mar 2014 07:42:21 -0300 [thread overview]
Message-ID: <20140312074221.73ee30b1@samsung.com> (raw)
In-Reply-To: <1392631070-41868-15-git-send-email-hverkuil@xs4all.nl>
Em Mon, 17 Feb 2014 10:57:29 +0100
Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> From: Hans Verkuil <hans.verkuil@cisco.com>
>
> Add core support for matrices.
Again, this patch has negative values for array index.
I'll stop analyzing here, as it is hard to keep the mind in a
sane state seeing those crazy things ;)
>
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
> drivers/media/v4l2-core/v4l2-ctrls.c | 54 +++++++++++++++++++++++-------------
> include/media/v4l2-ctrls.h | 8 ++++--
> 2 files changed, 39 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
> index 49ce52e..f76716e 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
> @@ -1132,7 +1132,7 @@ static void send_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 changes)
> v4l2_event_queue_fh(sev->fh, &ev);
> }
>
> -static bool std_equal(const struct v4l2_ctrl *ctrl,
> +static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
> union v4l2_ctrl_ptr ptr1,
> union v4l2_ctrl_ptr ptr2)
> {
> @@ -1151,7 +1151,7 @@ static bool std_equal(const struct v4l2_ctrl *ctrl,
> }
> }
>
> -static void std_init(const struct v4l2_ctrl *ctrl,
> +static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
> union v4l2_ctrl_ptr ptr)
> {
> switch (ctrl->type) {
> @@ -1178,6 +1178,9 @@ static void std_log(const struct v4l2_ctrl *ctrl)
> {
> union v4l2_ctrl_ptr ptr = ctrl->stores[0];
>
> + if (ctrl->is_matrix)
> + pr_cont("[%u][%u] ", ctrl->rows, ctrl->cols);
> +
> switch (ctrl->type) {
> case V4L2_CTRL_TYPE_INTEGER:
> pr_cont("%d", *ptr.p_s32);
> @@ -1220,7 +1223,7 @@ static void std_log(const struct v4l2_ctrl *ctrl)
> })
>
> /* Validate a new control */
> -static int std_validate(const struct v4l2_ctrl *ctrl,
> +static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx,
> union v4l2_ctrl_ptr ptr)
> {
> size_t len;
> @@ -1444,7 +1447,7 @@ static int cluster_changed(struct v4l2_ctrl *master)
>
> if (ctrl == NULL)
> continue;
> - ctrl->has_changed = !ctrl->type_ops->equal(ctrl,
> + ctrl->has_changed = !ctrl->type_ops->equal(ctrl, 0,
> ctrl->stores[0], ctrl->new);
> changed |= ctrl->has_changed;
> }
> @@ -1502,15 +1505,15 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
> case V4L2_CTRL_TYPE_BUTTON:
> case V4L2_CTRL_TYPE_CTRL_CLASS:
> ptr.p_s32 = &c->value;
> - return ctrl->type_ops->validate(ctrl, ptr);
> + return ctrl->type_ops->validate(ctrl, 0, ptr);
>
> case V4L2_CTRL_TYPE_INTEGER64:
> ptr.p_s64 = &c->value64;
> - return ctrl->type_ops->validate(ctrl, ptr);
> + return ctrl->type_ops->validate(ctrl, 0, ptr);
>
> default:
> ptr.p = c->p;
> - return ctrl->type_ops->validate(ctrl, ptr);
> + return ctrl->type_ops->validate(ctrl, 0, ptr);
> }
> }
>
> @@ -1736,7 +1739,8 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
> const s64 *qmenu_int, void *priv)
> {
> struct v4l2_ctrl *ctrl;
> - unsigned sz_extra;
> + bool is_matrix;
> + unsigned sz_extra, tot_ctrl_size;
> void *data;
> int err;
> int s;
> @@ -1748,6 +1752,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
> cols = 1;
> if (rows == 0)
> rows = 1;
> + is_matrix = cols > 1 || rows > 1;
>
> if (type == V4L2_CTRL_TYPE_INTEGER64)
> elem_size = sizeof(s64);
> @@ -1755,17 +1760,18 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
> elem_size = max + 1;
> else if (type < V4L2_CTRL_COMPLEX_TYPES)
> elem_size = sizeof(s32);
> + tot_ctrl_size = elem_size * cols * rows;
>
> /* Sanity checks */
> - if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE ||
> - elem_size == 0 ||
> + if (id == 0 || name == NULL || !elem_size ||
> + id >= V4L2_CID_PRIVATE_BASE ||
> (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) ||
> (type == V4L2_CTRL_TYPE_INTEGER_MENU && qmenu_int == NULL)) {
> handler_set_err(hdl, -ERANGE);
> return NULL;
> }
> /* Complex controls are always hidden */
> - if (type >= V4L2_CTRL_COMPLEX_TYPES)
> + if (is_matrix || type >= V4L2_CTRL_COMPLEX_TYPES)
> flags |= V4L2_CTRL_FLAG_HIDDEN;
> err = check_range(type, min, max, step, def);
> if (err) {
> @@ -1776,14 +1782,21 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
> handler_set_err(hdl, -ERANGE);
> return NULL;
> }
> + if (is_matrix &&
> + (type == V4L2_CTRL_TYPE_BUTTON ||
> + type == V4L2_CTRL_TYPE_CTRL_CLASS)) {
> + handler_set_err(hdl, -EINVAL);
> + return NULL;
> + }
>
> - sz_extra = elem_size;
> + sz_extra = tot_ctrl_size;
> if (type == V4L2_CTRL_TYPE_BUTTON)
> flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
> else if (type == V4L2_CTRL_TYPE_CTRL_CLASS)
> flags |= V4L2_CTRL_FLAG_READ_ONLY;
> - else if (type == V4L2_CTRL_TYPE_STRING || type >= V4L2_CTRL_COMPLEX_TYPES)
> - sz_extra += elem_size;
> + else if (type == V4L2_CTRL_TYPE_STRING ||
> + type >= V4L2_CTRL_COMPLEX_TYPES || is_matrix)
> + sz_extra += tot_ctrl_size;
>
> ctrl = kzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL);
> if (ctrl == NULL) {
> @@ -1805,9 +1818,10 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
> ctrl->maximum = max;
> ctrl->step = step;
> ctrl->default_value = def;
> - ctrl->is_string = type == V4L2_CTRL_TYPE_STRING;
> - ctrl->is_ptr = type >= V4L2_CTRL_COMPLEX_TYPES || ctrl->is_string;
> + ctrl->is_string = !is_matrix && type == V4L2_CTRL_TYPE_STRING;
> + ctrl->is_ptr = is_matrix || type >= V4L2_CTRL_COMPLEX_TYPES || ctrl->is_string;
> ctrl->is_int = !ctrl->is_ptr && type != V4L2_CTRL_TYPE_INTEGER64;
> + ctrl->is_matrix = is_matrix;
> ctrl->cols = cols;
> ctrl->rows = rows;
> ctrl->elem_size = elem_size;
> @@ -1821,13 +1835,13 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
>
> if (ctrl->is_ptr) {
> for (s = -1; s <= 0; s++)
> - ctrl->stores[s].p = data + (s + 1) * elem_size;
> + ctrl->stores[s].p = data + (s + 1) * tot_ctrl_size;
> } else {
> ctrl->new.p = &ctrl->val;
> ctrl->stores[0].p = data;
> }
> for (s = -1; s <= 0; s++)
> - ctrl->type_ops->init(ctrl, ctrl->stores[s]);
> + ctrl->type_ops->init(ctrl, 0, ctrl->stores[s]);
>
> if (handler_new_ref(hdl, ctrl)) {
> kfree(ctrl);
> @@ -2734,7 +2748,7 @@ s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl)
> struct v4l2_ext_control c;
>
> /* It's a driver bug if this happens. */
> - WARN_ON(ctrl->type != V4L2_CTRL_TYPE_INTEGER64);
> + WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64);
> c.value = 0;
> get_ctrl(ctrl, &c);
> return c.value;
> @@ -3044,7 +3058,7 @@ int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
> struct v4l2_ext_control c;
>
> /* It's a driver bug if this happens. */
> - WARN_ON(ctrl->type != V4L2_CTRL_TYPE_INTEGER64);
> + WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64);
> c.value64 = val;
> return set_ctrl_lock(NULL, ctrl, &c);
> }
> diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
> index 1b06930..7d72328 100644
> --- a/include/media/v4l2-ctrls.h
> +++ b/include/media/v4l2-ctrls.h
> @@ -74,13 +74,13 @@ struct v4l2_ctrl_ops {
> * @validate: validate the value. Return 0 on success and a negative value otherwise.
> */
> struct v4l2_ctrl_type_ops {
> - bool (*equal)(const struct v4l2_ctrl *ctrl,
> + bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx,
> union v4l2_ctrl_ptr ptr1,
> union v4l2_ctrl_ptr ptr2);
> - void (*init)(const struct v4l2_ctrl *ctrl,
> + void (*init)(const struct v4l2_ctrl *ctrl, u32 idx,
> union v4l2_ctrl_ptr ptr);
> void (*log)(const struct v4l2_ctrl *ctrl);
> - int (*validate)(const struct v4l2_ctrl *ctrl,
> + int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
> union v4l2_ctrl_ptr ptr);
> };
>
> @@ -111,6 +111,7 @@ typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
> * @is_ptr: If set, then this control is a matrix and/or has type >= V4L2_CTRL_COMPLEX_TYPES
> * and/or has type V4L2_CTRL_TYPE_STRING. In other words, struct
> * v4l2_ext_control uses field p to point to the data.
> + * @is_matrix: If set, then this control contains a matrix.
> * @has_volatiles: If set, then one or more members of the cluster are volatile.
> * Drivers should never touch this flag.
> * @call_notify: If set, then call the handler's notify function whenever the
> @@ -169,6 +170,7 @@ struct v4l2_ctrl {
> unsigned int is_int:1;
> unsigned int is_string:1;
> unsigned int is_ptr:1;
> + unsigned int is_matrix:1;
> unsigned int has_volatiles:1;
> unsigned int call_notify:1;
> unsigned int manual_mode_value:8;
--
Regards,
Mauro
next prev parent reply other threads:[~2014-03-12 10:42 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-17 9:57 [REVIEWv3 PATCH 00/35] Add support for complex controls, use in solo/go7007 Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 01/35] v4l2-ctrls: increase internal min/max/step/def to 64 bit Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 02/35] v4l2-ctrls: add unit string Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 03/35] v4l2-ctrls: use pr_info/cont instead of printk Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 04/35] videodev2.h: add initial support for complex controls Hans Verkuil
2014-03-11 19:34 ` Mauro Carvalho Chehab
2014-03-11 20:23 ` Hans Verkuil
2014-03-11 23:48 ` Mauro Carvalho Chehab
2014-02-17 9:57 ` [REVIEWv3 PATCH 05/35] videodev2.h: add struct v4l2_query_ext_ctrl and VIDIOC_QUERY_EXT_CTRL Hans Verkuil
2014-03-11 19:42 ` Mauro Carvalho Chehab
2014-03-11 20:29 ` Hans Verkuil
2014-03-11 23:35 ` Mauro Carvalho Chehab
2014-02-17 9:57 ` [REVIEWv3 PATCH 06/35] v4l2-ctrls: add support for complex types Hans Verkuil
2014-03-11 20:14 ` Mauro Carvalho Chehab
2014-03-11 20:43 ` Hans Verkuil
2014-03-11 23:43 ` Mauro Carvalho Chehab
2014-02-17 9:57 ` [REVIEWv3 PATCH 07/35] v4l2: integrate support for VIDIOC_QUERY_EXT_CTRL Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 08/35] v4l2-ctrls: create type_ops Hans Verkuil
2014-03-11 20:22 ` Mauro Carvalho Chehab
2014-03-11 20:49 ` Hans Verkuil
2014-03-11 23:56 ` Mauro Carvalho Chehab
2014-02-17 9:57 ` [REVIEWv3 PATCH 09/35] v4l2-ctrls: rewrite copy routines to operate on union v4l2_ctrl_ptr Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 10/35] v4l2-ctrls: compare values only once Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 11/35] v4l2-ctrls: prepare for matrix support: add cols & rows fields Hans Verkuil
2014-03-12 10:34 ` Mauro Carvalho Chehab
2014-02-17 9:57 ` [REVIEWv3 PATCH 12/35] v4l2-ctrls: replace cur by a union v4l2_ctrl_ptr Hans Verkuil
2014-03-12 10:38 ` Mauro Carvalho Chehab
2014-02-17 9:57 ` [REVIEWv3 PATCH 13/35] v4l2-ctrls: use 'new' to access pointer controls Hans Verkuil
2014-03-12 10:40 ` Mauro Carvalho Chehab
2014-02-17 9:57 ` [REVIEWv3 PATCH 14/35] v4l2-ctrls: prepare for matrix support Hans Verkuil
2014-03-12 10:42 ` Mauro Carvalho Chehab [this message]
2014-03-12 12:21 ` Hans Verkuil
2014-03-12 13:00 ` Mauro Carvalho Chehab
2014-03-12 13:00 ` Mauro Carvalho Chehab
2014-03-12 13:41 ` Hans Verkuil
2014-03-12 13:44 ` Sylwester Nawrocki
2014-02-17 9:57 ` [REVIEWv3 PATCH 15/35] v4l2-ctrls: type_ops can handle matrix elements Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 16/35] v4l2-ctrls: add matrix support Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 17/35] v4l2-ctrls: return elem_size instead of strlen Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 18/35] v4l2-ctrl: fix error return of copy_to/from_user Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 19/35] DocBook media: document VIDIOC_QUERY_EXT_CTRL Hans Verkuil
2014-03-12 14:13 ` Mauro Carvalho Chehab
2014-03-13 7:58 ` Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 20/35] DocBook media: update VIDIOC_G/S/TRY_EXT_CTRLS Hans Verkuil
2014-03-12 14:20 ` Mauro Carvalho Chehab
2014-03-13 12:18 ` Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 21/35] DocBook media: fix coding style in the control example code Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 22/35] DocBook media: update control section Hans Verkuil
2014-02-19 23:15 ` Sakari Ailus
2014-03-12 14:27 ` Mauro Carvalho Chehab
2014-02-17 9:57 ` [REVIEWv3 PATCH 23/35] v4l2-controls.txt: update to the new way of accessing controls Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 24/35] v4l2-ctrls/videodev2.h: add u8 and u16 types Hans Verkuil
2014-03-12 14:44 ` Mauro Carvalho Chehab
2014-02-17 9:57 ` [REVIEWv3 PATCH 25/35] DocBook media: document new u8 and u16 control types Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 26/35] v4l2-ctrls: fix comments Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 27/35] v4l2-ctrls/v4l2-controls.h: add MD controls Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 28/35] DocBook media: document new motion detection controls Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 29/35] v4l2: add a motion detection event Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 30/35] DocBook: document new v4l " Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 31/35] solo6x10: implement the new motion detection controls Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 32/35] solo6x10: implement the motion detection event Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 33/35] solo6x10: fix 'dma from stack' warning Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 34/35] solo6x10: check dma_map_sg() return value Hans Verkuil
2014-02-17 9:57 ` [REVIEWv3 PATCH 35/35] go7007: add motion detection support Hans Verkuil
2014-02-19 8:28 ` [REVIEWv3 PATCH 00/35] Add support for complex controls, use in solo/go7007 Ricardo Ribalda Delgado
2014-02-19 8:54 ` Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140312074221.73ee30b1@samsung.com \
--to=m.chehab@samsung.com \
--cc=hans.verkuil@cisco.com \
--cc=hverkuil@xs4all.nl \
--cc=ismael.luceno@corp.bluecherry.net \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=pete@sensoray.com \
--cc=s.nawrocki@samsung.com \
--cc=sakari.ailus@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.