From: Hans Verkuil <hverkuil@xs4all.nl>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
linux-media@vger.kernel.org
Cc: sadegh abbasi <sadegh612000@yahoo.co.uk>
Subject: Re: [PATCH v2 3/6] v4l2-ctrls: Make the control type init op initialize the whole control
Date: Wed, 28 Jan 2015 11:20:44 +0100 [thread overview]
Message-ID: <54C8B7FC.4090806@xs4all.nl> (raw)
In-Reply-To: <1422436639-18292-4-git-send-email-laurent.pinchart@ideasonboard.com>
On 01/28/15 10:17, Laurent Pinchart wrote:
> The control type init operation is called in a loop to initialize all
> elements of a control. Not only is this inefficient for control types
> that could use a memset(), it also complicates the implementation of
> custom control types, for instance when a matrix needs to be initialized
> with different values for its elements.
>
> Make the init operation initialize the whole control instead, and use
> memset() when possible.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Thanks!
Hans
> ---
> drivers/media/v4l2-core/v4l2-ctrls.c | 46 ++++++++++++++++++++++++++----------
> include/media/v4l2-ctrls.h | 3 +--
> 2 files changed, 34 insertions(+), 15 deletions(-)
>
> Changes since v1:
>
> - Remove support for V4L2_CTRL_TYPE_U8 and V4L2_CTRL_TYPE_S8 from
> std_init_one(), as those cases are now handled by std_init()
>
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
> index adac93e..81b8e66 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
> @@ -1263,8 +1263,8 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
> }
> }
>
> -static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
> - union v4l2_ctrl_ptr ptr)
> +static void std_init_one(const struct v4l2_ctrl *ctrl, u32 idx,
> + union v4l2_ctrl_ptr ptr)
> {
> switch (ctrl->type) {
> case V4L2_CTRL_TYPE_STRING:
> @@ -1282,10 +1282,6 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
> case V4L2_CTRL_TYPE_BOOLEAN:
> ptr.p_s32[idx] = ctrl->default_value;
> break;
> - case V4L2_CTRL_TYPE_U8:
> - case V4L2_CTRL_TYPE_S8:
> - ptr.p_u8[idx] = ctrl->default_value;
> - break;
> case V4L2_CTRL_TYPE_U16:
> case V4L2_CTRL_TYPE_S16:
> ptr.p_u16[idx] = ctrl->default_value;
> @@ -1295,8 +1291,35 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
> ptr.p_u32[idx] = ctrl->default_value;
> break;
> default:
> - idx *= ctrl->elem_size;
> - memset(ptr.p + idx, 0, ctrl->elem_size);
> + break;
> + }
> +}
> +
> +static void std_init(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr ptr)
> +{
> + u32 idx;
> +
> + switch (ctrl->type) {
> + case V4L2_CTRL_TYPE_STRING:
> + case V4L2_CTRL_TYPE_INTEGER64:
> + case V4L2_CTRL_TYPE_INTEGER:
> + case V4L2_CTRL_TYPE_INTEGER_MENU:
> + case V4L2_CTRL_TYPE_MENU:
> + case V4L2_CTRL_TYPE_BITMASK:
> + case V4L2_CTRL_TYPE_BOOLEAN:
> + case V4L2_CTRL_TYPE_U16:
> + case V4L2_CTRL_TYPE_S16:
> + case V4L2_CTRL_TYPE_U32:
> + case V4L2_CTRL_TYPE_S32:
> + for (idx = 0; idx < ctrl->elems; idx++)
> + std_init_one(ctrl, idx, ptr);
> + break;
> + case V4L2_CTRL_TYPE_U8:
> + case V4L2_CTRL_TYPE_S8:
> + memset(ptr.p_u8, ctrl->default_value, ctrl->elems);
> + break;
> + default:
> + memset(ptr.p, 0, ctrl->elems * ctrl->elem_size);
> break;
> }
> }
> @@ -1929,7 +1952,6 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
> unsigned elems = 1;
> bool is_array;
> unsigned tot_ctrl_size;
> - unsigned idx;
> void *data;
> int err;
>
> @@ -2049,10 +2071,8 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
> ctrl->p_new.p = &ctrl->val;
> ctrl->p_cur.p = &ctrl->cur.val;
> }
> - for (idx = 0; idx < elems; idx++) {
> - ctrl->type_ops->init(ctrl, idx, ctrl->p_cur);
> - ctrl->type_ops->init(ctrl, idx, ctrl->p_new);
> - }
> + ctrl->type_ops->init(ctrl, ctrl->p_cur);
> + ctrl->type_ops->init(ctrl, ctrl->p_new);
>
> if (handler_new_ref(hdl, ctrl)) {
> kfree(ctrl);
> diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
> index e1cfb8f..a7280e9 100644
> --- a/include/media/v4l2-ctrls.h
> +++ b/include/media/v4l2-ctrls.h
> @@ -87,8 +87,7 @@ struct v4l2_ctrl_type_ops {
> 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, u32 idx,
> - union v4l2_ctrl_ptr ptr);
> + void (*init)(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr ptr);
> void (*log)(const struct v4l2_ctrl *ctrl);
> int (*validate)(const struct v4l2_ctrl *ctrl, u32 idx,
> union v4l2_ctrl_ptr ptr);
>
next prev parent reply other threads:[~2015-01-28 20:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-28 9:17 [PATCH v2 0/6] omap4iss: Add RGB2RGB blending matrix support Laurent Pinchart
2015-01-28 9:17 ` [PATCH v2 1/6] v4l2-ctrls: Add new S8, S16 and S32 compound control types Laurent Pinchart
2015-01-28 10:19 ` Hans Verkuil
[not found] ` <532636346.4083310.1436543123211.JavaMail.yahoo@mail.yahoo.com>
2015-07-12 22:18 ` Laurent Pinchart
2015-07-13 8:12 ` Hans Verkuil
2015-01-28 9:17 ` [PATCH v2 2/6] v4l2-ctrls: Don't initialize array tail when setting a control Laurent Pinchart
2015-01-28 9:17 ` [PATCH v2 3/6] v4l2-ctrls: Make the control type init op initialize the whole control Laurent Pinchart
2015-01-28 10:20 ` Hans Verkuil [this message]
2015-01-28 9:17 ` [PATCH v2 4/6] v4l2-ctrls: Export the standard control type operations Laurent Pinchart
2015-01-28 9:17 ` [PATCH v2 5/6] staging: media: omap4iss: Cleanup media entities after unregistration Laurent Pinchart
2015-01-28 9:17 ` [PATCH v2 6/6] staging: media: omap4iss: ipipe: Expose the RGB2RGB blending matrix Laurent Pinchart
2015-01-28 10:27 ` Hans Verkuil
2015-01-28 12:18 ` Laurent Pinchart
2015-06-14 10:30 ` Laurent Pinchart
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=54C8B7FC.4090806@xs4all.nl \
--to=hverkuil@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=sadegh612000@yahoo.co.uk \
/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.