Skip to contentSkip to conversation

some small fixes

PATCH Superseded Bruce Richardson 4 participants 26 messages Apr 5, 2019 – Apr 22, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover some small fixes

A few coverity fixes, along with a fix for one of the examples meson.build files which I caught along the way.

Bruce Richardson (5):
examples/vhost_scsi: fix header check for meson build examples/vhost_scsi: fix missing NULL-check for parameter net/i40e: fix dereference before NULL check in mbuf release app/testpmd: fix variable use before NULL check net/i40e: fix dereference before check when getting EEPROM

 app/test-pmd/cmdline.c           | 4 ++--
 drivers/net/i40e/i40e_ethdev.c   | 5 +++--
 drivers/net/i40e/i40e_rxtx.c     | 4 ++--
 examples/vhost_scsi/meson.build  | 2 +-
 examples/vhost_scsi/vhost_scsi.c | 6 ++++++
 5 files changed, 14 insertions(+), 7 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/5 examples/vhost_scsi: fix header check for meson build

The header check for the example app was looking for virtio_scsi.h without the "linux/" prefix, which meant it was never getting found when it should have been.

Fixes 8d47a753b7cb ("examples/vhost_scsi: disable build if missing dependency")
CC Maxime Coquelin <[email protected]>
CC Tiwei Bie <[email protected]>
CC Zhihong Wang <[email protected]>
---
 examples/vhost_scsi/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/vhost_scsi/meson.build +1 -1
index ca1248023..e00a7dab1 100644
@@ -10,7 +10,7 @@ if host_machine.system() != 'linux'
 	build = false
 endif
 
-if not cc.has_header('virtio_scsi.h')
+if not cc.has_header('linux/virtio_scsi.h')
 	build = false
 endif
 
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/5 examples/vhost_scsi: fix missing NULL-check for parameter

In reply to Bruce Richardson

Coverity points out that there is a check in the main thread loop for the ctrlr->bdev being NULL, but by that stage the pointer has already been dereferenced. Therefore, for safety, before we enter the loop do an initial check on the parameter structure.

Coverity issue: 158657

Fixes db75c7af19bb ("examples/vhost_scsi: introduce a new sample app")
CC Maxime Coquelin <[email protected]>
CC Tiwei Bie <[email protected]>
CC Zhihong Wang <[email protected]>
---
 examples/vhost_scsi/vhost_scsi.c | 6 ++++++
 1 file changed, 6 insertions(+)
examples/vhost_scsi/vhost_scsi.c +6 -0
index 2908ff68b..a6465d089 100644
@@ -285,6 +285,12 @@ ctrlr_worker(void *arg)
 	cpu_set_t cpuset;
 	pthread_t thread;
 
+	if (ctrlr == NULL || ctrlr->bdev == NULL) {
+		fprintf(stdout, "%s: Error, invalid argument passed to worker thread\n",
+				__func__);
+		return NULL;
+	}
+
 	thread = pthread_self();
 	CPU_ZERO(&cpuset);
 	CPU_SET(0, &cpuset);
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/5 net/i40e: fix dereference before NULL check in mbuf release

In reply to Bruce Richardson

Coverity flags that the txq variable is used before it's checked for NULL.

Coverity issue: 195023

Fixes 24853544c84c ("net/i40e: fix mbuf free in vector Tx")
---
 drivers/net/i40e/i40e_rxtx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/i40e/i40e_rxtx.c +2 -2
index 8f727fae6..5ce85eb52 100644
@@ -2423,13 +2423,13 @@ i40e_tx_queue_release_mbufs(struct i40e_tx_queue *txq)
 	struct rte_eth_dev *dev;
 	uint16_t i;
 
-	dev = &rte_eth_devices[txq->port_id];
-
 	if (!txq || !txq->sw_ring) {
 		PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL");
 		return;
 	}
 
