Skip to contentSkip to conversation

pci-assign: Fix warning from coverity (argument cannot be negative)

PATCH In review Stefan Weil 2 participants 2 messages Mar 14, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci-assign: Fix warning from coverity (argument cannot be negative)

Coverity warns because function monitor_fd_param can return a negative value which might be passed to function read.

This won't happen because dev->config_fd will only be negative (-1) when local_err is set.

---
 hw/i386/kvm/pci-assign.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/kvm/pci-assign.c +1 -1
index 9db7c77..f3d145b 100644
@@ -554,7 +554,7 @@ static void get_real_device(AssignedDevice *pci_dev, Error **errp)
     if (pci_dev->configfd_name && *pci_dev->configfd_name) {
         dev->config_fd = monitor_fd_param(cur_mon, pci_dev->configfd_name,
                                           &local_err);
-        if (local_err) {
+        if (dev->config_fd < 0) {
             error_propagate(errp, local_err);
             return;
         }
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 5 lines · Stefan Weil

Coverity warns because function monitor_fd_param can return a negative value which might be passed to function read.

This won't happen because dev->config_fd will only be negative (-1) when local_err is set.

Yes.

Quoted 12 lines
---
 hw/i386/kvm/pci-assign.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/kvm/pci-assign.c +0 -0
index 9db7c77..f3d145b 100644

hw/i386/kvm/pci-assign.c static void get_real_device(AssignedDevice *pci_dev, Error **errp) · line 560

Quoted 8 lines
hw/i386/kvm/pci-assign.c +1 -1
@@ -554,7 +554,7 @@ static void get_real_device(AssignedDevice *pci_dev, Error **errp)
     if (pci_dev->configfd_name && *pci_dev->configfd_name) {
         dev->config_fd = monitor_fd_param(cur_mon, pci_dev->configfd_name,
                                           &local_err);
-        if (local_err) {
+        if (dev->config_fd < 0) {
             error_propagate(errp, local_err);
             return;
         }

This fix the coverity warning of dev->config_id. I'm not sure that this may introduce another warning of not checking local_err.

Signature · 2 lines
Thanks,
Shannon