* [v4l-utils PATCH 0/2] Prepare for mediatext library, cleanups @ 2016-05-24 12:48 Sakari Ailus 2016-05-24 12:48 ` [v4l-utils PATCH 1/2] libmediactl: Drop length argument from media_get_entity_by_name() Sakari Ailus 2016-05-24 12:48 ` [v4l-utils PATCH 2/2] mediactl: Separate entity and pad parsing Sakari Ailus 0 siblings, 2 replies; 11+ messages in thread From: Sakari Ailus @ 2016-05-24 12:48 UTC (permalink / raw) To: linux-media Hi, These two patches prepare for the mediatext library and clean up libmediactl interface a little. -- Kind regards, Sakari ^ permalink raw reply [flat|nested] 11+ messages in thread
* [v4l-utils PATCH 1/2] libmediactl: Drop length argument from media_get_entity_by_name() 2016-05-24 12:48 [v4l-utils PATCH 0/2] Prepare for mediatext library, cleanups Sakari Ailus @ 2016-05-24 12:48 ` Sakari Ailus 2016-05-24 17:09 ` Laurent Pinchart 2016-05-24 12:48 ` [v4l-utils PATCH 2/2] mediactl: Separate entity and pad parsing Sakari Ailus 1 sibling, 1 reply; 11+ messages in thread From: Sakari Ailus @ 2016-05-24 12:48 UTC (permalink / raw) To: linux-media Recently it was decided that the API dealing with string operations would be better to just receive a nul-terminated string rather than a string the length of which is defined. This change was implemented for v4l2_subdev_string_to_pixelcode() and v4l2_subdev_string_to_field() functions by patch "v4l: libv4l2subdev: Drop length argument from string conversion functions" (commit id 341f4343e6190a7ceb546f7c74fa67e1cc9ae79f). Do the same change for media_get_entity_by_name() in libmediactl. No other functions using length argument for strings remain in libmediactl. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> --- utils/media-ctl/libmediactl.c | 19 +++++++++---------- utils/media-ctl/media-ctl.c | 3 +-- utils/media-ctl/mediactl.h | 3 +-- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/utils/media-ctl/libmediactl.c b/utils/media-ctl/libmediactl.c index 89ac11c..78caa7c 100644 --- a/utils/media-ctl/libmediactl.c +++ b/utils/media-ctl/libmediactl.c @@ -66,21 +66,14 @@ struct media_pad *media_entity_remote_source(struct media_pad *pad) } struct media_entity *media_get_entity_by_name(struct media_device *media, - const char *name, size_t length) + const char *name) { unsigned int i; - /* A match is impossible if the entity name is longer than the maximum - * size we can get from the kernel. - */ - if (length >= FIELD_SIZEOF(struct media_entity_desc, name)) - return NULL; - for (i = 0; i < media->entities_count; ++i) { struct media_entity *entity = &media->entities[i]; - if (strncmp(entity->info.name, name, length) == 0 && - entity->info.name[length] == '\0') + if (strcmp(entity->info.name, name) == 0) return entity; } @@ -804,6 +797,8 @@ struct media_pad *media_parse_pad(struct media_device *media, for (; isspace(*p); ++p); if (*p == '"' || *p == '\'') { + char *name; + for (end = (char *)p + 1; *end && *end != '"' && *end != '\''; ++end); if (*end != '"' && *end != '\'') { media_dbg(media, "missing matching '\"'\n"); @@ -811,7 +806,11 @@ struct media_pad *media_parse_pad(struct media_device *media, return NULL; } - entity = media_get_entity_by_name(media, p + 1, end - p - 1); + name = strndup(p + 1, end - p - 1); + if (!name) + return NULL; + entity = media_get_entity_by_name(media, name); + free(name); if (entity == NULL) { media_dbg(media, "no such entity \"%.*s\"\n", end - p - 1, p + 1); *endp = (char *)p + 1; diff --git a/utils/media-ctl/media-ctl.c b/utils/media-ctl/media-ctl.c index f45ca43..2f049c6 100644 --- a/utils/media-ctl/media-ctl.c +++ b/utils/media-ctl/media-ctl.c @@ -559,8 +559,7 @@ int main(int argc, char **argv) if (media_opts.entity) { struct media_entity *entity; - entity = media_get_entity_by_name(media, media_opts.entity, - strlen(media_opts.entity)); + entity = media_get_entity_by_name(media, media_opts.entity); if (entity == NULL) { printf("Entity '%s' not found\n", media_opts.entity); goto out; diff --git a/utils/media-ctl/mediactl.h b/utils/media-ctl/mediactl.h index 77ac182..b5a92f5 100644 --- a/utils/media-ctl/mediactl.h +++ b/utils/media-ctl/mediactl.h @@ -245,14 +245,13 @@ static inline unsigned int media_entity_type(struct media_entity *entity) * @brief Find an entity by its name. * @param media - media device. * @param name - entity name. - * @param length - size of @a name. * * Search for an entity with a name equal to @a name. * * @return A pointer to the entity if found, or NULL otherwise. */ struct media_entity *media_get_entity_by_name(struct media_device *media, - const char *name, size_t length); + const char *name); /** * @brief Find an entity by its ID. -- 1.9.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [v4l-utils PATCH 1/2] libmediactl: Drop length argument from media_get_entity_by_name() 2016-05-24 12:48 ` [v4l-utils PATCH 1/2] libmediactl: Drop length argument from media_get_entity_by_name() Sakari Ailus @ 2016-05-24 17:09 ` Laurent Pinchart 2016-05-24 20:50 ` Sakari Ailus 0 siblings, 1 reply; 11+ messages in thread From: Laurent Pinchart @ 2016-05-24 17:09 UTC (permalink / raw) To: Sakari Ailus; +Cc: linux-media Hi Sakari, Thank you for the patch. On Tuesday 24 May 2016 15:48:02 Sakari Ailus wrote: > Recently it was decided that the API dealing with string operations would > be better to just receive a nul-terminated string rather than a string the > length of which is defined. This change was implemented for > v4l2_subdev_string_to_pixelcode() and v4l2_subdev_string_to_field() > functions by patch "v4l: libv4l2subdev: Drop length argument from string > conversion functions" (commit id > 341f4343e6190a7ceb546f7c74fa67e1cc9ae79f). > > Do the same change for media_get_entity_by_name() in libmediactl. No other > functions using length argument for strings remain in libmediactl. > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> > --- > utils/media-ctl/libmediactl.c | 19 +++++++++---------- > utils/media-ctl/media-ctl.c | 3 +-- > utils/media-ctl/mediactl.h | 3 +-- > 3 files changed, 11 insertions(+), 14 deletions(-) > > diff --git a/utils/media-ctl/libmediactl.c b/utils/media-ctl/libmediactl.c > index 89ac11c..78caa7c 100644 > --- a/utils/media-ctl/libmediactl.c > +++ b/utils/media-ctl/libmediactl.c > @@ -66,21 +66,14 @@ struct media_pad *media_entity_remote_source(struct > media_pad *pad) } > > struct media_entity *media_get_entity_by_name(struct media_device *media, > - const char *name, size_t length) > + const char *name) > { > unsigned int i; > > - /* A match is impossible if the entity name is longer than the maximum > - * size we can get from the kernel. > - */ > - if (length >= FIELD_SIZEOF(struct media_entity_desc, name)) > - return NULL; > - > for (i = 0; i < media->entities_count; ++i) { > struct media_entity *entity = &media->entities[i]; > > - if (strncmp(entity->info.name, name, length) == 0 && > - entity->info.name[length] == '\0') > + if (strcmp(entity->info.name, name) == 0) While the kernel API guarantees that entity->info.name will be NULL- terminated, wouldn't it be safer to add a safety check here ? > return entity; > } > > @@ -804,6 +797,8 @@ struct media_pad *media_parse_pad(struct media_device > *media, for (; isspace(*p); ++p); > > if (*p == '"' || *p == '\'') { > + char *name; > + > for (end = (char *)p + 1; *end && *end != '"' && *end != '\''; ++end); > if (*end != '"' && *end != '\'') { > media_dbg(media, "missing matching '\"'\n"); > @@ -811,7 +806,11 @@ struct media_pad *media_parse_pad(struct media_device > *media, return NULL; > } > > - entity = media_get_entity_by_name(media, p + 1, end - p - 1); > + name = strndup(p + 1, end - p - 1); > + if (!name) > + return NULL; > + entity = media_get_entity_by_name(media, name); > + free(name); > if (entity == NULL) { > media_dbg(media, "no such entity \"%.*s\"\n", end - p - 1, p + 1); > *endp = (char *)p + 1; > diff --git a/utils/media-ctl/media-ctl.c b/utils/media-ctl/media-ctl.c > index f45ca43..2f049c6 100644 > --- a/utils/media-ctl/media-ctl.c > +++ b/utils/media-ctl/media-ctl.c > @@ -559,8 +559,7 @@ int main(int argc, char **argv) > if (media_opts.entity) { > struct media_entity *entity; > > - entity = media_get_entity_by_name(media, media_opts.entity, > - strlen(media_opts.entity)); > + entity = media_get_entity_by_name(media, media_opts.entity); > if (entity == NULL) { > printf("Entity '%s' not found\n", media_opts.entity); > goto out; > diff --git a/utils/media-ctl/mediactl.h b/utils/media-ctl/mediactl.h > index 77ac182..b5a92f5 100644 > --- a/utils/media-ctl/mediactl.h > +++ b/utils/media-ctl/mediactl.h > @@ -245,14 +245,13 @@ static inline unsigned int media_entity_type(struct > media_entity *entity) * @brief Find an entity by its name. > * @param media - media device. > * @param name - entity name. > - * @param length - size of @a name. > * > * Search for an entity with a name equal to @a name. > * > * @return A pointer to the entity if found, or NULL otherwise. > */ > struct media_entity *media_get_entity_by_name(struct media_device *media, > - const char *name, size_t length); > + const char *name); > > /** > * @brief Find an entity by its ID. -- Regards, Laurent Pinchart ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [v4l-utils PATCH 1/2] libmediactl: Drop length argument from media_get_entity_by_name() 2016-05-24 17:09 ` Laurent Pinchart @ 2016-05-24 20:50 ` Sakari Ailus 2016-05-26 12:07 ` Laurent Pinchart 0 siblings, 1 reply; 11+ messages in thread From: Sakari Ailus @ 2016-05-24 20:50 UTC (permalink / raw) To: Laurent Pinchart; +Cc: Sakari Ailus, linux-media Hi Laurent, Thanks for the review! On Tue, May 24, 2016 at 08:09:37PM +0300, Laurent Pinchart wrote: ... > > + if (strcmp(entity->info.name, name) == 0) > > While the kernel API guarantees that entity->info.name will be NULL- > terminated, wouldn't it be safer to add a safety check here ? The kernel implementation in media-device.c does use strlcpy() so this is even not about drivers doing this right. If you insist, I'll change it. :-) -- Cheers, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [v4l-utils PATCH 1/2] libmediactl: Drop length argument from media_get_entity_by_name() 2016-05-24 20:50 ` Sakari Ailus @ 2016-05-26 12:07 ` Laurent Pinchart 2016-05-26 12:28 ` Sakari Ailus 0 siblings, 1 reply; 11+ messages in thread From: Laurent Pinchart @ 2016-05-26 12:07 UTC (permalink / raw) To: Sakari Ailus; +Cc: Sakari Ailus, linux-media Hi Sakari, On Tuesday 24 May 2016 23:50:44 Sakari Ailus wrote: > On Tue, May 24, 2016 at 08:09:37PM +0300, Laurent Pinchart wrote: > ... > > > > + if (strcmp(entity->info.name, name) == 0) > > > > While the kernel API guarantees that entity->info.name will be NULL- > > terminated, wouldn't it be safer to add a safety check here ? > > The kernel implementation in media-device.c does use strlcpy() so this is > even not about drivers doing this right. If you insist, I'll change it. :-) I suppose we'll have other problems if the kernel doesn't behave. Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> -- Regards, Laurent Pinchart ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [v4l-utils PATCH 1/2] libmediactl: Drop length argument from media_get_entity_by_name() 2016-05-26 12:07 ` Laurent Pinchart @ 2016-05-26 12:28 ` Sakari Ailus 0 siblings, 0 replies; 11+ messages in thread From: Sakari Ailus @ 2016-05-26 12:28 UTC (permalink / raw) To: Laurent Pinchart; +Cc: Sakari Ailus, linux-media On Thu, May 26, 2016 at 03:07:41PM +0300, Laurent Pinchart wrote: > Hi Sakari, > > On Tuesday 24 May 2016 23:50:44 Sakari Ailus wrote: > > On Tue, May 24, 2016 at 08:09:37PM +0300, Laurent Pinchart wrote: > > ... > > > > > > + if (strcmp(entity->info.name, name) == 0) > > > > > > While the kernel API guarantees that entity->info.name will be NULL- > > > terminated, wouldn't it be safer to add a safety check here ? > > > > The kernel implementation in media-device.c does use strlcpy() so this is > > even not about drivers doing this right. If you insist, I'll change it. :-) > > I suppose we'll have other problems if the kernel doesn't behave. > > Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Thanks! I'll then proceed to push the two patches to v4l-utils. -- Kind regards, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 11+ messages in thread
* [v4l-utils PATCH 2/2] mediactl: Separate entity and pad parsing 2016-05-24 12:48 [v4l-utils PATCH 0/2] Prepare for mediatext library, cleanups Sakari Ailus 2016-05-24 12:48 ` [v4l-utils PATCH 1/2] libmediactl: Drop length argument from media_get_entity_by_name() Sakari Ailus @ 2016-05-24 12:48 ` Sakari Ailus 2016-05-24 17:14 ` Laurent Pinchart 1 sibling, 1 reply; 11+ messages in thread From: Sakari Ailus @ 2016-05-24 12:48 UTC (permalink / raw) To: linux-media Sometimes it's useful to be able to parse the entity independent of the pad. Separate entity parsing into media_parse_entity(). Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> --- utils/media-ctl/libmediactl.c | 28 ++++++++++++++++++++++++---- utils/media-ctl/mediactl.h | 14 ++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/utils/media-ctl/libmediactl.c b/utils/media-ctl/libmediactl.c index 78caa7c..14b17e6 100644 --- a/utils/media-ctl/libmediactl.c +++ b/utils/media-ctl/libmediactl.c @@ -781,10 +781,10 @@ int media_device_add_entity(struct media_device *media, return 0; } -struct media_pad *media_parse_pad(struct media_device *media, - const char *p, char **endp) +struct media_entity *media_parse_entity(struct media_device *media, + const char *p, char **endp) { - unsigned int entity_id, pad; + unsigned int entity_id; struct media_entity *entity; char *end; @@ -827,7 +827,27 @@ struct media_pad *media_parse_pad(struct media_device *media, return NULL; } } - for (; isspace(*end); ++end); + for (p = end; isspace(*p); ++p); + + *endp = (char *)p; + + return entity; +} + +struct media_pad *media_parse_pad(struct media_device *media, + const char *p, char **endp) +{ + unsigned int pad; + struct media_entity *entity; + char *end; + + if (endp == NULL) + endp = &end; + + entity = media_parse_entity(media, p, &end); + if (!entity) + return NULL; + *endp = end; if (*end != ':') { media_dbg(media, "Expected ':'\n", *end); diff --git a/utils/media-ctl/mediactl.h b/utils/media-ctl/mediactl.h index b5a92f5..af36051 100644 --- a/utils/media-ctl/mediactl.h +++ b/utils/media-ctl/mediactl.h @@ -367,6 +367,20 @@ int media_setup_link(struct media_device *media, int media_reset_links(struct media_device *media); /** + * @brief Parse string to an entity on the media device. + * @param media - media device. + * @param p - input string + * @param endp - pointer to string where parsing ended + * + * Parse NULL terminated string describing an entity and return its + * struct media_entity instance. + * + * @return Pointer to struct media_entity on success, NULL on failure. + */ +struct media_entity *media_parse_entity(struct media_device *media, + const char *p, char **endp); + +/** * @brief Parse string to a pad on the media device. * @param media - media device. * @param p - input string -- 1.9.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [v4l-utils PATCH 2/2] mediactl: Separate entity and pad parsing 2016-05-24 12:48 ` [v4l-utils PATCH 2/2] mediactl: Separate entity and pad parsing Sakari Ailus @ 2016-05-24 17:14 ` Laurent Pinchart 2016-05-24 20:54 ` Sakari Ailus 2016-05-24 20:56 ` [v4l-utils PATCH v1.1 " Sakari Ailus 0 siblings, 2 replies; 11+ messages in thread From: Laurent Pinchart @ 2016-05-24 17:14 UTC (permalink / raw) To: Sakari Ailus; +Cc: linux-media Hi Sakari, Thank you for the patch. On Tuesday 24 May 2016 15:48:03 Sakari Ailus wrote: > Sometimes it's useful to be able to parse the entity independent of the pad. > Separate entity parsing into media_parse_entity(). > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> > --- > utils/media-ctl/libmediactl.c | 28 ++++++++++++++++++++++++---- > utils/media-ctl/mediactl.h | 14 ++++++++++++++ > 2 files changed, 38 insertions(+), 4 deletions(-) > > diff --git a/utils/media-ctl/libmediactl.c b/utils/media-ctl/libmediactl.c > index 78caa7c..14b17e6 100644 > --- a/utils/media-ctl/libmediactl.c > +++ b/utils/media-ctl/libmediactl.c > @@ -781,10 +781,10 @@ int media_device_add_entity(struct media_device > *media, return 0; > } > > -struct media_pad *media_parse_pad(struct media_device *media, > - const char *p, char **endp) > +struct media_entity *media_parse_entity(struct media_device *media, > + const char *p, char **endp) > { > - unsigned int entity_id, pad; > + unsigned int entity_id; > struct media_entity *entity; > char *end; > > @@ -827,7 +827,27 @@ struct media_pad *media_parse_pad(struct media_device > *media, return NULL; > } > } > - for (; isspace(*end); ++end); > + for (p = end; isspace(*p); ++p); > + > + *endp = (char *)p; > + > + return entity; > +} > + > +struct media_pad *media_parse_pad(struct media_device *media, > + const char *p, char **endp) > +{ > + unsigned int pad; > + struct media_entity *entity; > + char *end; > + > + if (endp == NULL) > + endp = &end; > + > + entity = media_parse_entity(media, p, &end); > + if (!entity) > + return NULL; > + *endp = end; Did you mean if (!entity) { *endp = end; return NULL; } ? There's no need to assign endp after the check as all return paths below assign it correctly, but it should be set when returning an error here. > if (*end != ':') { > media_dbg(media, "Expected ':'\n", *end); > diff --git a/utils/media-ctl/mediactl.h b/utils/media-ctl/mediactl.h > index b5a92f5..af36051 100644 > --- a/utils/media-ctl/mediactl.h > +++ b/utils/media-ctl/mediactl.h > @@ -367,6 +367,20 @@ int media_setup_link(struct media_device *media, > int media_reset_links(struct media_device *media); > > /** > + * @brief Parse string to an entity on the media device. > + * @param media - media device. > + * @param p - input string > + * @param endp - pointer to string where parsing ended > + * > + * Parse NULL terminated string describing an entity and return its > + * struct media_entity instance. > + * > + * @return Pointer to struct media_entity on success, NULL on failure. > + */ > +struct media_entity *media_parse_entity(struct media_device *media, > + const char *p, char **endp); > + > +/** > * @brief Parse string to a pad on the media device. > * @param media - media device. > * @param p - input string -- Regards, Laurent Pinchart ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [v4l-utils PATCH 2/2] mediactl: Separate entity and pad parsing 2016-05-24 17:14 ` Laurent Pinchart @ 2016-05-24 20:54 ` Sakari Ailus 2016-05-24 20:56 ` [v4l-utils PATCH v1.1 " Sakari Ailus 1 sibling, 0 replies; 11+ messages in thread From: Sakari Ailus @ 2016-05-24 20:54 UTC (permalink / raw) To: Laurent Pinchart; +Cc: Sakari Ailus, linux-media Hi Laurent, On Tue, May 24, 2016 at 08:14:22PM +0300, Laurent Pinchart wrote: ... > > +struct media_pad *media_parse_pad(struct media_device *media, > > + const char *p, char **endp) > > +{ > > + unsigned int pad; > > + struct media_entity *entity; > > + char *end; > > + > > + if (endp == NULL) > > + endp = &end; > > + > > + entity = media_parse_entity(media, p, &end); > > + if (!entity) > > + return NULL; > > + *endp = end; > > Did you mean > > if (!entity) { > *endp = end; > return NULL; > } > > ? There's no need to assign endp after the check as all return paths below > assign it correctly, but it should be set when returning an error here. Good catch! Yeah, it's a bug, I'll fix that. -- Cheers, Sakari Ailus e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk ^ permalink raw reply [flat|nested] 11+ messages in thread
* [v4l-utils PATCH v1.1 2/2] mediactl: Separate entity and pad parsing 2016-05-24 17:14 ` Laurent Pinchart 2016-05-24 20:54 ` Sakari Ailus @ 2016-05-24 20:56 ` Sakari Ailus 2016-05-24 22:38 ` Laurent Pinchart 1 sibling, 1 reply; 11+ messages in thread From: Sakari Ailus @ 2016-05-24 20:56 UTC (permalink / raw) To: laurent.pinchart; +Cc: linux-media Sometimes it's useful to be able to parse the entity independent of the pad. Separate entity parsing into media_parse_entity(). Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> --- utils/media-ctl/libmediactl.c | 29 +++++++++++++++++++++++++---- utils/media-ctl/mediactl.h | 14 ++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/utils/media-ctl/libmediactl.c b/utils/media-ctl/libmediactl.c index 78caa7c..498dfd1 100644 --- a/utils/media-ctl/libmediactl.c +++ b/utils/media-ctl/libmediactl.c @@ -781,10 +781,10 @@ int media_device_add_entity(struct media_device *media, return 0; } -struct media_pad *media_parse_pad(struct media_device *media, - const char *p, char **endp) +struct media_entity *media_parse_entity(struct media_device *media, + const char *p, char **endp) { - unsigned int entity_id, pad; + unsigned int entity_id; struct media_entity *entity; char *end; @@ -827,7 +827,28 @@ struct media_pad *media_parse_pad(struct media_device *media, return NULL; } } - for (; isspace(*end); ++end); + for (p = end; isspace(*p); ++p); + + *endp = (char *)p; + + return entity; +} + +struct media_pad *media_parse_pad(struct media_device *media, + const char *p, char **endp) +{ + unsigned int pad; + struct media_entity *entity; + char *end; + + if (endp == NULL) + endp = &end; + + entity = media_parse_entity(media, p, &end); + if (!entity) { + *endp = end; + return NULL; + } if (*end != ':') { media_dbg(media, "Expected ':'\n", *end); diff --git a/utils/media-ctl/mediactl.h b/utils/media-ctl/mediactl.h index b5a92f5..af36051 100644 --- a/utils/media-ctl/mediactl.h +++ b/utils/media-ctl/mediactl.h @@ -367,6 +367,20 @@ int media_setup_link(struct media_device *media, int media_reset_links(struct media_device *media); /** + * @brief Parse string to an entity on the media device. + * @param media - media device. + * @param p - input string + * @param endp - pointer to string where parsing ended + * + * Parse NULL terminated string describing an entity and return its + * struct media_entity instance. + * + * @return Pointer to struct media_entity on success, NULL on failure. + */ +struct media_entity *media_parse_entity(struct media_device *media, + const char *p, char **endp); + +/** * @brief Parse string to a pad on the media device. * @param media - media device. * @param p - input string -- 1.9.1 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [v4l-utils PATCH v1.1 2/2] mediactl: Separate entity and pad parsing 2016-05-24 20:56 ` [v4l-utils PATCH v1.1 " Sakari Ailus @ 2016-05-24 22:38 ` Laurent Pinchart 0 siblings, 0 replies; 11+ messages in thread From: Laurent Pinchart @ 2016-05-24 22:38 UTC (permalink / raw) To: Sakari Ailus; +Cc: linux-media Hi Sakari, Thank you for the patch. On Tuesday 24 May 2016 23:56:33 Sakari Ailus wrote: > Sometimes it's useful to be able to parse the entity independent of the pad. > Separate entity parsing into media_parse_entity(). > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > utils/media-ctl/libmediactl.c | 29 +++++++++++++++++++++++++---- > utils/media-ctl/mediactl.h | 14 ++++++++++++++ > 2 files changed, 39 insertions(+), 4 deletions(-) > > diff --git a/utils/media-ctl/libmediactl.c b/utils/media-ctl/libmediactl.c > index 78caa7c..498dfd1 100644 > --- a/utils/media-ctl/libmediactl.c > +++ b/utils/media-ctl/libmediactl.c > @@ -781,10 +781,10 @@ int media_device_add_entity(struct media_device > *media, return 0; > } > > -struct media_pad *media_parse_pad(struct media_device *media, > - const char *p, char **endp) > +struct media_entity *media_parse_entity(struct media_device *media, > + const char *p, char **endp) > { > - unsigned int entity_id, pad; > + unsigned int entity_id; > struct media_entity *entity; > char *end; > > @@ -827,7 +827,28 @@ struct media_pad *media_parse_pad(struct media_device > *media, return NULL; > } > } > - for (; isspace(*end); ++end); > + for (p = end; isspace(*p); ++p); > + > + *endp = (char *)p; > + > + return entity; > +} > + > +struct media_pad *media_parse_pad(struct media_device *media, > + const char *p, char **endp) > +{ > + unsigned int pad; > + struct media_entity *entity; > + char *end; > + > + if (endp == NULL) > + endp = &end; > + > + entity = media_parse_entity(media, p, &end); > + if (!entity) { > + *endp = end; > + return NULL; > + } > > if (*end != ':') { > media_dbg(media, "Expected ':'\n", *end); > diff --git a/utils/media-ctl/mediactl.h b/utils/media-ctl/mediactl.h > index b5a92f5..af36051 100644 > --- a/utils/media-ctl/mediactl.h > +++ b/utils/media-ctl/mediactl.h > @@ -367,6 +367,20 @@ int media_setup_link(struct media_device *media, > int media_reset_links(struct media_device *media); > > /** > + * @brief Parse string to an entity on the media device. > + * @param media - media device. > + * @param p - input string > + * @param endp - pointer to string where parsing ended > + * > + * Parse NULL terminated string describing an entity and return its > + * struct media_entity instance. > + * > + * @return Pointer to struct media_entity on success, NULL on failure. > + */ > +struct media_entity *media_parse_entity(struct media_device *media, > + const char *p, char **endp); > + > +/** > * @brief Parse string to a pad on the media device. > * @param media - media device. > * @param p - input string -- Regards, Laurent Pinchart ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2016-05-26 12:29 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-05-24 12:48 [v4l-utils PATCH 0/2] Prepare for mediatext library, cleanups Sakari Ailus 2016-05-24 12:48 ` [v4l-utils PATCH 1/2] libmediactl: Drop length argument from media_get_entity_by_name() Sakari Ailus 2016-05-24 17:09 ` Laurent Pinchart 2016-05-24 20:50 ` Sakari Ailus 2016-05-26 12:07 ` Laurent Pinchart 2016-05-26 12:28 ` Sakari Ailus 2016-05-24 12:48 ` [v4l-utils PATCH 2/2] mediactl: Separate entity and pad parsing Sakari Ailus 2016-05-24 17:14 ` Laurent Pinchart 2016-05-24 20:54 ` Sakari Ailus 2016-05-24 20:56 ` [v4l-utils PATCH v1.1 " Sakari Ailus 2016-05-24 22:38 ` Laurent Pinchart
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).