* [PATCH v3 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS @ 2019-06-06 16:12 Ezequiel Garcia 2019-06-06 16:12 ` [PATCH v3 2/2] media: v4l2-ctrl: Move compound control initialization Ezequiel Garcia 2019-06-06 17:36 ` [PATCH v3 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Boris Brezillon 0 siblings, 2 replies; 7+ messages in thread From: Ezequiel Garcia @ 2019-06-06 16:12 UTC (permalink / raw) To: linux-media, Hans Verkuil; +Cc: kernel, Boris Brezillon, Ezequiel Garcia These two control types don't really need a default value, as they are not expected to carry any value. However, it's slightly clearer to initialize them explicitly instead of falling back to the switch default. Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> --- Changes from v2: * Initialize the controls to zero, instead of default. Changes from v1: * No change. --- drivers/media/v4l2-core/v4l2-ctrls.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index 1870cecad9ae..92a5521f6813 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -1532,6 +1532,10 @@ 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_BUTTON: + case V4L2_CTRL_TYPE_CTRL_CLASS: + ptr.p_s32[idx] = 0; + break; case V4L2_CTRL_TYPE_U8: ptr.p_u8[idx] = ctrl->default_value; break; -- 2.20.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 2/2] media: v4l2-ctrl: Move compound control initialization 2019-06-06 16:12 [PATCH v3 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Ezequiel Garcia @ 2019-06-06 16:12 ` Ezequiel Garcia 2019-06-06 17:37 ` Boris Brezillon 2019-06-12 13:34 ` Hans Verkuil 2019-06-06 17:36 ` [PATCH v3 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Boris Brezillon 1 sibling, 2 replies; 7+ messages in thread From: Ezequiel Garcia @ 2019-06-06 16:12 UTC (permalink / raw) To: linux-media, Hans Verkuil; +Cc: kernel, Boris Brezillon, Ezequiel Garcia Rework std_init adding an explicit initialization for compound controls. While here, make sure the control is initialized to zero, before providing default values for all its fields. Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> --- Changes from v2: * Align parameters to parenthesis * Drop unneeded zero initialization Changes from v1: * Drop the s/break/return replacements * Drop unneeded default cases * Fix memset to take account of the index --- drivers/media/v4l2-core/v4l2-ctrls.c | 37 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index 92a5521f6813..18c8d0c102d2 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -1506,17 +1506,36 @@ 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_compound(const struct v4l2_ctrl *ctrl, u32 idx, + union v4l2_ctrl_ptr ptr) { struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params; + idx *= ctrl->elem_size; + memset(ptr.p + idx, 0, ctrl->elem_size); + /* * The cast is needed to get rid of a gcc warning complaining that * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the * v4l2_ctrl_type enum. */ switch ((u32)ctrl->type) { + case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS: + p_mpeg2_slice_params = ptr.p; + /* 4:2:0 */ + p_mpeg2_slice_params->sequence.chroma_format = 1; + /* interlaced top field */ + p_mpeg2_slice_params->picture.picture_structure = 1; + p_mpeg2_slice_params->picture.picture_coding_type = + V4L2_MPEG2_PICTURE_CODING_TYPE_I; + break; + } +} + +static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, + union v4l2_ctrl_ptr ptr) +{ + switch (ctrl->type) { case V4L2_CTRL_TYPE_STRING: idx *= ctrl->elem_size; memset(ptr.p_char + idx, ' ', ctrl->minimum); @@ -1545,20 +1564,8 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, case V4L2_CTRL_TYPE_U32: ptr.p_u32[idx] = ctrl->default_value; break; - case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS: - p_mpeg2_slice_params = ptr.p; - /* 4:2:0 */ - p_mpeg2_slice_params->sequence.chroma_format = 1; - /* 8 bits */ - p_mpeg2_slice_params->picture.intra_dc_precision = 0; - /* interlaced top field */ - p_mpeg2_slice_params->picture.picture_structure = 1; - p_mpeg2_slice_params->picture.picture_coding_type = - V4L2_MPEG2_PICTURE_CODING_TYPE_I; - break; default: - idx *= ctrl->elem_size; - memset(ptr.p + idx, 0, ctrl->elem_size); + std_init_compound(ctrl, idx, ptr); break; } } -- 2.20.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] media: v4l2-ctrl: Move compound control initialization 2019-06-06 16:12 ` [PATCH v3 2/2] media: v4l2-ctrl: Move compound control initialization Ezequiel Garcia @ 2019-06-06 17:37 ` Boris Brezillon 2019-06-12 13:34 ` Hans Verkuil 1 sibling, 0 replies; 7+ messages in thread From: Boris Brezillon @ 2019-06-06 17:37 UTC (permalink / raw) To: Ezequiel Garcia; +Cc: linux-media, Hans Verkuil, kernel On Thu, 6 Jun 2019 13:12:54 -0300 Ezequiel Garcia <ezequiel@collabora.com> wrote: > Rework std_init adding an explicit initialization for > compound controls. > > While here, make sure the control is initialized to zero, > before providing default values for all its fields. > > Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> > --- > Changes from v2: > * Align parameters to parenthesis > * Drop unneeded zero initialization > > Changes from v1: > * Drop the s/break/return replacements > * Drop unneeded default cases > * Fix memset to take account of the index > --- > drivers/media/v4l2-core/v4l2-ctrls.c | 37 +++++++++++++++++----------- > 1 file changed, 22 insertions(+), 15 deletions(-) > > diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c > index 92a5521f6813..18c8d0c102d2 100644 > --- a/drivers/media/v4l2-core/v4l2-ctrls.c > +++ b/drivers/media/v4l2-core/v4l2-ctrls.c > @@ -1506,17 +1506,36 @@ 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_compound(const struct v4l2_ctrl *ctrl, u32 idx, > + union v4l2_ctrl_ptr ptr) > { > struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params; > > + idx *= ctrl->elem_size; > + memset(ptr.p + idx, 0, ctrl->elem_size); > + > /* > * The cast is needed to get rid of a gcc warning complaining that > * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the > * v4l2_ctrl_type enum. > */ > switch ((u32)ctrl->type) { > + case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS: > + p_mpeg2_slice_params = ptr.p; > + /* 4:2:0 */ > + p_mpeg2_slice_params->sequence.chroma_format = 1; > + /* interlaced top field */ > + p_mpeg2_slice_params->picture.picture_structure = 1; > + p_mpeg2_slice_params->picture.picture_coding_type = > + V4L2_MPEG2_PICTURE_CODING_TYPE_I; > + break; > + } > +} > + > +static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, > + union v4l2_ctrl_ptr ptr) > +{ > + switch (ctrl->type) { > case V4L2_CTRL_TYPE_STRING: > idx *= ctrl->elem_size; > memset(ptr.p_char + idx, ' ', ctrl->minimum); > @@ -1545,20 +1564,8 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, > case V4L2_CTRL_TYPE_U32: > ptr.p_u32[idx] = ctrl->default_value; > break; > - case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS: > - p_mpeg2_slice_params = ptr.p; > - /* 4:2:0 */ > - p_mpeg2_slice_params->sequence.chroma_format = 1; > - /* 8 bits */ > - p_mpeg2_slice_params->picture.intra_dc_precision = 0; > - /* interlaced top field */ > - p_mpeg2_slice_params->picture.picture_structure = 1; > - p_mpeg2_slice_params->picture.picture_coding_type = > - V4L2_MPEG2_PICTURE_CODING_TYPE_I; > - break; > default: > - idx *= ctrl->elem_size; > - memset(ptr.p + idx, 0, ctrl->elem_size); > + std_init_compound(ctrl, idx, ptr); > break; > } > } ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] media: v4l2-ctrl: Move compound control initialization 2019-06-06 16:12 ` [PATCH v3 2/2] media: v4l2-ctrl: Move compound control initialization Ezequiel Garcia 2019-06-06 17:37 ` Boris Brezillon @ 2019-06-12 13:34 ` Hans Verkuil 2019-06-18 23:17 ` [PATCH v3] " Ezequiel Garcia 1 sibling, 1 reply; 7+ messages in thread From: Hans Verkuil @ 2019-06-12 13:34 UTC (permalink / raw) To: Ezequiel Garcia, linux-media, Hans Verkuil; +Cc: kernel, Boris Brezillon On 6/6/19 6:12 PM, Ezequiel Garcia wrote: > Rework std_init adding an explicit initialization for > compound controls. > > While here, make sure the control is initialized to zero, > before providing default values for all its fields. > > Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> > --- > Changes from v2: > * Align parameters to parenthesis > * Drop unneeded zero initialization > > Changes from v1: > * Drop the s/break/return replacements > * Drop unneeded default cases > * Fix memset to take account of the index > --- > drivers/media/v4l2-core/v4l2-ctrls.c | 37 +++++++++++++++++----------- > 1 file changed, 22 insertions(+), 15 deletions(-) > > diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c > index 92a5521f6813..18c8d0c102d2 100644 > --- a/drivers/media/v4l2-core/v4l2-ctrls.c > +++ b/drivers/media/v4l2-core/v4l2-ctrls.c > @@ -1506,17 +1506,36 @@ 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_compound(const struct v4l2_ctrl *ctrl, u32 idx, > + union v4l2_ctrl_ptr ptr) > { > struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params; > > + idx *= ctrl->elem_size; > + memset(ptr.p + idx, 0, ctrl->elem_size); > + > /* > * The cast is needed to get rid of a gcc warning complaining that > * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the > * v4l2_ctrl_type enum. > */ > switch ((u32)ctrl->type) { > + case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS: > + p_mpeg2_slice_params = ptr.p; This is wrong, it should be ptr.p + idx, just as is done in the memset. I'd add a 'void *p = ptr.p + idx * ctrl->elem_size;' variable at the beginning and use 'p' in the memset and in the line above. Regards, Hans > + /* 4:2:0 */ > + p_mpeg2_slice_params->sequence.chroma_format = 1; > + /* interlaced top field */ > + p_mpeg2_slice_params->picture.picture_structure = 1; > + p_mpeg2_slice_params->picture.picture_coding_type = > + V4L2_MPEG2_PICTURE_CODING_TYPE_I; > + break; > + } > +} > + > +static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, > + union v4l2_ctrl_ptr ptr) > +{ > + switch (ctrl->type) { > case V4L2_CTRL_TYPE_STRING: > idx *= ctrl->elem_size; > memset(ptr.p_char + idx, ' ', ctrl->minimum); > @@ -1545,20 +1564,8 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, > case V4L2_CTRL_TYPE_U32: > ptr.p_u32[idx] = ctrl->default_value; > break; > - case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS: > - p_mpeg2_slice_params = ptr.p; > - /* 4:2:0 */ > - p_mpeg2_slice_params->sequence.chroma_format = 1; > - /* 8 bits */ > - p_mpeg2_slice_params->picture.intra_dc_precision = 0; > - /* interlaced top field */ > - p_mpeg2_slice_params->picture.picture_structure = 1; > - p_mpeg2_slice_params->picture.picture_coding_type = > - V4L2_MPEG2_PICTURE_CODING_TYPE_I; > - break; > default: > - idx *= ctrl->elem_size; > - memset(ptr.p + idx, 0, ctrl->elem_size); > + std_init_compound(ctrl, idx, ptr); > break; > } > } > ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] media: v4l2-ctrl: Move compound control initialization 2019-06-12 13:34 ` Hans Verkuil @ 2019-06-18 23:17 ` Ezequiel Garcia 2019-06-19 12:59 ` Ezequiel Garcia 0 siblings, 1 reply; 7+ messages in thread From: Ezequiel Garcia @ 2019-06-18 23:17 UTC (permalink / raw) To: linux-media, Hans Verkuil; +Cc: kernel, Boris Brezillon, Ezequiel Garcia Rework std_init adding an explicit initialization for compound controls. While here, make sure the control is initialized to zero, before providing default values for all its fields. Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> --- Changes from v2: * Fix missing index usage Changes from v2: * Align parameters to parenthesis * Drop unneeded zero initialization Changes from v1: * Drop the s/break/return replacements * Drop unneeded default cases * Fix memset to take account of the index --- drivers/media/v4l2-core/v4l2-ctrls.c | 37 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index 915187a8ca5c..b04e66d1500a 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -1502,10 +1502,13 @@ 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_compound(const struct v4l2_ctrl *ctrl, u32 idx, + union v4l2_ctrl_ptr ptr) { struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params; + void *p = ptr.p + idx * ctrl->elem_size; + + memset(p, 0, ctrl->elem_size); /* * The cast is needed to get rid of a gcc warning complaining that @@ -1513,6 +1516,22 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, * v4l2_ctrl_type enum. */ switch ((u32)ctrl->type) { + case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS: + p_mpeg2_slice_params = p; + /* 4:2:0 */ + p_mpeg2_slice_params->sequence.chroma_format = 1; + /* interlaced top field */ + p_mpeg2_slice_params->picture.picture_structure = 1; + p_mpeg2_slice_params->picture.picture_coding_type = + V4L2_MPEG2_PICTURE_CODING_TYPE_I; + break; + } +} + +static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, + union v4l2_ctrl_ptr ptr) +{ + switch (ctrl->type) { case V4L2_CTRL_TYPE_STRING: idx *= ctrl->elem_size; memset(ptr.p_char + idx, ' ', ctrl->minimum); @@ -1541,20 +1560,8 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, case V4L2_CTRL_TYPE_U32: ptr.p_u32[idx] = ctrl->default_value; break; - case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS: - p_mpeg2_slice_params = ptr.p; - /* 4:2:0 */ - p_mpeg2_slice_params->sequence.chroma_format = 1; - /* 8 bits */ - p_mpeg2_slice_params->picture.intra_dc_precision = 0; - /* interlaced top field */ - p_mpeg2_slice_params->picture.picture_structure = 1; - p_mpeg2_slice_params->picture.picture_coding_type = - V4L2_MPEG2_PICTURE_CODING_TYPE_I; - break; default: - idx *= ctrl->elem_size; - memset(ptr.p + idx, 0, ctrl->elem_size); + std_init_compound(ctrl, idx, ptr); break; } } -- 2.20.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3] media: v4l2-ctrl: Move compound control initialization 2019-06-18 23:17 ` [PATCH v3] " Ezequiel Garcia @ 2019-06-19 12:59 ` Ezequiel Garcia 0 siblings, 0 replies; 7+ messages in thread From: Ezequiel Garcia @ 2019-06-19 12:59 UTC (permalink / raw) To: linux-media, Hans Verkuil; +Cc: kernel, Boris Brezillon On Tue, 2019-06-18 at 20:17 -0300, Ezequiel Garcia wrote: > Rework std_init adding an explicit initialization for > compound controls. > > While here, make sure the control is initialized to zero, > before providing default values for all its fields. > > Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> > Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> > --- > Changes from v2: > * Fix missing index usage > Erratum, should be "Changes from v3" since this is v4 patch. Thanks, Ezequiel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS 2019-06-06 16:12 [PATCH v3 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Ezequiel Garcia 2019-06-06 16:12 ` [PATCH v3 2/2] media: v4l2-ctrl: Move compound control initialization Ezequiel Garcia @ 2019-06-06 17:36 ` Boris Brezillon 1 sibling, 0 replies; 7+ messages in thread From: Boris Brezillon @ 2019-06-06 17:36 UTC (permalink / raw) To: Ezequiel Garcia; +Cc: linux-media, Hans Verkuil, kernel On Thu, 6 Jun 2019 13:12:53 -0300 Ezequiel Garcia <ezequiel@collabora.com> wrote: > These two control types don't really need a default value, > as they are not expected to carry any value. > > However, it's slightly clearer to initialize them explicitly > instead of falling back to the switch default. > > Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> > --- > Changes from v2: > * Initialize the controls to zero, instead of default. > > Changes from v1: > * No change. > --- > drivers/media/v4l2-core/v4l2-ctrls.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c > index 1870cecad9ae..92a5521f6813 100644 > --- a/drivers/media/v4l2-core/v4l2-ctrls.c > +++ b/drivers/media/v4l2-core/v4l2-ctrls.c > @@ -1532,6 +1532,10 @@ 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_BUTTON: > + case V4L2_CTRL_TYPE_CTRL_CLASS: > + ptr.p_s32[idx] = 0; > + break; > case V4L2_CTRL_TYPE_U8: > ptr.p_u8[idx] = ctrl->default_value; > break; ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-06-19 12:59 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-06-06 16:12 [PATCH v3 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Ezequiel Garcia 2019-06-06 16:12 ` [PATCH v3 2/2] media: v4l2-ctrl: Move compound control initialization Ezequiel Garcia 2019-06-06 17:37 ` Boris Brezillon 2019-06-12 13:34 ` Hans Verkuil 2019-06-18 23:17 ` [PATCH v3] " Ezequiel Garcia 2019-06-19 12:59 ` Ezequiel Garcia 2019-06-06 17:36 ` [PATCH v3 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Boris Brezillon
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).