Static analysis warns about logically dead/unreachable code since all
options for 'rc' are accounted for. Make this section a bit more succinct,
while fixing both this warning as well as ensuring gcc doesn't warn about
reaching the end of a non-void function.
Cc: Dan Williams <dan.j.williams(a)intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma(a)intel.com>
---
ndctl/lib/libndctl.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 4434846..e78a32c 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1086,13 +1086,7 @@ NDCTL_EXPORT unsigned int ndctl_bus_get_scrub_count(struct
ndctl_bus *bus)
return UINT_MAX;
rc = sscanf(buf, "%u%c", &scrub_count, &in_progress);
- if (rc < 0)
- return UINT_MAX;
- if (rc == 0) {
- /* unable to read scrub count */
- return UINT_MAX;
- }
- if (rc >= 1)
+ if (rc > 0)
return scrub_count;
return UINT_MAX;
--
2.9.5
Show replies by date
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(a)intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma(a)intel.com>
---
ndctl/lib/libndctl.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
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;
}
--
2.9.5
The iteration helper ndctl_namespace_bb_foreach ensures bb cannot be
NULL in the loop, so an explicit check for it is not necessary. Remove
it.
Cc: Dan Williams <dan.j.williams(a)intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma(a)intel.com>
---
ndctl/inject-error.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/ndctl/inject-error.c b/ndctl/inject-error.c
index 4c45902..a05f813 100644
--- a/ndctl/inject-error.c
+++ b/ndctl/inject-error.c
@@ -250,9 +250,6 @@ static int injection_status(struct ndctl_namespace *ndns)
}
ndctl_namespace_bb_foreach(ndns, bb) {
- if (!bb)
- break;
-
block = ndctl_bb_get_block(bb);
count = ndctl_bb_get_count(bb);
jbb = util_badblock_rec_to_json(block, count, ictx.flags);
--
2.9.5