[dpdk-dev] [PATCH 1/1] net/mlx4: add port parameter

Legacy, Allain Allain.Legacy at windriver.com
Fri Mar 10 17:24:32 CET 2017


> -----Original Message-----
> From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Gaetan Rivet
> Sent: Friday, March 03, 2017 10:40 AM
...
> +	errno = 0;
> +	tmp = strtoul(val, NULL, 0);
The robustness of the strtoul() could be improved with something like the following to catch non-integer characters following the port number. 

    char *end = NULL;
    tmp = strtoull(val, &end, 0);
    if ((val[0] == '\0') || (end == NULL) || (*end != '\0') || (errno != 0))


> +	if (errno) {
> +		WARN("%s: \"%s\" is not a valid integer", key, val);
> +		return -errno;
> +	}
> +	if (strcmp(MLX4_PMD_PORT_KVARG, key) == 0) {
> +		if (tmp >= MLX4_PMD_MAX_PHYS_PORTS) {
> +			ERROR("invalid port index %lu (max: %u)",
> +				tmp, MLX4_PMD_MAX_PHYS_PORTS - 1);
> +			return -EINVAL;
> +		}
> +		conf->active_ports |= 1 << tmp;
> +	} else {
> +		WARN("%s: unknown parameter", key);
> +		return -EINVAL;
> +	}
> +	return 0;
> +}
The usage of strtoul() should be moved to be within the strcmp(MLX4_PMD_PORT_KVARG, key) IF statement.  That way the "val" would only be parsed if "key" is "port" and it is expected that "val" is an integer.


> +	if (mlx4_args(pci_dev->device.devargs, &conf)) {
> +		ERROR("failed to process device arguments");
> +		goto error;
> +	}
It would be helpful for debugging if the error message included the devargs so that we can see what is wrong with the input. 


> +	/* Use all ports when none are defined */
> +	if (conf.active_ports == 0) {
> +		for (i = 0; i < MLX4_PMD_MAX_PHYS_PORTS; i++)
> +			conf.active_ports |= 1 << i;
> +	}

Rather than use a loop to populate all active fields would a #define with an all ports mask be better suited to this.  Or alternatively just change the IF statement below to use the following and avoid the need for this loop altogether:

if (conf.active_ports & !(conf.active_ports & (1 << i)))
	continue;




More information about the dev mailing list