* [PATCH v2 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS @ 2019-05-30 17:19 Ezequiel Garcia 2019-05-30 17:19 ` [PATCH v2 2/2] media: v4l2-ctrl: Move compound control initialization Ezequiel Garcia 2019-06-01 9:05 ` [PATCH v2 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Boris Brezillon 0 siblings, 2 replies; 6+ messages in thread From: Ezequiel Garcia @ 2019-05-30 17:19 UTC (permalink / raw) To: linux-media, Hans Verkuil Cc: kernel, Nicolas Dufresne, 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> --- drivers/media/v4l2-core/v4l2-ctrls.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index 1870cecad9ae..c7d5fdb8efb4 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -1530,6 +1530,8 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, case V4L2_CTRL_TYPE_MENU: case V4L2_CTRL_TYPE_BITMASK: case V4L2_CTRL_TYPE_BOOLEAN: + case V4L2_CTRL_TYPE_BUTTON: + case V4L2_CTRL_TYPE_CTRL_CLASS: ptr.p_s32[idx] = ctrl->default_value; break; case V4L2_CTRL_TYPE_U8: -- 2.20.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] media: v4l2-ctrl: Move compound control initialization 2019-05-30 17:19 [PATCH v2 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Ezequiel Garcia @ 2019-05-30 17:19 ` Ezequiel Garcia 2019-06-01 9:02 ` Boris Brezillon 2019-06-05 10:45 ` Hans Verkuil 2019-06-01 9:05 ` [PATCH v2 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Boris Brezillon 1 sibling, 2 replies; 6+ messages in thread From: Ezequiel Garcia @ 2019-05-30 17:19 UTC (permalink / raw) To: linux-media, Hans Verkuil Cc: kernel, Nicolas Dufresne, 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 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, 23 insertions(+), 14 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index c7d5fdb8efb4..ebaff951ec87 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -1506,17 +1506,38 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx, } } -static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, +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; + /* 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; + } +} + +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); @@ -1543,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] 6+ messages in thread
* Re: [PATCH v2 2/2] media: v4l2-ctrl: Move compound control initialization 2019-05-30 17:19 ` [PATCH v2 2/2] media: v4l2-ctrl: Move compound control initialization Ezequiel Garcia @ 2019-06-01 9:02 ` Boris Brezillon 2019-06-05 10:45 ` Hans Verkuil 1 sibling, 0 replies; 6+ messages in thread From: Boris Brezillon @ 2019-06-01 9:02 UTC (permalink / raw) To: Ezequiel Garcia; +Cc: linux-media, Hans Verkuil, kernel, Nicolas Dufresne On Thu, 30 May 2019 14:19:09 -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> > -- > 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, 23 insertions(+), 14 deletions(-) > > diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c > index c7d5fdb8efb4..ebaff951ec87 100644 > --- a/drivers/media/v4l2-core/v4l2-ctrls.c > +++ b/drivers/media/v4l2-core/v4l2-ctrls.c > @@ -1506,17 +1506,38 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx, > } > } > > -static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, > +static void std_init_compound(const struct v4l2_ctrl *ctrl, u32 idx, > union v4l2_ctrl_ptr ptr) nit: union v4l2_ctrl_ptr is not aligned on the std_init_compound() open parens. The patch looks good otherwise: Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> > { > 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; > + /* 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; > + } > +} > + > +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); > @@ -1543,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] 6+ messages in thread
* Re: [PATCH v2 2/2] media: v4l2-ctrl: Move compound control initialization 2019-05-30 17:19 ` [PATCH v2 2/2] media: v4l2-ctrl: Move compound control initialization Ezequiel Garcia 2019-06-01 9:02 ` Boris Brezillon @ 2019-06-05 10:45 ` Hans Verkuil 1 sibling, 0 replies; 6+ messages in thread From: Hans Verkuil @ 2019-06-05 10:45 UTC (permalink / raw) To: Ezequiel Garcia, linux-media, Hans Verkuil Cc: kernel, Nicolas Dufresne, Boris Brezillon On 5/30/19 7:19 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 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, 23 insertions(+), 14 deletions(-) > > diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c > index c7d5fdb8efb4..ebaff951ec87 100644 > --- a/drivers/media/v4l2-core/v4l2-ctrls.c > +++ b/drivers/media/v4l2-core/v4l2-ctrls.c > @@ -1506,17 +1506,38 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx, > } > } > > -static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, > +static void std_init_compound(const struct v4l2_ctrl *ctrl, u32 idx, > union v4l2_ctrl_ptr ptr) As Boris mentioned, fix the alignment with the open (. > { > 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; > + /* 8 bits */ > + p_mpeg2_slice_params->picture.intra_dc_precision = 0; I'd drop this assignment. Everything is already zeroed, so why still do this? Regards, Hans > + /* 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); > @@ -1543,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] 6+ messages in thread
* Re: [PATCH v2 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS 2019-05-30 17:19 [PATCH v2 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Ezequiel Garcia 2019-05-30 17:19 ` [PATCH v2 2/2] media: v4l2-ctrl: Move compound control initialization Ezequiel Garcia @ 2019-06-01 9:05 ` Boris Brezillon 2019-06-05 10:44 ` Hans Verkuil 1 sibling, 1 reply; 6+ messages in thread From: Boris Brezillon @ 2019-06-01 9:05 UTC (permalink / raw) To: Ezequiel Garcia; +Cc: linux-media, Hans Verkuil, kernel, Nicolas Dufresne On Thu, 30 May 2019 14:19:08 -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. If they don't carry any value, why not having a case that does nothing? I find it disturbing to assign a default to something that does not have a value attached to it. > > Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> > --- > drivers/media/v4l2-core/v4l2-ctrls.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c > index 1870cecad9ae..c7d5fdb8efb4 100644 > --- a/drivers/media/v4l2-core/v4l2-ctrls.c > +++ b/drivers/media/v4l2-core/v4l2-ctrls.c > @@ -1530,6 +1530,8 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, > case V4L2_CTRL_TYPE_MENU: > case V4L2_CTRL_TYPE_BITMASK: > case V4L2_CTRL_TYPE_BOOLEAN: > + case V4L2_CTRL_TYPE_BUTTON: > + case V4L2_CTRL_TYPE_CTRL_CLASS: > ptr.p_s32[idx] = ctrl->default_value; > break; > case V4L2_CTRL_TYPE_U8: ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS 2019-06-01 9:05 ` [PATCH v2 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Boris Brezillon @ 2019-06-05 10:44 ` Hans Verkuil 0 siblings, 0 replies; 6+ messages in thread From: Hans Verkuil @ 2019-06-05 10:44 UTC (permalink / raw) To: Boris Brezillon, Ezequiel Garcia Cc: linux-media, Hans Verkuil, kernel, Nicolas Dufresne On 6/1/19 11:05 AM, Boris Brezillon wrote: > On Thu, 30 May 2019 14:19:08 -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. > > If they don't carry any value, why not having a case that does nothing? > I find it disturbing to assign a default to something that does not > have a value attached to it. I agree to a point. It is still good to initialize these, if only to make sure that there is a sane value in the control. How about this: 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; Regards, Hans > >> >> Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> >> --- >> drivers/media/v4l2-core/v4l2-ctrls.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c >> index 1870cecad9ae..c7d5fdb8efb4 100644 >> --- a/drivers/media/v4l2-core/v4l2-ctrls.c >> +++ b/drivers/media/v4l2-core/v4l2-ctrls.c >> @@ -1530,6 +1530,8 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, >> case V4L2_CTRL_TYPE_MENU: >> case V4L2_CTRL_TYPE_BITMASK: >> case V4L2_CTRL_TYPE_BOOLEAN: >> + case V4L2_CTRL_TYPE_BUTTON: >> + case V4L2_CTRL_TYPE_CTRL_CLASS: >> ptr.p_s32[idx] = ctrl->default_value; >> break; >> case V4L2_CTRL_TYPE_U8: > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-06-05 10:45 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-05-30 17:19 [PATCH v2 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Ezequiel Garcia 2019-05-30 17:19 ` [PATCH v2 2/2] media: v4l2-ctrl: Move compound control initialization Ezequiel Garcia 2019-06-01 9:02 ` Boris Brezillon 2019-06-05 10:45 ` Hans Verkuil 2019-06-01 9:05 ` [PATCH v2 1/2] media: v4l2-ctrl: Initialize _BUTTON and _CTRL_CLASS Boris Brezillon 2019-06-05 10:44 ` Hans Verkuil
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.