DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Wei Hu (Xavier)" <huwei013@chinasoftinc.com>
To: <dev@dpdk.org>
Cc: <xavier.huwei@huawei.com>
Subject: [dpdk-dev] [PATCH v2 8/9] net/hns3: check return value when reading PCI config space
Date: Tue, 29 Sep 2020 20:01:16 +0800	[thread overview]
Message-ID: <20200929120117.50394-9-huwei013@chinasoftinc.com> (raw)
In-Reply-To: <20200929120117.50394-1-huwei013@chinasoftinc.com>

From: Hongbo Zheng <zhenghongbo3@huawei.com>

This patch add return value check when calling rte_pci_read_config
function.

Fixes: cea37e513329 ("net/hns3: fix FLR reset")
Cc: stable@dpdk.org

Signed-off-by: Hongbo Zheng <zhenghongbo3@huawei.com>
Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
---
 drivers/net/hns3/hns3_ethdev_vf.c | 62 ++++++++++++++++++++++++++++++++-------
 1 file changed, 51 insertions(+), 11 deletions(-)

diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index 849f6cc..a6cc11d 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -64,12 +64,18 @@ static int hns3vf_add_mc_mac_addr(struct hns3_hw *hw,
 static int hns3vf_remove_mc_mac_addr(struct hns3_hw *hw,
 				     struct rte_ether_addr *mac_addr);
 /* set PCI bus mastering */
-static void
+static int
 hns3vf_set_bus_master(const struct rte_pci_device *device, bool op)
 {
 	uint16_t reg;
+	int ret;
 
-	rte_pci_read_config(device, &reg, sizeof(reg), PCI_COMMAND);
+	ret = rte_pci_read_config(device, &reg, sizeof(reg), PCI_COMMAND);
+	if (ret < 0) {
+		PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x",
+			     PCI_COMMAND);
+		return ret;
+	}
 
 	if (op)
 		/* set the master bit */
@@ -77,7 +83,7 @@ hns3vf_set_bus_master(const struct rte_pci_device *device, bool op)
 	else
 		reg &= ~(PCI_COMMAND_MASTER);
 
-	rte_pci_write_config(device, &reg, sizeof(reg), PCI_COMMAND);
+	return rte_pci_write_config(device, &reg, sizeof(reg), PCI_COMMAND);
 }
 
 /**
@@ -94,16 +100,34 @@ hns3vf_find_pci_capability(const struct rte_pci_device *device, int cap)
 	uint8_t pos;
 	uint8_t id;
 	int ttl;
+	int ret;
+
+	ret = rte_pci_read_config(device, &status, sizeof(status), PCI_STATUS);
+	if (ret < 0) {
+		PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x", PCI_STATUS);
+		return 0;
+	}
 
-	rte_pci_read_config(device, &status, sizeof(status), PCI_STATUS);
 	if (!(status & PCI_STATUS_CAP_LIST))
 		return 0;
 
 	ttl = MAX_PCIE_CAPABILITY;
-	rte_pci_read_config(device, &pos, sizeof(pos), PCI_CAPABILITY_LIST);
+	ret = rte_pci_read_config(device, &pos, sizeof(pos),
+				  PCI_CAPABILITY_LIST);
+	if (ret < 0) {
+		PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x",
+			     PCI_CAPABILITY_LIST);
+		return 0;
+	}
+
 	while (ttl-- && pos >= PCI_STD_HEADER_SIZEOF) {
-		rte_pci_read_config(device, &id, sizeof(id),
-				    (pos + PCI_CAP_LIST_ID));
+		ret = rte_pci_read_config(device, &id, sizeof(id),
+					  (pos + PCI_CAP_LIST_ID));
+		if (ret < 0) {
+			PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x",
+				     (pos + PCI_CAP_LIST_ID));
+			break;
+		}
 
 		if (id == 0xFF)
 			break;
@@ -111,8 +135,13 @@ hns3vf_find_pci_capability(const struct rte_pci_device *device, int cap)
 		if (id == cap)
 			return (int)pos;
 
-		rte_pci_read_config(device, &pos, sizeof(pos),
-				    (pos + PCI_CAP_LIST_NEXT));
+		ret = rte_pci_read_config(device, &pos, sizeof(pos),
+					  (pos + PCI_CAP_LIST_NEXT));
+		if (ret < 0) {
+			PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x",
+				     (pos + PCI_CAP_LIST_NEXT));
+			break;
+		}
 	}
 	return 0;
 }
@@ -122,11 +151,18 @@ hns3vf_enable_msix(const struct rte_pci_device *device, bool op)
 {
 	uint16_t control;
 	int pos;
+	int ret;
 
 	pos = hns3vf_find_pci_capability(device, PCI_CAP_ID_MSIX);
 	if (pos) {
-		rte_pci_read_config(device, &control, sizeof(control),
+		ret = rte_pci_read_config(device, &control, sizeof(control),
 				    (pos + PCI_MSIX_FLAGS));
+		if (ret < 0) {
+			PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x",
+				     (pos + PCI_MSIX_FLAGS));
+			return -ENXIO;
+		}
+
 		if (op)
 			control |= PCI_MSIX_FLAGS_ENABLE;
 		else
@@ -2574,7 +2610,11 @@ hns3vf_reinit_dev(struct hns3_adapter *hns)
 
 	if (hw->reset.level == HNS3_VF_FULL_RESET) {
 		rte_intr_disable(&pci_dev->intr_handle);
-		hns3vf_set_bus_master(pci_dev, true);
+		ret = hns3vf_set_bus_master(pci_dev, true);
+		if (ret) {
+			hns3_err(hw, "failed to set pci bus, ret = %d", ret);
+			return ret;
+		}
 	}
 
 	/* Firmware command initialize */
