@@ -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;
}
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(-)