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 3/7] v4l2-ctrls: Make the control type init op initialize the whole control
Date: Thu, 22 Jan 2015 16:12:31 +0100 [thread overview]
Message-ID: <54C1135F.30504@xs4all.nl> (raw)
In-Reply-To: <1421938126-17747-4-git-send-email-laurent.pinchart@ideasonboard.com>
On 01/22/15 15:48, 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>
> ---
> drivers/media/v4l2-core/v4l2-ctrls.c | 40 +++++++++++++++++++++++++++++-------
> include/media/v4l2-ctrls.h | 3 +--
> 2 files changed, 34 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
> index adac93e..ba996de 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:
> @@ -1301,6 +1301,35 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
> }
> }
>
> +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);
std_init_one still contains support for TYPE_U8, which can now be removed,
and the default case can be removed as well (or reduced to just a break
statement).
> + 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;
> + }
> +}
> +
> static void std_log(const struct v4l2_ctrl *ctrl)
> {
> union v4l2_ctrl_ptr ptr = ctrl->p_cur;
> @@ -1929,7 +1958,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 +2077,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);
>
Regards,
Hans
next prev parent reply other threads:[~2015-01-22 15:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-22 14:48 [PATCH 0/7] omap4iss: Add RGB2RGB blending matrix support Laurent Pinchart
2015-01-22 14:48 ` [PATCH 1/7] v4l2-ctrls: Add new S8, S16 and S32 compound control types Laurent Pinchart
2015-01-22 15:07 ` Hans Verkuil
2015-01-22 14:48 ` [PATCH 2/7] v4l2-ctrls: Don't initialize array tail when setting a control Laurent Pinchart
2015-01-22 15:07 ` Hans Verkuil
2015-01-22 14:48 ` [PATCH 3/7] v4l2-ctrls: Make the control type init op initialize the whole control Laurent Pinchart
2015-01-22 15:12 ` Hans Verkuil [this message]
2015-01-22 16:13 ` Laurent Pinchart
2015-01-22 14:48 ` [PATCH 4/7] v4l2-ctrls: Export the standard control type operations Laurent Pinchart
2015-01-22 15:13 ` Hans Verkuil
2015-01-22 14:48 ` [PATCH 5/7] Revert "[media] v4l: omap4iss: Add module debug parameter" Laurent Pinchart
2015-01-22 15:14 ` Hans Verkuil
2015-01-22 14:48 ` [PATCH 6/7] staging: media: omap4iss: Cleanup media entities after unregistration Laurent Pinchart
2015-01-22 14:48 ` [PATCH 7/7] staging: media: omap4iss: ipipe: Expose the RGB2RGB blending matrix 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=54C1135F.30504@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.