[media-ctl] Compare entity name length aswell

Message ID 1335362233-31022-1-git-send-email-saaguirre@ti.com (mailing list archive)
State Not Applicable, archived
Headers

Commit Message

Aguirre Rodriguez, Sergio Alberto April 25, 2012, 1:57 p.m. UTC
  Otherwise, some false positives might arise when
having 2 subdevices with similar names, like:

"OMAP4 ISS ISP IPIPEIF"
"OMAP4 ISS ISP IPIPE"

Before this patch, trying to find "OMAP4 ISS ISP IPIPE", resulted
in a false entity match, retrieving "OMAP4 ISS ISP IPIPEIF"
information instead.

Checking length should ensure such cases are handled well.

Signed-off-by: Sergio Aguirre <saaguirre@ti.com>
---
 src/mediactl.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
  

Comments

Aguirre Rodriguez, Sergio Alberto April 28, 2012, 3:04 p.m. UTC | #1
Hi Laurent

On Wed, Apr 25, 2012 at 8:57 AM, Sergio Aguirre <saaguirre@ti.com> wrote:
> Otherwise, some false positives might arise when
> having 2 subdevices with similar names, like:
>
> "OMAP4 ISS ISP IPIPEIF"
> "OMAP4 ISS ISP IPIPE"
>
> Before this patch, trying to find "OMAP4 ISS ISP IPIPE", resulted
> in a false entity match, retrieving "OMAP4 ISS ISP IPIPEIF"
> information instead.
>
> Checking length should ensure such cases are handled well.

Any feedback about this?

Regards,
Sergio

>
> Signed-off-by: Sergio Aguirre <saaguirre@ti.com>
> ---
>  src/mediactl.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/src/mediactl.c b/src/mediactl.c
> index 5b8c587..451a386 100644
> --- a/src/mediactl.c
> +++ b/src/mediactl.c
> @@ -66,7 +66,8 @@ struct media_entity *media_get_entity_by_name(struct media_device *media,
>        for (i = 0; i < media->entities_count; ++i) {
>                struct media_entity *entity = &media->entities[i];
>
> -               if (strncmp(entity->info.name, name, length) == 0)
> +               if ((strncmp(entity->info.name, name, length) == 0) &&
> +                   (strlen(entity->info.name) == length))
>                        return entity;
>        }
>
> --
> 1.7.5.4
>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  

Patch

diff --git a/src/mediactl.c b/src/mediactl.c
index 5b8c587..451a386 100644
--- a/src/mediactl.c
+++ b/src/mediactl.c
@@ -66,7 +66,8 @@  struct media_entity *media_get_entity_by_name(struct media_device *media,
 	for (i = 0; i < media->entities_count; ++i) {
 		struct media_entity *entity = &media->entities[i];
 
-		if (strncmp(entity->info.name, name, length) == 0)
+		if ((strncmp(entity->info.name, name, length) == 0) &&
+		    (strlen(entity->info.name) == length))
 			return entity;
 	}