DPDK patches and discussions
 help / color / mirror / Atom feed
From: Gaetan Rivet <grive@u256.net>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v1 2/2] pci: explain how empty strings are rejected in DBDF
Date: Wed, 13 May 2020 12:47:51 +0200	[thread overview]
Message-ID: <20200513104751.46466-3-grive@u256.net> (raw)
In-Reply-To: <20200513104751.46466-1-grive@u256.net>

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 <grive@u256.net>
---
 lib/librte_pci/rte_pci.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/librte_pci/rte_pci.c b/lib/librte_pci/rte_pci.c
index e4ecdc32f..60e6fbae7 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 > UINT16_MAX)
 		return -EINVAL;
 	dev_addr->domain = (uint16_t)val;
-- 
2.26.2


  parent reply	other threads:[~2020-05-13 10:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-13 10:47 [dpdk-dev] [PATCH v1 0/2] pci: a comment and a minor fix Gaetan Rivet
2020-05-13 10:47 ` [dpdk-dev] [PATCH v1 1/2] pci: fix allowing underflow when parsing PCI id Gaetan Rivet
2020-05-14  8:52   ` Stojaczyk, Dariusz
2020-05-19  9:17   ` David Marchand
2020-05-13 10:47 ` Gaetan Rivet [this message]
2020-05-14  8:53   ` [dpdk-dev] [PATCH v1 2/2] pci: explain how empty strings are rejected in DBDF Stojaczyk, Dariusz
2020-05-19  9:18   ` David Marchand

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=20200513104751.46466-3-grive@u256.net \
    --to=grive@u256.net \
    --cc=dev@dpdk.org \
    /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).