diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2013-09-26 22:16:24 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2013-09-26 23:49:27 +0200 |
commit | 87f58c2ed885d636229f7209fde883058433a1ce (patch) | |
tree | 92af07c4965a7a60469aa409765019d1e2d18a16 /src | |
parent | c4df9505cb1a6af6c1e7b12246b3d02f9e64597d (diff) |
Print v4l parser position on error
Most parser functions take a **endp argument to indicate the caller
where parsing has stopped. This is currently only used after parsing
something successfully. This patch sets **endp to the erroneous
position in the error case and prints its position after an error
has occured.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/mediactl.c | 4 | ||||
-rw-r--r-- | src/tools.h | 3 | ||||
-rw-r--r-- | src/v4l2subdev.c | 37 |
3 files changed, 33 insertions, 11 deletions
diff --git a/src/mediactl.c b/src/mediactl.c index b22fbdf..57cf86b 100644 --- a/src/mediactl.c +++ b/src/mediactl.c @@ -677,8 +677,8 @@ int media_parse_setup_link(struct media_device *media, return media_setup_link(media, link->source, link->sink, flags); } -static void media_print_streampos(struct media_device *media, const char *p, - const char *end) +void media_print_streampos(struct media_device *media, const char *p, + const char *end) { int pos; diff --git a/src/tools.h b/src/tools.h index de06cb3..e64b37e 100644 --- a/src/tools.h +++ b/src/tools.h @@ -25,5 +25,8 @@ #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) +void media_print_streampos(struct media_device *media, const char *p, + const char *end); + #endif /* __TOOLS_H__ */ diff --git a/src/v4l2subdev.c b/src/v4l2subdev.c index 60655af..2d45d7f 100644 --- a/src/v4l2subdev.c +++ b/src/v4l2subdev.c @@ -277,12 +277,14 @@ static int v4l2_subdev_parse_rectangle(struct media_device *media, if (*p++ != '(') { media_dbg(media, "Expected '('\n"); + *endp = (char *)p - 1; return -EINVAL; } r->left = strtoul(p, &end, 10); if (*end != ',') { media_dbg(media, "Expected ','\n"); + *endp = end; return -EINVAL; } @@ -290,10 +292,12 @@ static int v4l2_subdev_parse_rectangle(struct media_device *media, r->top = strtoul(p, &end, 10); if (*end++ != ')') { media_dbg(media, "Expected ')'\n"); + *endp = end - 1; return -EINVAL; } if (*end != '/') { media_dbg(media, "Expected '/'\n"); + *endp = end; return -EINVAL; } @@ -301,6 +305,7 @@ static int v4l2_subdev_parse_rectangle(struct media_device *media, r->width = strtoul(p, &end, 10); if (*end != 'x') { media_dbg(media, "Expected 'x'\n"); + *endp = end; return -EINVAL; } @@ -324,6 +329,7 @@ static int v4l2_subdev_parse_frame_interval(struct media_device *media, for (p = end; isspace(*p); ++p); if (*p++ != '/') { media_dbg(media, "Expected '/'\n"); + *endp = (char *)p - 1; return -EINVAL; } @@ -363,12 +369,15 @@ static struct media_pad *v4l2_subdev_parse_pad_format( for (; isspace(*p); ++p); pad = media_parse_pad(media, p, &end); - if (pad == NULL) + if (pad == NULL) { + *endp = end; return NULL; + } for (p = end; isspace(*p); ++p); if (*p++ != '[') { media_dbg(media, "Expected '['\n"); + *endp = (char *)p - 1; return NULL; } @@ -380,9 +389,11 @@ static struct media_pad *v4l2_subdev_parse_pad_format( * uppercase later, process it as a format description. */ if (strhazit("fmt:", &p) || (first && isupper(*p))) { - ret = v4l2_subdev_parse_format(format, p, &end); - if (ret < 0) + ret = v4l2_subdev_parse_format(media, format, p, &end); + if (ret < 0) { + *endp = end; return NULL; + } p = end; continue; @@ -393,27 +404,33 @@ static struct media_pad *v4l2_subdev_parse_pad_format( * implicitly without the 'crop:' property name. */ if (strhazit("crop:", &p) || *p == '(') { - ret = v4l2_subdev_parse_rectangle(crop, p, &end); - if (ret < 0) + ret = v4l2_subdev_parse_rectangle(media, crop, p, &end); + if (ret < 0) { + *endp = end; return NULL; + } p = end; continue; } if (strhazit("compose:", &p)) { - ret = v4l2_subdev_parse_rectangle(compose, p, &end); - if (ret < 0) + ret = v4l2_subdev_parse_rectangle(media, compose, p, &end); + if (ret < 0) { + *endp = end; return NULL; + } for (p = end; isspace(*p); p++); continue; } if (*p == '@') { - ret = v4l2_subdev_parse_frame_interval(interval, ++p, &end); - if (ret < 0) + ret = v4l2_subdev_parse_frame_interval(media, interval, ++p, &end); + if (ret < 0) { + *endp = end; return NULL; + } p = end; continue; @@ -424,6 +441,7 @@ static struct media_pad *v4l2_subdev_parse_pad_format( if (*p != ']') { media_dbg(media, "Expected ']'\n"); + *endp = (char *)p; return NULL; } @@ -534,6 +552,7 @@ static int v4l2_subdev_parse_setup_format(struct media_device *media, pad = v4l2_subdev_parse_pad_format(media, &format, &crop, &compose, &interval, p, &end); if (pad == NULL) { + media_print_streampos(media, p, end); media_dbg(media, "Unable to parse format\n"); return -EINVAL; } |