[dpdk-dev] vdev: fix name comparison in find_vdev

Message ID 1520634518-3055-1-git-send-email-nprachan@vyatta.att-mail.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Nachiketa Prachanda March 9, 2018, 10:28 p.m. UTC
  Use strcmp to compare device names as the strncmp in original code
causes find_vdev to return -EEXIST  for names that are prefix
of another. The creation of interfaces fails unpredictably based
on the order of their creation. An easy way hit this bug is to create
eth_vhost1 after eth_vhost11.

Signed-off-by: Nachiketa Prachanda <nprachan@vyatta.att-mail.com>

Fixes: dda987315ca2 ("vdev: make virtual bus use its device struct")
Cc: jblunck@infradead.org
Cc: stable@dpdk.org
---
 drivers/bus/vdev/vdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Jianfeng Tan March 12, 2018, 2:51 a.m. UTC | #1
Hi,


On 3/10/2018 6:28 AM, Nachiketa Prachanda wrote:
> Use strcmp to compare device names as the strncmp in original code
> causes find_vdev to return -EEXIST  for names that are prefix
> of another. The creation of interfaces fails unpredictably based
> on the order of their creation. An easy way hit this bug is to create
> eth_vhost1 after eth_vhost11.
>
> Signed-off-by: Nachiketa Prachanda <nprachan@vyatta.att-mail.com>

Except a nit bellow:

Acked-by: Jianfeng Tan <jianfeng.tan@intel.com>

>
> Fixes: dda987315ca2 ("vdev: make virtual bus use its device struct")
> Cc: jblunck@infradead.org
> Cc: stable@dpdk.org

AFAIK, we usually put above line before Signed-off-by.

> ---
>   drivers/bus/vdev/vdev.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
> index e4bc724..7eae319 100644
> --- a/drivers/bus/vdev/vdev.c
> +++ b/drivers/bus/vdev/vdev.c
> @@ -188,7 +188,7 @@ find_vdev(const char *name)
>   	TAILQ_FOREACH(dev, &vdev_device_list, next) {
>   		const char *devname = rte_vdev_device_name(dev);
>   
> -		if (!strncmp(devname, name, strlen(name)))
> +		if (!strcmp(devname, name))
>   			return dev;
>   	}
>
  

Patch

diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index e4bc724..7eae319 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -188,7 +188,7 @@  find_vdev(const char *name)
 	TAILQ_FOREACH(dev, &vdev_device_list, next) {
 		const char *devname = rte_vdev_device_name(dev);
 
-		if (!strncmp(devname, name, strlen(name)))
+		if (!strcmp(devname, name))
 			return dev;
 	}