From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by dpdk.org (Postfix) with ESMTP id 29EFE2B8C for ; Fri, 10 Mar 2017 18:49:23 +0100 (CET) Received: by mail-wm0-f45.google.com with SMTP id 196so481230wmm.1 for ; Fri, 10 Mar 2017 09:49:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=1dWCJMLm9muQ0yTApbSpiQf3+TPyLoNqI13OpkkmOTU=; b=TeE2pZtbLLeu3Sz+VhPJUlRZb1yXT6/5ejFdoTkRKLai1wNxVMUwY4EyaOIE/vwJS1 2YIULMX0QdRouYjNWelopqlWp8H+6SZMLLLdtCM1pmIewTZDhtYqPjNsdLiG4nQFZHsw 46lyZ25d6E+Q28mQoFRl1dUTLHTxUqNMFJTuLPiUwxKTikUX6yZ4UoaZWhDEdBe3PY8H LpaM+Ezh60qd0X8Iu9ezfqb6Sz7stBVLtHxI+s+Z3vhqgeCSPPPwdBOC+G/zq4RbpLXK DWE3ZgI+0epuDIdbKFkUaQvoRyoWEjKAbB6cX1kgljod3pPoRT/u9x3RqXUERdjYn87s 8PLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=1dWCJMLm9muQ0yTApbSpiQf3+TPyLoNqI13OpkkmOTU=; b=S9mpTE8whPjSMT7BSHV/zryySBuHifDRyWAjc5khDzdLVyR+R9bNABY51CpA6cvIxG E/+jv7QJT3NXQedkhuJiTx1VqdzxWGnnDxz6TQU8zFLBUTBvcYEtc/Yi9FqUHn83W8u1 kHmgLUAflBBBG5MxEZY+thOmC6Jny3rMpC1d3JRiylmt7aGodN9ZjY6llxP3iQaQgMYS WWXvzY9ZCnBfnoeJz60ZIviTBMFlFcNWxjXPT/6RN9f9mR23I0liaNKiyhHPUgD9nj4u ogCfFW4AhAcQL/FbDLXyFko4JF/w1i6lssxf3Eak8ns+wnJGIcMkk5/z30RJractzDME v22g== X-Gm-Message-State: AFeK/H27uXwIrT6Kasl40rZNTpFYTSsvlhSHca5ZXbRyYepfc2OM4e6rvEGvjMT2o8gvomh6 X-Received: by 10.28.48.67 with SMTP id w64mr127797wmw.125.1489168162750; Fri, 10 Mar 2017 09:49:22 -0800 (PST) Received: from bidouze.vm.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id x23sm13885862wrb.49.2017.03.10.09.49.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Mar 2017 09:49:22 -0800 (PST) Date: Fri, 10 Mar 2017 18:49:13 +0100 From: =?iso-8859-1?Q?Ga=EBtan?= Rivet To: "Legacy, Allain" Cc: "dev@dpdk.org" , Adrien Mazarguil , Nelio Laranjeiro Message-ID: <20170310174913.GL908@bidouze.vm.6wind.com> References: <70A7408C6E1BFB41B192A929744D8523968EC82E@ALA-MBC.corp.ad.wrs.com> <20170310171159.GK908@bidouze.vm.6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20170310171159.GK908@bidouze.vm.6wind.com> User-Agent: Mutt/1.5.23 (2014-03-12) 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 17:49:23 -0000 slight additional remark below. On Fri, Mar 10, 2017 at 06:11:59PM +0100, Gaëtan Rivet wrote: >Hey, thanks for reading. > >On Fri, Mar 10, 2017 at 04:24:32PM +0000, Legacy, Allain wrote: >>>-----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)) >> >> > >Thanks for the suggestion, I'd keep the strtoul though ;). >I will see into it for the v2, keeping in mind Stephen's remarks as >well. > >>>+ 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. >> >> > >This function was aimed at being generic. >If we consider that no other parameter would ever be added, then the >strcmp should be scraped altogether, as this callback is only called >upon parsing this parameter in the kvlist in the first place. > >But we are in the control path, avoiding a useless strtoul at the >price of making the function less useful seems an unnecessary tradeoff >to me. > >>>+ 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. >> >> > >Agreed. > Actually, on second thought, here the devargs that was problematic has already been shown with a warning while it was being parsed. >>>+ /* 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; >> >> > >I do not agree with removing this loop. > >Your second solution will scatter the relevant bits concerning the >default value of the active_port configuration option. While being >slightly slicker it hides it unnecessarily from the reader. > >The first solution might be interesting, however it makes this option >dependent on two defines instead of one. If one had to change the >default MAX_PHYS_PORT value for mlx4 (however unlikely it might be), >then they would have to change the valid ALL_PORTS mask as well. In >principle this contradicts DRY[1]. > >[1]: https://en.wikipedia.org/wiki/Don't_repeat_yourself > >-- >Gaëtan Rivet >6WIND -- Gaëtan Rivet 6WIND