diff mbox

[ndctl,2/3] libndctl: add missing error handling in _wait_for_scrub_completion

Message ID 20171106231610.8271-2-vishal.l.verma@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Verma, Vishal L Nov. 6, 2017, 11:16 p.m. UTC
Static analysis complains that we could be passing a negative value to
close(). The root of the problem is that we neglect to error-check the
return from open(). Add that to correctly fix the problem. Also fix a
whitespace error in close().

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/lib/libndctl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index e78a32c..6737705 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1114,6 +1114,12 @@  NDCTL_EXPORT int ndctl_bus_wait_for_scrub_completion(struct ndctl_bus *bus)
 	int fd = 0, rc;
 
 	fd = open(bus->scrub_path, O_RDONLY|O_CLOEXEC);
+	if (fd < 0) {
+		err(ctx, "failed to open %s: %s\n", bus->scrub_path,
+			strerror(errno));
+		return -errno;
+	}
+
 	fds.fd = fd;
 	fds.events =  POLLPRI | POLLIN;
 	do {
@@ -1154,7 +1160,7 @@  NDCTL_EXPORT int ndctl_bus_wait_for_scrub_completion(struct ndctl_bus *bus)
 
 	dbg(ctx, "bus%d: scrub complete\n", ndctl_bus_get_id(bus));
 	if (fd)
-		close (fd);
+		close(fd);
 	return rc < 0 ? -ENXIO : 0;
 }