-- 
2.9.5


  parent reply	other threads:[~2020-09-29 12:04 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29 11:09 [dpdk-dev] [PATCH 0/9] updates and fixes for hns3 PMD driver Wei Hu (Xavier)
2020-09-29 11:09 ` [dpdk-dev] [PATCH 1/9] net/hns3: expand the number of queues for one TC up to 512 Wei Hu (Xavier)
2020-09-29 11:09 ` [dpdk-dev] [PATCH 2/9] net/hns3: maximize the queue number Wei Hu (Xavier)
2020-09-29 11:09 ` [dpdk-dev] [PATCH 3/9] net/hns3: fix error type when validating RSS flow action Wei Hu (Xavier)
2020-09-29 11:09 ` [dpdk-dev] [PATCH 4/9] net/hns3: set suitable type when initial flow error struct Wei Hu (Xavier)
2020-09-29 11:09 ` [dpdk-dev] [PATCH 5/9] net/hns3: offload calculating the shapping para to firmware Wei Hu (Xavier)
2020-09-29 11:09 ` [dpdk-dev] [PATCH 6/9] net/hns3: set max scheduling rate based on actual board Wei Hu (Xavier)
2020-09-29 11:09 ` [dpdk-dev] [PATCH 7/9] net/hns3: support start and stop Tx or Rx queue Wei Hu (Xavier)
2020-09-29 11:09 ` [dpdk-dev] [PATCH 8/9] net/hns3: check return value when reading PCI config space Wei Hu (Xavier)
2020-09-29 11:09 ` [dpdk-dev] [PATCH 9/9] net/hns3: remove redundant return value assignments Wei Hu (Xavier)
2020-09-29 12:01 ` [dpdk-dev] [PATCH v2 0/9] updates and fixes for hns3 PMD driver Wei Hu (Xavier)
2020-09-29 12:01   ` [dpdk-dev] [PATCH v2 1/9] net/hns3: expand the number of queues for one TC up to 512 Wei Hu (Xavier)
2020-09-29 12:01   ` [dpdk-dev] [PATCH v2 2/9] net/hns3: maximize the queue number Wei Hu (Xavier)
2020-09-29 12:01   ` [dpdk-dev] [PATCH v2 3/9] net/hns3: fix error type when validating RSS flow action Wei Hu (Xavier)
2020-09-29 12:01   ` [dpdk-dev] [PATCH v2 4/9] net/hns3: set suitable type when initial flow error struct Wei Hu (Xavier)
2020-09-29 12:01   ` [dpdk-dev] [PATCH v2 5/9] net/hns3: offload calculating the shapping para to firmware Wei Hu (Xavier)
2020-09-29 12:01   ` [dpdk-dev] [PATCH v2 6/9] net/hns3: set max scheduling rate based on actual board Wei Hu (Xavier)
2020-09-29 12:01   ` [dpdk-dev] [PATCH v2 7/9] net/hns3: support start and stop Tx or Rx queue Wei Hu (Xavier)
2020-09-30 22:49     ` Ferruh Yigit
2020-09-30 22:54       ` Ferruh Yigit
2020-09-29 12:01   ` Wei Hu (Xavier) [this message]
2020-09-29 12:01   ` [dpdk-dev] [PATCH v2 9/9] net/hns3: remove redundant return value assignments Wei Hu (Xavier)
2020-09-30 22:59   ` [dpdk-dev] [PATCH v2 0/9] updates and fixes for hns3 PMD driver 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=20200929120117.50394-9-huwei013@chinasoftinc.com \
    --to=huwei013@chinasoftinc.com \
    --cc=dev@dpdk.org \
    --cc=xavier.huwei@huawei.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).