diff mbox series

[7/8] v4l2-utils: turn mbus_names into const vector

Message ID 20210421072035.4188497-7-rosenp@gmail.com
State New
Headers show
Series [1/8] clang-tidy: use auto | expand

Commit Message

Rosen Penev April 21, 2021, 7:20 a.m. UTC
Allows usage of a more standard for loop.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 utils/v4l2-ctl/v4l2-ctl-subdev.cpp | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Comments

Rosen Penev April 21, 2021, 9:25 a.m. UTC | #1
> On Apr 21, 2021, at 01:02, Hans Verkuil <hverkuil@xs4all.nl> wrote:
> 
>> On 21/04/2021 09:20, Rosen Penev wrote:
>> Allows usage of a more standard for loop.
>> 
>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>> ---
>> utils/v4l2-ctl/v4l2-ctl-subdev.cpp | 16 ++++++++--------
>> 1 file changed, 8 insertions(+), 8 deletions(-)
>> 
>> diff --git a/utils/v4l2-ctl/v4l2-ctl-subdev.cpp b/utils/v4l2-ctl/v4l2-ctl-subdev.cpp
>> index d0f391bba..f2be9442c 100644
>> --- a/utils/v4l2-ctl/v4l2-ctl-subdev.cpp
>> +++ b/utils/v4l2-ctl/v4l2-ctl-subdev.cpp
>> @@ -1,3 +1,5 @@
>> +#include <vector>
>> +
>> #include "v4l2-ctl.h"
>> 
>> struct mbus_name {
>> @@ -5,10 +7,9 @@ struct mbus_name {
>>    __u32 code;
>> };
>> 
>> -static struct mbus_name mbus_names[] = {
>> +static const std::vector<mbus_name> mbus_names{
>>    { "Fixed", MEDIA_BUS_FMT_FIXED },
>> #include "media-bus-format-names.h"
>> -    { nullptr, 0 }
>> };
> 
> I see no reason for this change, there is nothing wrong with the
> current array that I can see (other than that it should have been
> const, but I'll add that).
I used vector since it’s not easy to see the size.
> 
>> 
>> /* selection specified */
>> @@ -343,9 +344,9 @@ static void print_framefmt(const struct v4l2_mbus_framefmt &fmt)
>> {
>>    __u32 colsp = fmt.colorspace;
>>    __u32 ycbcr_enc = fmt.ycbcr_enc;
>> -    unsigned int i;
>> +    size_t i;
>> 
>> -    for (i = 0; mbus_names[i].name; i++)
>> +    for (i = 0; i < mbus_names.size(); i++)
>>        if (mbus_names[i].code == fmt.code)
>>            break;
>>    printf("\tWidth/Height      : %u/%u\n", fmt.width, fmt.height);
>> @@ -554,9 +555,9 @@ void subdev_get(cv4l_fd &_fd)
>> 
>> static void print_mbus_code(__u32 code)
>> {
>> -    unsigned int i;
>> +    size_t i;
>> 
>> -    for (i = 0; mbus_names[i].name; i++)
>> +    for (i = 0; i < mbus_names.size(); i++)
>>        if (mbus_names[i].code == code)
>>            break;
>>    if (mbus_names[i].name)
>> @@ -568,9 +569,8 @@ static void print_mbus_code(__u32 code)
>> 
>> static void print_mbus_codes(int fd, __u32 pad)
>> {
>> -    struct v4l2_subdev_mbus_code_enum mbus_code;
>> +    struct v4l2_subdev_mbus_code_enum mbus_code = {};
>> 
>> -    memset(&mbus_code, 0, sizeof(mbus_code));
> 
> This one is nice to have, though. But it's independent of the other
> changes.
Noticed it as I was passing by :).
> 
> Regards,
> 
>    Hans
> 
> 
>>    mbus_code.pad = pad;
>>    mbus_code.which = V4L2_SUBDEV_FORMAT_TRY;
>> 
>> 
>
diff mbox series

Patch

diff --git a/utils/v4l2-ctl/v4l2-ctl-subdev.cpp b/utils/v4l2-ctl/v4l2-ctl-subdev.cpp
index d0f391bba..f2be9442c 100644
--- a/utils/v4l2-ctl/v4l2-ctl-subdev.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-subdev.cpp
@@ -1,3 +1,5 @@ 
+#include <vector>
+
 #include "v4l2-ctl.h"
 
 struct mbus_name {
@@ -5,10 +7,9 @@  struct mbus_name {
 	__u32 code;
 };
 
-static struct mbus_name mbus_names[] = {
+static const std::vector<mbus_name> mbus_names{
 	{ "Fixed", MEDIA_BUS_FMT_FIXED },
 #include "media-bus-format-names.h"
-	{ nullptr, 0 }
 };
 
 /* selection specified */
@@ -343,9 +344,9 @@  static void print_framefmt(const struct v4l2_mbus_framefmt &fmt)
 {
 	__u32 colsp = fmt.colorspace;
 	__u32 ycbcr_enc = fmt.ycbcr_enc;
-	unsigned int i;
+	size_t i;
 
-	for (i = 0; mbus_names[i].name; i++)
+	for (i = 0; i < mbus_names.size(); i++)
 		if (mbus_names[i].code == fmt.code)
 			break;
 	printf("\tWidth/Height      : %u/%u\n", fmt.width, fmt.height);
@@ -554,9 +555,9 @@  void subdev_get(cv4l_fd &_fd)
 
 static void print_mbus_code(__u32 code)
 {
-	unsigned int i;
+	size_t i;
 
-	for (i = 0; mbus_names[i].name; i++)
+	for (i = 0; i < mbus_names.size(); i++)
 		if (mbus_names[i].code == code)
 			break;
 	if (mbus_names[i].name)
@@ -568,9 +569,8 @@  static void print_mbus_code(__u32 code)
 
 static void print_mbus_codes(int fd, __u32 pad)
 {
-	struct v4l2_subdev_mbus_code_enum mbus_code;
+	struct v4l2_subdev_mbus_code_enum mbus_code = {};
 
-	memset(&mbus_code, 0, sizeof(mbus_code));
 	mbus_code.pad = pad;
 	mbus_code.which = V4L2_SUBDEV_FORMAT_TRY;