From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.windriver.com (mail.windriver.com [147.11.1.11]) by dpdk.org (Postfix) with ESMTP id 94543108A for ; Fri, 10 Mar 2017 17:24:38 +0100 (CET) Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail.windriver.com (8.15.2/8.15.1) with ESMTPS id v2AGOXvF013713 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Fri, 10 Mar 2017 08:24:34 -0800 (PST) Received: from ALA-MBC.corp.ad.wrs.com ([fe80::fcbe:9b7:1141:89a1]) by ALA-HCA.corp.ad.wrs.com ([147.11.189.40]) with mapi id 14.03.0294.000; Fri, 10 Mar 2017 08:24:33 -0800 From: "Legacy, Allain" To: Gaetan Rivet , "dev@dpdk.org" CC: Adrien Mazarguil , Nelio Laranjeiro Thread-Topic: [dpdk-dev] [PATCH 1/1] net/mlx4: add port parameter Thread-Index: AQHSlDR+DogFpIqa80my87yRDlQ816GORhTA Date: Fri, 10 Mar 2017 16:24:32 +0000 Message-ID: <70A7408C6E1BFB41B192A929744D8523968EC82E@ALA-MBC.corp.ad.wrs.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [128.224.140.166] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH 1/1] net/mlx4: add port parameter X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Mar 2017 16:24:39 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Gaetan Rivet > Sent: Friday, March 03, 2017 10:40 AM ... > + errno =3D 0; > + tmp =3D strtoul(val, NULL, 0); The robustness of the strtoul() could be improved with something like the f= ollowing to catch non-integer characters following the port number.=20 char *end =3D NULL; tmp =3D strtoull(val, &end, 0); if ((val[0] =3D=3D '\0') || (end =3D=3D NULL) || (*end !=3D '\0') || (e= rrno !=3D 0)) > + if (errno) { > + WARN("%s: \"%s\" is not a valid integer", key, val); > + return -errno; > + } > + if (strcmp(MLX4_PMD_PORT_KVARG, key) =3D=3D 0) { > + if (tmp >=3D MLX4_PMD_MAX_PHYS_PORTS) { > + ERROR("invalid port index %lu (max: %u)", > + tmp, MLX4_PMD_MAX_PHYS_PORTS - 1); > + return -EINVAL; > + } > + conf->active_ports |=3D 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_POR= T_KVARG, key) IF statement. That way the "val" would only be parsed if "ke= y" 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.=20 > + /* Use all ports when none are defined */ > + if (conf.active_ports =3D=3D 0) { > + for (i =3D 0; i < MLX4_PMD_MAX_PHYS_PORTS; i++) > + conf.active_ports |=3D 1 << i; > + } Rather than use a loop to populate all active fields would a #define with a= n all ports mask be better suited to this. Or alternatively just change th= e 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;