From: Gaetan Rivet Date: Wed, 13 May 2020 10:47:51 +0000 (+0200) Subject: pci: explain how empty strings are rejected in DBDF X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=8354e681e347f72a0102f3443e3c154b0984295d;p=dpdk.git pci: explain how empty strings are rejected in DBDF Empty strings are forbidden as input to rte_pci_addr_parse(). It is explicitly enforced in BDF parsing as parsing the bus field will immediately fail. The related check is commented. It is implicitly enforced in DBDF parsing, as the domain would be parsed to 0 without error, but the check `end[0] != ':'` afterward will return -EINVAL. Enforcing consistency between parsers by reading the code is not helped by this property being implicit. Add a comment to explain. Signed-off-by: Gaetan Rivet Acked-by: Darek Stojaczyk --- diff --git a/lib/librte_pci/rte_pci.c b/lib/librte_pci/rte_pci.c index 5f7726fa89..9c80c4b71d 100644 --- a/lib/librte_pci/rte_pci.c +++ b/lib/librte_pci/rte_pci.c @@ -84,6 +84,10 @@ pci_dbdf_parse(const char *input, struct rte_pci_addr *dev_addr) errno = 0; val = strtoul(in, &end, 16); + /* Empty string is not an error for strtoul, but the check + * end[0] != ':' + * will detect the issue. + */ if (errno != 0 || end[0] != ':' || val > UINT32_MAX) return -EINVAL; dev_addr->domain = (uint32_t)val;