Skip to contentSkip to conversation

Fix Coverity issues for virtio-pci and vhost-user msg

PATCH Applied Tiwei Bie 2 participants 6 messages Nov 7, 2018 – Nov 9, 2018 Network drivers

lore
Share & tools
lore

Tiwei Bie

author
#0 lore raw

cover Fix Coverity issues for virtio-pci and vhost-user msg

Tiwei Bie (2):
net/virtio: fix unchecked return value
vhost: remove unneeded null pointer check

 drivers/net/virtio/virtio_pci.c | 10 ++++++++--
 lib/librte_vhost/vhost_user.c   |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.19.1
author
#1 lore raw

PATCH 1/2 net/virtio: fix unchecked return value

Coverity issue: 302861

Fixes 6ba1f63b5ab0 ("virtio: support specification 1.0")

---
This patch can't be backported because it depends on the API change introduced by below commit in this release.

commit e8d435f1f3a1 ("bus/pci: harmonize return value of config read")

 drivers/net/virtio/virtio_pci.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_pci.c +8 -2
index 21110cd69..c8883c32e 100644
@@ -614,9 +614,15 @@ virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw)
 			hw->common_cfg = get_cfg_addr(dev, &cap);
 			break;
 		case VIRTIO_PCI_CAP_NOTIFY_CFG:
-			rte_pci_read_config(dev, &hw->notify_off_multiplier,
+			ret = rte_pci_read_config(dev,
+					&hw->notify_off_multiplier,
 					4, pos + sizeof(cap));
-			hw->notify_base = get_cfg_addr(dev, &cap);
+			if (ret != 4)
+				PMD_INIT_LOG(DEBUG,
+					"failed to read notify_off_multiplier, ret %d",
+					ret);
+			else
+				hw->notify_base = get_cfg_addr(dev, &cap);
 			break;
 		case VIRTIO_PCI_CAP_DEVICE_CFG:
 			hw->dev_cfg = get_cfg_addr(dev, &cap);
Signature · 1 line
2.19.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] net/virtio: fix unchecked return value

Quoted 26 lines · Tiwei Bie

Coverity issue: 302861

Fixes 6ba1f63b5ab0 ("virtio: support specification 1.0")

---
This patch can't be backported because it depends on the API change introduced by below commit in this release.

commit e8d435f1f3a1 ("bus/pci: harmonize return value of config read")

  drivers/net/virtio/virtio_pci.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_pci.c +2 -1
index 21110cd69..c8883c32e 100644
@@ -614,9 +614,15 @@ virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw)
  			hw->common_cfg = get_cfg_addr(dev, &cap);
  			break;
  		case VIRTIO_PCI_CAP_NOTIFY_CFG:
-			rte_pci_read_config(dev, &hw->notify_off_multiplier,
+			ret = rte_pci_read_config(dev,
+					&hw->notify_off_multiplier,
  					4, pos + sizeof(cap));

drivers/net/virtio/virtio_pci.c virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw) · line 628

Quoted 10 lines
drivers/net/virtio/virtio_pci.c +6 -1
-			hw->notify_base = get_cfg_addr(dev, &cap);
+			if (ret != 4)
+				PMD_INIT_LOG(DEBUG,
+					"failed to read notify_off_multiplier, ret %d",
+					ret);
+			else
+				hw->notify_base = get_cfg_addr(dev, &cap);
  			break;
  		case VIRTIO_PCI_CAP_DEVICE_CFG:
  			hw->dev_cfg = get_cfg_addr(dev, &cap);

Thanks,
Maxime

author
#3 lore raw

PATCH 2/2 vhost: remove unneeded null pointer check

In reply to Tiwei Bie

The caller will guarantee that msg won't be null. Remove the unneeded null pointer check which caused a Coverity warning.

Coverity issue: 323484

Fixes 8f972312b8f4 ("vhost: support vhost-user")
---
 lib/librte_vhost/vhost_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_vhost/vhost_user.c +1 -1
index cc154f312..3ea64eba6 100644
@@ -1732,7 +1732,7 @@ read_vhost_message(int sockfd, struct VhostUserMsg *msg)
 	if (ret <= 0)
 		return ret;
 
-	if (msg && msg->size) {
+	if (msg->size) {
 		if (msg->size > sizeof(msg->payload)) {
 			RTE_LOG(ERR, VHOST_CONFIG,
 				"invalid msg size: %d\n", msg->size);
Signature · 1 line
2.19.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] vhost: remove unneeded null pointer check

Quoted 19 lines · Tiwei Bie

The caller will guarantee that msg won't be null. Remove the unneeded null pointer check which caused a Coverity warning.

Coverity issue: 323484

Fixes 8f972312b8f4 ("vhost: support vhost-user")
---
  lib/librte_vhost/vhost_user.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_vhost/vhost_user.c +0 -0
index cc154f312..3ea64eba6 100644

lib/librte_vhost/vhost_user.c read_vhost_message(int sockfd, struct VhostUserMsg *msg) · line 1738

Quoted 8 lines
lib/librte_vhost/vhost_user.c +1 -1
@@ -1732,7 +1732,7 @@ read_vhost_message(int sockfd, struct VhostUserMsg *msg)
  	if (ret <= 0)
  		return ret;
 
-	if (msg && msg->size) {
+	if (msg->size) {
  		if (msg->size > sizeof(msg->payload)) {
  			RTE_LOG(ERR, VHOST_CONFIG,
  				"invalid msg size: %d\n", msg->size);

Thanks,
Maxime

#5 lore raw
In reply to Tiwei Bie
Quoted 8 lines · Tiwei Bie

Tiwei Bie (2):
net/virtio: fix unchecked return value
vhost: remove unneeded null pointer check

  drivers/net/virtio/virtio_pci.c | 10 ++++++++--
  lib/librte_vhost/vhost_user.c   |  2 +-
  2 files changed, 9 insertions(+), 3 deletions(-)

Applied to dpdk-next-virtio/master

Thanks,
Maxime