DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Legacy, Allain" <Allain.Legacy@windriver.com>
To: Gaetan Rivet <gaetan.rivet@6wind.com>, "dev@dpdk.org" <dev@dpdk.org>
Cc: Adrien Mazarguil <adrien.mazarguil@6wind.com>,
	Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
Subject: Re: [dpdk-dev] [PATCH 1/1] net/mlx4: add port parameter
Date: Fri, 10 Mar 2017 16:24:32 +0000	[thread overview]
Message-ID: <70A7408C6E1BFB41B192A929744D8523968EC82E@ALA-MBC.corp.ad.wrs.com> (raw)
In-Reply-To: <f49bbc965816575b851b22ba3cbcd657a847d9b2.1488550887.git.gaetan.rivet@6wind.com>

> -----Original Message-----
> From: dev [mailto:dev-bounces@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;

  reply	other threads:[~2017-03-10 16:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-03 15:40 Gaetan Rivet
2017-03-10 16:24 ` Legacy, Allain [this message]
2017-03-10 16:34   ` Stephen Hemminger
2017-03-10 17:11   ` Gaëtan Rivet
2017-03-10 17:49     ` Gaëtan Rivet
2017-03-11 11:32     ` Legacy, Allain
2017-03-16 11:04 ` Adrien Mazarguil
2017-03-20 13:24   ` Ferruh Yigit
2017-03-20 13:56     ` Adrien Mazarguil
2017-03-27 15:08 ` Ferruh Yigit
2017-03-27 15:46   ` Gaëtan Rivet
2017-03-27 15:41 ` [dpdk-dev] [PATCH v2 " Gaetan Rivet
2017-03-27 16:42   ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=70A7408C6E1BFB41B192A929744D8523968EC82E@ALA-MBC.corp.ad.wrs.com \
    --to=allain.legacy@windriver.com \
    --cc=adrien.mazarguil@6wind.com \
    --cc=dev@dpdk.org \
    --cc=gaetan.rivet@6wind.com \
    --cc=nelio.laranjeiro@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).