+	dev = &rte_eth_devices[txq->port_id];
+
 	/**
 	 *  vPMD tx will not set sw_ring's mbuf to NULL after free,
 	 *  so need to free remains more carefully.
Signature · 1 line
2.20.1
Acked-by on v1 3/5
#4 lore raw

Re: [dpdk-dev] [PATCH 3/5] net/i40e: fix dereference before NULL check in mbuf release

In this occasion I noticed that there is a typo in the code that appears in the patch;
it should be "Pointer to txq" instead of "Pointer to rxq":
I would consider resending and fixing it on this occasion:

Quoted 4 lines
 if (!txq || !txq->sw_ring) {
              PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL");
               return;
       }

‏<[email protected]>:

Quoted 38 lines

Coverity flags that the txq variable is used before it's checked for NULL.

Coverity issue: 195023

Fixes 24853544c84c ("net/i40e: fix mbuf free in vector Tx")
---
 drivers/net/i40e/i40e_rxtx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/i40e/i40e_rxtx.c +2 -2
index 8f727fae6..5ce85eb52 100644
@@ -2423,13 +2423,13 @@ i40e_tx_queue_release_mbufs(struct i40e_tx_queue
 *txq)
        struct rte_eth_dev *dev;
        uint16_t i;
 
-       dev = &rte_eth_devices[txq->port_id];
-
        if (!txq || !txq->sw_ring) {
                PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL");
                return;
        }
 
+       dev = &rte_eth_devices[txq->port_id];
+
        /**
         *  vPMD tx will not set sw_ring's mbuf to NULL after free,

* so need to free remains more carefully.
--
2.20.1

#5 lore raw

PATCH 4/5 app/testpmd: fix variable use before NULL check

In reply to Bruce Richardson

The value returned from rte_eth_dev_tx_offload_name() function is used for string comparison before being checked for NULL. Move the NULL check up to be done first.

Coverity issue: 279438

Fixes c73a9071877a ("app/testpmd: add commands to test new offload API")
Cc Bernard Iremonger <[email protected]>
Cc Wenzhuo Lu <[email protected]>
---
 app/test-pmd/cmdline.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-pmd/cmdline.c +2 -2
index ee50e4566..2155ff241 100644
@@ -18306,13 +18306,13 @@ search_tx_offload(const char *name)
 	single_offload = 1;
 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
 		single_name = rte_eth_dev_tx_offload_name(single_offload);
+		if (single_name == NULL)
+			break;
 		if (!strcasecmp(single_name, name)) {
 			found = 1;
 			break;
 		} else if (!strcasecmp(single_name, "UNKNOWN"))
 			break;
-		else if (single_name == NULL)
-			break;
 		single_offload <<= 1;
 	}
 
Signature · 1 line
2.20.1
#7 lore raw

PATCH 5/5 net/i40e: fix dereference before check when getting EEPROM

In reply to Bruce Richardson

As flagged by coverity, the "info" structure is being explicitly dereferenced before being checked later for a NULL value.

Coverity issue: 277241

Fixes 98e60c0d43f1 ("net/i40e: add module EEPROM callbacks for i40e")
CC Beilei Xing <[email protected]>
CC Qi Zhang <[email protected]>
---
 drivers/net/i40e/i40e_ethdev.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/i40e/i40e_ethdev.c +3 -2
index b031bf4c6..6450af016 100644
@@ -11893,16 +11893,17 @@ static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	bool is_sfp = false;
 	i40e_status status;
-	uint8_t *data = info->data;
+	uint8_t *data;
 	uint32_t value = 0;
 	uint32_t i;
 
-	if (!info || !info->length || !data)
+	if (!info || !info->length || !info->data)
 		return -EINVAL;
 
 	if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
 		is_sfp = true;
 
+	data = info->data;
 	for (i = 0; i < info->length; i++) {
 		u32 offset = i + info->offset;
 		u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
Signature · 1 line
2.20.1
#9 lore raw

v2 cover some small fixes

In reply to Bruce Richardson

A few coverity fixes, along with a fix for one of the examples meson.build files which I caught along the way.

v2: include a typo fix identified by Rami Rosen.

Bruce Richardson (5):
examples/vhost_scsi: fix header check for meson build examples/vhost_scsi: fix missing NULL-check for parameter net/i40e: fix dereference before NULL check in mbuf release app/testpmd: fix variable use before NULL check net/i40e: fix dereference before check when getting EEPROM

 app/test-pmd/cmdline.c           | 4 ++--
 drivers/net/i40e/i40e_ethdev.c   | 5 +++--
 drivers/net/i40e/i40e_rxtx.c     | 6 +++---
 examples/vhost_scsi/meson.build  | 2 +-
 examples/vhost_scsi/vhost_scsi.c | 6 ++++++
 5 files changed, 15 insertions(+), 8 deletions(-)
Signature · 1 line
2.20.1
#10 lore raw

PATCH v2 1/5 examples/vhost_scsi: fix header check for meson build

The header check for the example app was looking for virtio_scsi.h without the "linux/" prefix, which meant it was never getting found when it should have been.

Fixes 8d47a753b7cb ("examples/vhost_scsi: disable build if missing dependency")
CC Maxime Coquelin <[email protected]>
CC Tiwei Bie <[email protected]>
CC Zhihong Wang <[email protected]>
---
 examples/vhost_scsi/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/vhost_scsi/meson.build +1 -1
index ca1248023..e00a7dab1 100644
@@ -10,7 +10,7 @@ if host_machine.system() != 'linux'
 	build = false
 endif
 
-if not cc.has_header('virtio_scsi.h')
+if not cc.has_header('linux/virtio_scsi.h')
 	build = false
 endif
 
Signature · 1 line
2.20.1
Reviewed-by on v2 1/5
#11 lore raw

Re: [dpdk-dev] [PATCH v2 1/5] examples/vhost_scsi: fix header check for meson build

Quoted 30 lines · Bruce Richardson

The header check for the example app was looking for virtio_scsi.h without the "linux/" prefix, which meant it was never getting found when it should have been.

Fixes 8d47a753b7cb ("examples/vhost_scsi: disable build if missing dependency")
CC Maxime Coquelin <[email protected]>
CC Tiwei Bie <[email protected]>
CC Zhihong Wang <[email protected]>
---
 examples/vhost_scsi/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/vhost_scsi/meson.build +1 -1
index ca1248023..e00a7dab1 100644
@@ -10,7 +10,7 @@ if host_machine.system() != 'linux'
 	build = false
 endif
 
-if not cc.has_header('virtio_scsi.h')
+if not cc.has_header('linux/virtio_scsi.h')
 	build = false
 endif
 
Signature · 1 line
2.20.1
#12 lore raw

PATCH v2 2/5 examples/vhost_scsi: fix missing NULL-check for parameter

In reply to Bruce Richardson

Coverity points out that there is a check in the main thread loop for the ctrlr->bdev being NULL, but by that stage the pointer has already been dereferenced. Therefore, for safety, before we enter the loop do an initial check on the parameter structure.

Coverity issue: 158657

Fixes db75c7af19bb ("examples/vhost_scsi: introduce a new sample app")
CC Maxime Coquelin <[email protected]>
CC Tiwei Bie <[email protected]>
CC Zhihong Wang <[email protected]>
---
 examples/vhost_scsi/vhost_scsi.c | 6 ++++++
 1 file changed, 6 insertions(+)
examples/vhost_scsi/vhost_scsi.c +6 -0
index 2908ff68b..a6465d089 100644
@@ -285,6 +285,12 @@ ctrlr_worker(void *arg)
 	cpu_set_t cpuset;
 	pthread_t thread;
 
+	if (ctrlr == NULL || ctrlr->bdev == NULL) {
+		fprintf(stdout, "%s: Error, invalid argument passed to worker thread\n",
+				__func__);
+		return NULL;
+	}
+
 	thread = pthread_self();
 	CPU_ZERO(&cpuset);
 	CPU_SET(0, &cpuset);
Signature · 1 line
2.20.1
#13 lore raw

Re: [dpdk-dev] [PATCH v2 2/5] examples/vhost_scsi: fix missing NULL-check for parameter

Quoted 22 lines · Bruce Richardson

Coverity points out that there is a check in the main thread loop for the ctrlr->bdev being NULL, but by that stage the pointer has already been dereferenced. Therefore, for safety, before we enter the loop do an initial check on the parameter structure.

Coverity issue: 158657

Fixes db75c7af19bb ("examples/vhost_scsi: introduce a new sample app")
CC Maxime Coquelin <[email protected]>
CC Tiwei Bie <[email protected]>
CC Zhihong Wang <[email protected]>
---
 examples/vhost_scsi/vhost_scsi.c | 6 ++++++
 1 file changed, 6 insertions(+)
examples/vhost_scsi/vhost_scsi.c +0 -0
index 2908ff68b..a6465d089 100644

examples/vhost_scsi/vhost_scsi.c ctrlr_worker(void *arg) · line 289

Quoted 5 lines
examples/vhost_scsi/vhost_scsi.c +2 -0
@@ -285,6 +285,12 @@ ctrlr_worker(void *arg)
 	cpu_set_t cpuset;
 	pthread_t thread;
 
+	if (ctrlr == NULL || ctrlr->bdev == NULL) {
+		fprintf(stdout, "%s: Error, invalid argument passed to worker thread\n",

Might be better to print to stderr.

examples/vhost_scsi/vhost_scsi.c ctrlr_worker(void *arg) · line 291

Quoted 2 lines
examples/vhost_scsi/vhost_scsi.c +2 -0
+				__func__);
+		return NULL;

Might be better to exit() directly like what the other error handling in this thread does:

https://github.com/DPDK/dpdk/blob/bdcfcceb7a0b7534a0dba669279d18bd0f98d5e5/examples/vhost_scsi/vhost_scsi.c#L296-L299

Otherwise destroy_device() will hang on sem_wait(&exit_sem):

https://github.com/DPDK/dpdk/blob/bdcfcceb7a0b7534a0dba669279d18bd0f98d5e5/examples/vhost_scsi/vhost_scsi.c#L390

Thanks,
Tiwei

Quoted 8 lines
examples/vhost_scsi/vhost_scsi.c +2 -0
+	}
+
 	thread = pthread_self();
 	CPU_ZERO(&cpuset);
 	CPU_SET(0, &cpuset);
Signature · 1 line
2.20.1
#14 lore raw

Re: [dpdk-dev] [PATCH v2 2/5] examples/vhost_scsi: fix missing NULL-check for parameter

Quoted 26 lines · Tiwei Bie
Quoted 25 lines · Bruce Richardson

Coverity points out that there is a check in the main thread loop for the ctrlr->bdev being NULL, but by that stage the pointer has already been dereferenced. Therefore, for safety, before we enter the loop do an initial check on the parameter structure.

Coverity issue: 158657

Fixes db75c7af19bb ("examples/vhost_scsi: introduce a new sample app")
CC Maxime Coquelin <[email protected]>
CC Tiwei Bie <[email protected]>
CC Zhihong Wang <[email protected]>
---
 examples/vhost_scsi/vhost_scsi.c | 6 ++++++
 1 file changed, 6 insertions(+)
examples/vhost_scsi/vhost_scsi.c +0 -0
index 2908ff68b..a6465d089 100644
@@ -285,6 +285,12 @@ ctrlr_worker(void *arg)
 	cpu_set_t cpuset;
 	pthread_t thread;
 
Quoted 5 lines

examples/vhost_scsi/vhost_scsi.c ctrlr_worker(void *arg) · line 289

Quoted 2 lines
examples/vhost_scsi/vhost_scsi.c +2 -0
+	if (ctrlr == NULL || ctrlr->bdev == NULL) {
+		fprintf(stdout, "%s: Error, invalid argument passed to worker thread\n",

Might be better to print to stderr.

Yes, this looks a typo on my part.

Quoted 6 lines

examples/vhost_scsi/vhost_scsi.c ctrlr_worker(void *arg) · line 291

Quoted 2 lines
examples/vhost_scsi/vhost_scsi.c +2 -0
+				__func__);
+		return NULL;

Might be better to exit() directly like what the other error handling in this thread does:

Quoted 6 lines

https://github.com/DPDK/dpdk/blob/bdcfcceb7a0b7534a0dba669279d18bd0f98d5e5/examples/vhost_scsi/vhost_scsi.c#L296-L299

Otherwise destroy_device() will hang on sem_wait(&exit_sem):

https://github.com/DPDK/dpdk/blob/bdcfcceb7a0b7534a0dba669279d18bd0f98d5e5/examples/vhost_scsi/vhost_scsi.c#L390

Ok, will change in next revision

#15 lore raw

PATCH v2 3/5 net/i40e: fix dereference before NULL check in mbuf release

In reply to Bruce Richardson

Coverity flags that the txq variable is used before it's checked for NULL. Also fix typo in error message.

Coverity issue: 195023

Fixes 24853544c84c ("net/i40e: fix mbuf free in vector Tx")

---
V2: Fix typo or copy/paste error while fixing main issue

---
 drivers/net/i40e/i40e_rxtx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/i40e/i40e_rxtx.c +3 -3
index 8f727fae6..282e18bc1 100644
@@ -2423,13 +2423,13 @@ i40e_tx_queue_release_mbufs(struct i40e_tx_queue *txq)
 	struct rte_eth_dev *dev;
 	uint16_t i;
 
-	dev = &rte_eth_devices[txq->port_id];
-
 	if (!txq || !txq->sw_ring) {
-		PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL");
+		PMD_DRV_LOG(DEBUG, "Pointer to txq or sw_ring is NULL");
 		return;
 	}
 
+	dev = &rte_eth_devices[txq->port_id];
+
 	/**
 	 *  vPMD tx will not set sw_ring's mbuf to NULL after free,
 	 *  so need to free remains more carefully.
Signature · 1 line
2.20.1
#16 lore raw

PATCH v2 4/5 app/testpmd: fix variable use before NULL check

In reply to Bruce Richardson

The value returned from rte_eth_dev_tx_offload_name() function is used for string comparison before being checked for NULL. Move the NULL check up to be done first.

Coverity issue: 279438

Fixes c73a9071877a ("app/testpmd: add commands to test new offload API")
Cc Bernard Iremonger <[email protected]>
Cc Wenzhuo Lu <[email protected]>
---
 app/test-pmd/cmdline.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-pmd/cmdline.c +2 -2
index ee50e4566..2155ff241 100644
@@ -18306,13 +18306,13 @@ search_tx_offload(const char *name)
 	single_offload = 1;
 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
 		single_name = rte_eth_dev_tx_offload_name(single_offload);
+		if (single_name == NULL)
+			break;
 		if (!strcasecmp(single_name, name)) {
 			found = 1;
 			break;
 		} else if (!strcasecmp(single_name, "UNKNOWN"))
 			break;
-		else if (single_name == NULL)
-			break;
 		single_offload <<= 1;
 	}
 
Signature · 1 line
2.20.1
#17 lore raw

PATCH v2 5/5 net/i40e: fix dereference before check when getting EEPROM

In reply to Bruce Richardson

As flagged by coverity, the "info" structure is being explicitly dereferenced before being checked later for a NULL value.

Coverity issue: 277241

Fixes 98e60c0d43f1 ("net/i40e: add module EEPROM callbacks for i40e")
CC Beilei Xing <[email protected]>
CC Qi Zhang <[email protected]>
---
 drivers/net/i40e/i40e_ethdev.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/i40e/i40e_ethdev.c +3 -2
index b031bf4c6..6450af016 100644
@@ -11893,16 +11893,17 @@ static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	bool is_sfp = false;
 	i40e_status status;
-	uint8_t *data = info->data;
+	uint8_t *data;
 	uint32_t value = 0;
 	uint32_t i;
 
-	if (!info || !info->length || !data)
+	if (!info || !info->length || !info->data)
 		return -EINVAL;
 
 	if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
 		is_sfp = true;
 
+	data = info->data;
 	for (i = 0; i < info->length; i++) {
 		u32 offset = i + info->offset;
 		u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
Signature · 1 line
2.20.1
#18 lore raw

v3 cover some small fixes

In reply to Bruce Richardson

A few coverity fixes, along with a fix for one of the examples meson.build files which I caught along the way.

v3: updated patch 2, to include fixes from Tiwei.
v2: include a typo fix identified by Rami Rosen.

Bruce Richardson (5):
examples/vhost_scsi: fix header check for meson build examples/vhost_scsi: fix missing NULL-check for parameter net/i40e: fix dereference before NULL check in mbuf release app/testpmd: fix variable use before NULL check net/i40e: fix dereference before check when getting EEPROM

 app/test-pmd/cmdline.c           | 4 ++--
 drivers/net/i40e/i40e_ethdev.c   | 5 +++--
 drivers/net/i40e/i40e_rxtx.c     | 6 +++---
 examples/vhost_scsi/meson.build  | 2 +-
 examples/vhost_scsi/vhost_scsi.c | 6 ++++++
 5 files changed, 15 insertions(+), 8 deletions(-)
Signature · 1 line
2.20.1
#19 lore raw

PATCH v3 1/5 examples/vhost_scsi: fix header check for meson build

The header check for the example app was looking for virtio_scsi.h without the "linux/" prefix, which meant it was never getting found when it should have been.

Fixes 8d47a753b7cb ("examples/vhost_scsi: disable build if missing dependency")
CC Maxime Coquelin <[email protected]>
CC Tiwei Bie <[email protected]>
CC Zhihong Wang <[email protected]>
---
 examples/vhost_scsi/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/vhost_scsi/meson.build +1 -1
index ca1248023..e00a7dab1 100644
@@ -10,7 +10,7 @@ if host_machine.system() != 'linux'
 	build = false
 endif
 
-if not cc.has_header('virtio_scsi.h')
+if not cc.has_header('linux/virtio_scsi.h')
 	build = false
 endif
 
Signature · 1 line
2.20.1
#20 lore raw

PATCH v3 2/5 examples/vhost_scsi: fix missing NULL-check for parameter

In reply to Bruce Richardson

Coverity points out that there is a check in the main thread loop for the ctrlr->bdev being NULL, but by that stage the pointer has already been dereferenced. Therefore, for safety, before we enter the loop do an initial check on the parameter structure.

Coverity issue: 158657

Fixes db75c7af19bb ("examples/vhost_scsi: introduce a new sample app")
CC Maxime Coquelin <[email protected]>
CC Tiwei Bie <[email protected]>
CC Zhihong Wang <[email protected]>
---
 examples/vhost_scsi/vhost_scsi.c | 6 ++++++
 1 file changed, 6 insertions(+)
examples/vhost_scsi/vhost_scsi.c +6 -0
index 2908ff68b..513af0cca 100644
@@ -285,6 +285,12 @@ ctrlr_worker(void *arg)
 	cpu_set_t cpuset;
 	pthread_t thread;
 
+	if (ctrlr == NULL || ctrlr->bdev == NULL) {
+		fprintf(stderr, "%s: Error, invalid argument passed to worker thread\n",
+				__func__);
+		exit(0);
+	}
+
 	thread = pthread_self();
 	CPU_ZERO(&cpuset);
 	CPU_SET(0, &cpuset);
Signature · 1 line
2.20.1
Reviewed-by on v3 2/5
#21 lore raw

Re: [dpdk-dev] [PATCH v3 2/5] examples/vhost_scsi: fix missing NULL-check for parameter

Quoted 12 lines · Bruce Richardson

Coverity points out that there is a check in the main thread loop for the ctrlr->bdev being NULL, but by that stage the pointer has already been dereferenced. Therefore, for safety, before we enter the loop do an initial check on the parameter structure.

Coverity issue: 158657

Fixes db75c7af19bb ("examples/vhost_scsi: introduce a new sample app")
CC Maxime Coquelin <[email protected]>
CC Tiwei Bie <[email protected]>
CC Zhihong Wang <[email protected]>
Quoted 4 lines
---
 examples/vhost_scsi/vhost_scsi.c | 6 ++++++
 1 file changed, 6 insertions(+)
#22 lore raw

PATCH v3 3/5 net/i40e: fix dereference before NULL check in mbuf release

In reply to Bruce Richardson

Coverity flags that the txq variable is used before it's checked for NULL. Also fix typo in error message.

Coverity issue: 195023

Fixes 24853544c84c ("net/i40e: fix mbuf free in vector Tx")
---
 drivers/net/i40e/i40e_rxtx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/i40e/i40e_rxtx.c +3 -3
index 8f727fae6..282e18bc1 100644
@@ -2423,13 +2423,13 @@ i40e_tx_queue_release_mbufs(struct i40e_tx_queue *txq)
 	struct rte_eth_dev *dev;
 	uint16_t i;
 
-	dev = &rte_eth_devices[txq->port_id];
-
 	if (!txq || !txq->sw_ring) {
-		PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL");
+		PMD_DRV_LOG(DEBUG, "Pointer to txq or sw_ring is NULL");
 		return;
 	}
 
+	dev = &rte_eth_devices[txq->port_id];
+
 	/**
 	 *  vPMD tx will not set sw_ring's mbuf to NULL after free,
 	 *  so need to free remains more carefully.
Signature · 1 line
2.20.1
#23 lore raw

PATCH v3 4/5 app/testpmd: fix variable use before NULL check

In reply to Bruce Richardson

The value returned from rte_eth_dev_tx_offload_name() function is used for string comparison before being checked for NULL. Move the NULL check up to be done first.

Coverity issue: 279438

Fixes c73a9071877a ("app/testpmd: add commands to test new offload API")
Cc Bernard Iremonger <[email protected]>
Cc Wenzhuo Lu <[email protected]>
---
 app/test-pmd/cmdline.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-pmd/cmdline.c +2 -2
index 2ab03c111..391bc8097 100644
@@ -18311,13 +18311,13 @@ search_tx_offload(const char *name)
 	single_offload = 1;
 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
 		single_name = rte_eth_dev_tx_offload_name(single_offload);
+		if (single_name == NULL)
+			break;
 		if (!strcasecmp(single_name, name)) {
 			found = 1;
 			break;
 		} else if (!strcasecmp(single_name, "UNKNOWN"))
 			break;
-		else if (single_name == NULL)
-			break;
 		single_offload <<= 1;
 	}
 
Signature · 1 line
2.20.1
#24 lore raw

PATCH v3 5/5 net/i40e: fix dereference before check when getting EEPROM

In reply to Bruce Richardson

As flagged by coverity, the "info" structure is being explicitly dereferenced before being checked later for a NULL value.

Coverity issue: 277241

Fixes 98e60c0d43f1 ("net/i40e: add module EEPROM callbacks for i40e")
CC Beilei Xing <[email protected]>
CC Qi Zhang <[email protected]>
---
 drivers/net/i40e/i40e_ethdev.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/i40e/i40e_ethdev.c +3 -2
index 5b01dc1f0..9305b7ac1 100644
@@ -11901,16 +11901,17 @@ static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	bool is_sfp = false;
 	i40e_status status;
-	uint8_t *data = info->data;
+	uint8_t *data;
 	uint32_t value = 0;
 	uint32_t i;
 
-	if (!info || !info->length || !data)
+	if (!info || !info->length || !info->data)
 		return -EINVAL;
 
 	if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
 		is_sfp = true;
 
+	data = info->data;
 	for (i = 0; i < info->length; i++) {
 		u32 offset = i + info->offset;
 		u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
Signature · 1 line
2.20.1
#25 lore raw
In reply to Bruce Richardson
Quoted 6 lines

Bruce Richardson (5):
examples/vhost_scsi: fix header check for meson build examples/vhost_scsi: fix missing NULL-check for parameter net/i40e: fix dereference before NULL check in mbuf release app/testpmd: fix variable use before NULL check net/i40e: fix dereference before check when getting EEPROM

Applied, thanks