diff mbox

[dpdk-dev,v3,13/28] eal/pci: Prevent double registration for devargs_list

Message ID 1418106629-22227-14-git-send-email-mukawa@igel.co.jp (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Tetsuya Mukawa Dec. 9, 2014, 6:30 a.m. UTC
The patch fixes rte_eal_devargs_add() not to register same device twice.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/common/eal_common_devargs.c | 35 ++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

Comments

Michael Qiu Dec. 9, 2014, 2:55 p.m. UTC | #1
On 2014/12/9 14:33, Tetsuya Mukawa wrote:
> The patch fixes rte_eal_devargs_add() not to register same device twice.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
>  lib/librte_eal/common/eal_common_devargs.c | 35 ++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>
> diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
> index 4c7d11a..f95a12d 100644
> --- a/lib/librte_eal/common/eal_common_devargs.c
> +++ b/lib/librte_eal/common/eal_common_devargs.c
> @@ -44,6 +44,35 @@
>  struct rte_devargs_list devargs_list =
>  	TAILQ_HEAD_INITIALIZER(devargs_list);
>  
> +
> +/* find a entry specified by pci address or device name */
> +static struct rte_devargs *
> +rte_eal_devargs_find(enum rte_devtype devtype, void *args)
> +{
> +	struct rte_devargs *devargs;
> +
> +	if (args == NULL)
> +		return NULL;
> +
> +	TAILQ_FOREACH(devargs, &devargs_list, next) {
> +		switch (devtype) {
> +		case RTE_DEVTYPE_WHITELISTED_PCI:
> +		case RTE_DEVTYPE_BLACKLISTED_PCI:
> +			if (eal_compare_pci_addr(&devargs->pci.addr, args) == 0)
> +				goto found;
> +			break;
> +		case RTE_DEVTYPE_VIRTUAL:
> +			if (memcmp(&devargs->virtual.drv_name, args,
> +					strlen((char *)args)) == 0)
> +				goto found;
> +			break;
> +		}
> +	}
> +	return NULL;
> +found:
> +	return devargs;
> +}
> +
>  /* store a whitelist parameter for later parsing */
>  int
>  rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
> @@ -101,6 +130,12 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
>  		break;
>  	}
>  
> +	/* make sure there is no same entry */
> +	if (rte_eal_devargs_find(devtype, &devargs->pci.addr)) {

Am I miss something? If devtype == RTE_DEVTYPE_VIRTUAL, what will happen?

Thanks,
Michael
> +		RTE_LOG(ERR, EAL, "device already registered: <%s>\n", buf);
> +		return -1;
> +	}
> +
>  	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
>  	return 0;
>  }
Tetsuya Mukawa Dec. 11, 2014, 4:57 a.m. UTC | #2
Hi Michael,

(2014/12/09 23:55), Qiu, Michael wrote:
> On 2014/12/9 14:33, Tetsuya Mukawa wrote:
>> The patch fixes rte_eal_devargs_add() not to register same device twice.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>>  lib/librte_eal/common/eal_common_devargs.c | 35 ++++++++++++++++++++++++++++++
>>  1 file changed, 35 insertions(+)
>>
>> diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
>> index 4c7d11a..f95a12d 100644
>> --- a/lib/librte_eal/common/eal_common_devargs.c
>> +++ b/lib/librte_eal/common/eal_common_devargs.c
>> @@ -44,6 +44,35 @@
>>  struct rte_devargs_list devargs_list =
>>  	TAILQ_HEAD_INITIALIZER(devargs_list);
>>  
>> +
>> +/* find a entry specified by pci address or device name */
>> +static struct rte_devargs *
>> +rte_eal_devargs_find(enum rte_devtype devtype, void *args)
>> +{
>> +	struct rte_devargs *devargs;
>> +
>> +	if (args == NULL)
>> +		return NULL;
>> +
>> +	TAILQ_FOREACH(devargs, &devargs_list, next) {
>> +		switch (devtype) {
>> +		case RTE_DEVTYPE_WHITELISTED_PCI:
>> +		case RTE_DEVTYPE_BLACKLISTED_PCI:
>> +			if (eal_compare_pci_addr(&devargs->pci.addr, args) == 0)
>> +				goto found;
>> +			break;
>> +		case RTE_DEVTYPE_VIRTUAL:
>> +			if (memcmp(&devargs->virtual.drv_name, args,
>> +					strlen((char *)args)) == 0)
>> +				goto found;
>> +			break;
>> +		}
>> +	}
>> +	return NULL;
>> +found:
>> +	return devargs;
>> +}
>> +
>>  /* store a whitelist parameter for later parsing */
>>  int
>>  rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
>> @@ -101,6 +130,12 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
>>  		break;
>>  	}
>>  
>> +	/* make sure there is no same entry */
>> +	if (rte_eal_devargs_find(devtype, &devargs->pci.addr)) {
> Am I miss something? If devtype == RTE_DEVTYPE_VIRTUAL, what will happen?

This will be issues.
When I implement, I guess devargs->pci.addr and
devargs->virtual.drv_name will have same address, because they are
accessed as union.
But it's rough coding and will have issue with some compilers. I will
change it.

Thanks,
Tetsuya

> Thanks,
> Michael
>> +		RTE_LOG(ERR, EAL, "device already registered: <%s>\n", buf);
>> +		return -1;
>> +	}
>> +
>>  	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
>>  	return 0;
>>  }
diff mbox

Patch

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index 4c7d11a..f95a12d 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -44,6 +44,35 @@ 
 struct rte_devargs_list devargs_list =
 	TAILQ_HEAD_INITIALIZER(devargs_list);
 
+
+/* find a entry specified by pci address or device name */
+static struct rte_devargs *
+rte_eal_devargs_find(enum rte_devtype devtype, void *args)
+{
+	struct rte_devargs *devargs;
+
+	if (args == NULL)
+		return NULL;
+
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+		switch (devtype) {
+		case RTE_DEVTYPE_WHITELISTED_PCI:
+		case RTE_DEVTYPE_BLACKLISTED_PCI:
+			if (eal_compare_pci_addr(&devargs->pci.addr, args) == 0)
+				goto found;
+			break;
+		case RTE_DEVTYPE_VIRTUAL:
+			if (memcmp(&devargs->virtual.drv_name, args,
+					strlen((char *)args)) == 0)
+				goto found;
+			break;
+		}
+	}
+	return NULL;
+found:
+	return devargs;
+}
+
 /* store a whitelist parameter for later parsing */
 int
 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
@@ -101,6 +130,12 @@  rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 		break;
 	}
 
+	/* make sure there is no same entry */
+	if (rte_eal_devargs_find(devtype, &devargs->pci.addr)) {
+		RTE_LOG(ERR, EAL, "device already registered: <%s>\n", buf);
+		return -1;
+	}
+
 	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
 	return 0;
 }