Skip to contentSkip to conversation

v4l: libv4l2subdev: Precisely convert media bus string to code

PATCH In review Sakari Ailus 2 participants 2 messages Jan 25, 2016 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 v4l: libv4l2subdev: Precisely convert media bus string to code

Any character beyond the fist `length' characters in the mbus_formats strings are ignored, causing incorrect matches if the format entry starts with but isn't equal to the passed format.

---
since v1:
- Use mbus_formats[i].name[length] == '\0' instead of comparing strlen() result.

 utils/media-ctl/libv4l2subdev.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
utils/media-ctl/libv4l2subdev.c +4 -6
index 33c1ee6..dc2cd87 100644
@@ -769,14 +769,12 @@ enum v4l2_mbus_pixelcode v4l2_subdev_string_to_pixelcode(const char *string,
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(mbus_formats); ++i) {
-		if (strncmp(mbus_formats[i].name, string, length) == 0)
-			break;
+		if (strncmp(mbus_formats[i].name, string, length) == 0
+		    && mbus_formats[i].name[length] == '\0')
+			return mbus_formats[i].code;
 	}
 
-	if (i == ARRAY_SIZE(mbus_formats))
-		return (enum v4l2_mbus_pixelcode)-1;
-
-	return mbus_formats[i].code;
+	return (enum v4l2_mbus_pixelcode)-1;
 }
 
 static struct {
Signature · 1 line
2.1.0.231.g7484e3b
Reviewed-by on v2 1/1
#1 lore raw

Hi Sakari,

Thank you for the patch.

Quoted 5 lines · On Monday 25 January 2016 14:35:06 Sakari Ailus wrote:

Any character beyond the fist `length' characters in the mbus_formats strings are ignored, causing incorrect matches if the format entry starts with but isn't equal to the passed format.

Quoted 31 lines

---
since v1:
- Use mbus_formats[i].name[length] == '\0' instead of comparing strlen() result.

 utils/media-ctl/libv4l2subdev.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/utils/media-ctl/libv4l2subdev.c index 33c1ee6..dc2cd87 100644

utils/media-ctl/libv4l2subdev.c +4 -6
@@ -769,14 +769,12 @@ enum v4l2_mbus_pixelcode
 v4l2_subdev_string_to_pixelcode(const char *string, unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(mbus_formats); ++i) {
-		if (strncmp(mbus_formats[i].name, string, length) == 0)
-			break;
+		if (strncmp(mbus_formats[i].name, string, length) == 0
+		    && mbus_formats[i].name[length] == '\0')
+			return mbus_formats[i].code;
 	}
 
-	if (i == ARRAY_SIZE(mbus_formats))
-		return (enum v4l2_mbus_pixelcode)-1;
-
-	return mbus_formats[i].code;
+	return (enum v4l2_mbus_pixelcode)-1;
 }
 
 static struct {
Signature · 3 lines
Regards,

Laurent Pinchart