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

Message ID 20181107090102.9364-2-tiwei.bie@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series Fix Coverity issues for virtio-pci and vhost-user msg |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Tiwei Bie Nov. 7, 2018, 9:01 a.m. UTC
  Coverity issue: 302861
Fixes: 6ba1f63b5ab0 ("virtio: support specification 1.0")

Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
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(-)
  

Comments

Maxime Coquelin Nov. 9, 2018, 11:38 a.m. UTC | #1
On 11/7/18 10:01 AM, Tiwei Bie wrote:
> Coverity issue: 302861
> Fixes: 6ba1f63b5ab0 ("virtio: support specification 1.0")
> 
> Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
> ---
> 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(-)
> 
> diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
> index 21110cd69..c8883c32e 100644
> --- a/drivers/net/virtio/virtio_pci.c
> +++ b/drivers/net/virtio/virtio_pci.c
> @@ -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);
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  

Patch

diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
index 21110cd69..c8883c32e 100644
--- a/drivers/net/virtio/virtio_pci.c
+++ b/drivers/net/virtio/virtio_pci.c
@@ -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);