From: Ricardo Ribalda Delgado <ribalda@kernel.org>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Ricardo Ribalda Delgado <ribalda@kernel.org>
Subject: [PATCH v4 6/6] media: v4l2-ctrl: Use p_const when possible
Date: Mon, 4 Nov 2019 14:09:23 +0100 [thread overview]
Message-ID: <20191104130923.22184-6-ribalda@kernel.org> (raw)
In-Reply-To: <20191104130923.22184-1-ribalda@kernel.org>
After adding a const pointer to ctrl_ptr, lets use it where it make
sense.
Suggested-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Ricardo Ribalda Delgado <ribalda@kernel.org>
---
drivers/media/v4l2-core/v4l2-ctrls.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
index 73d99c3561ce..a565ae3ba7e4 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -1556,7 +1556,8 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
if (ctrl->is_int)
return ptr1.p_s32[idx] == ptr2.p_s32[idx];
idx *= ctrl->elem_size;
- return !memcmp(ptr1.p + idx, ptr2.p + idx, ctrl->elem_size);
+ return !memcmp(ptr1.p_const + idx, ptr2.p_const + idx,
+ ctrl->elem_size);
}
}
@@ -1566,8 +1567,8 @@ static void std_init_compound(const struct v4l2_ctrl *ctrl, u32 idx,
struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
void *p = ptr.p + idx * ctrl->elem_size;
- if (ctrl->p_def.p)
- memcpy(p, ctrl->p_def.p, ctrl->elem_size);
+ if (ctrl->p_def.p_const)
+ memcpy(p, ctrl->p_def.p_const, ctrl->elem_size);
else
memset(p, 0, ctrl->elem_size);
@@ -1954,7 +1955,7 @@ static int ptr_to_user(struct v4l2_ext_control *c,
u32 len;
if (ctrl->is_ptr && !ctrl->is_string)
- return copy_to_user(c->ptr, ptr.p, c->size) ?
+ return copy_to_user(c->ptr, ptr.p_const, c->size) ?
-EFAULT : 0;
switch (ctrl->type) {
@@ -2069,7 +2070,7 @@ static void ptr_to_ptr(struct v4l2_ctrl *ctrl,
{
if (ctrl == NULL)
return;
- memcpy(to.p, from.p, ctrl->elems * ctrl->elem_size);
+ memcpy(to.p, from.p_const, ctrl->elems * ctrl->elem_size);
}
/* Copy the new value to the current value. */
@@ -2587,7 +2588,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
is_array)
sz_extra += 2 * tot_ctrl_size;
- if (type >= V4L2_CTRL_COMPOUND_TYPES && p_def.p)
+ if (type >= V4L2_CTRL_COMPOUND_TYPES && p_def.p_const)
sz_extra += elem_size;
ctrl = kvzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL);
@@ -2634,9 +2635,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
ctrl->p_cur.p = &ctrl->cur.val;
}
- if (type >= V4L2_CTRL_COMPOUND_TYPES && p_def.p) {
+ if (type >= V4L2_CTRL_COMPOUND_TYPES && p_def.p_const) {
ctrl->p_def.p = ctrl->p_cur.p + tot_ctrl_size;
- memcpy(ctrl->p_def.p, p_def.p, elem_size);
+ memcpy(ctrl->p_def.p, p_def.p_const, elem_size);
}
for (idx = 0; idx < elems; idx++) {
--
2.24.0.rc1
prev parent reply other threads:[~2019-11-04 13:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-04 13:09 [PATCH v4 1/6] media: v4l2_ctrl: Add p_def to v4l2_ctrl_config Ricardo Ribalda Delgado
2019-11-04 13:09 ` [PATCH v4 2/6] media: v4l2_ctrl: Add const pointer to ctrl_ptr Ricardo Ribalda Delgado
2019-11-04 13:09 ` [PATCH v4 3/6] media: vivid: Add an area control Ricardo Ribalda Delgado
2019-11-04 13:09 ` [PATCH v4 4/6] media: v4l2_core: Add p_area to struct v4l2_ext_control Ricardo Ribalda Delgado
2019-11-04 13:09 ` [PATCH v4 5/6] Documentation: v42l_core: v4l2_ext_control Ricardo Ribalda Delgado
2019-11-04 13:09 ` Ricardo Ribalda Delgado [this message]
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=20191104130923.22184-6-ribalda@kernel.org \
--to=ribalda@kernel.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox