vlib: fix issues in the new pci code reported by coverity
Change-Id: I8acc5c419b6ad01937c3aecec42801463d4a119a
Signed-off-by: Damjan Marion <damarion@cisco.com>
diff --git a/src/vlib/linux/pci.c b/src/vlib/linux/pci.c
index 24e2bb5..69dcdd0 100644
--- a/src/vlib/linux/pci.c
+++ b/src/vlib/linux/pci.c
@@ -259,6 +259,8 @@
}
}
+ close (fd);
+
vec_reset_length (f);
f = format (f, "%v/vpd%c", dev_dir_name, 0);
fd = open ((char *) f, O_RDONLY);
@@ -268,7 +270,7 @@
{
u8 tag[3];
u8 *data = 0;
- int len;
+ uword len;
if (read (fd, &tag, 3) != 3)
break;
@@ -583,8 +585,10 @@
free (s);
if (err)
{
- close (p->config_fd);
- close (p->uio_fd);
+ if (p->config_fd != -1)
+ close (p->config_fd);
+ if (p->uio_fd != -1)
+ close (p->uio_fd);
}
return err;
}
@@ -619,7 +623,7 @@
s = format (s, "/dev/vfio/%u%c", group, 0);
fd = open ((char *) s, O_RDWR);
if (fd < 0)
- clib_error_return_unix (0, "open '%s'", s);
+ return clib_error_return_unix (0, "open '%s'", s);
group_status.argsz = sizeof (group_status);
if (ioctl (fd, VFIO_GROUP_GET_STATUS, &group_status) < 0)
@@ -779,8 +783,10 @@
vec_free (s);
if (err)
{
- close (dfd);
- close (p->config_fd);
+ if (dfd != -1)
+ close (dfd);
+ if (p->config_fd != -1)
+ close (p->config_fd);
}
return err;
}