nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [ndctl PATCH 1/3] libndctl: refactor returns in ndctl_bus_get_scrub_count
@ 2017-11-06 23:16 Vishal Verma
  2017-11-06 23:16 ` [ndctl PATCH 2/3] libndctl: add missing error handling in _wait_for_scrub_completion Vishal Verma
  2017-11-06 23:16 ` [ndctl PATCH 3/3] ndctl, inject-error: remove unreachable code Vishal Verma
  0 siblings, 2 replies; 3+ messages in thread
From: Vishal Verma @ 2017-11-06 23:16 UTC (permalink / raw)
  To: linux-nvdimm

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@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@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

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [ndctl PATCH 2/3] libndctl: add missing error handling in _wait_for_scrub_completion
  2017-11-06 23:16 [ndctl PATCH 1/3] libndctl: refactor returns in ndctl_bus_get_scrub_count Vishal Verma
@ 2017-11-06 23:16 ` Vishal Verma
  2017-11-06 23:16 ` [ndctl PATCH 3/3] ndctl, inject-error: remove unreachable code Vishal Verma
  1 sibling, 0 replies; 3+ messages in thread
From: Vishal Verma @ 2017-11-06 23:16 UTC (permalink / raw)
  To: linux-nvdimm

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 --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

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [ndctl PATCH 3/3] ndctl, inject-error: remove unreachable code
  2017-11-06 23:16 [ndctl PATCH 1/3] libndctl: refactor returns in ndctl_bus_get_scrub_count Vishal Verma
  2017-11-06 23:16 ` [ndctl PATCH 2/3] libndctl: add missing error handling in _wait_for_scrub_completion Vishal Verma
@ 2017-11-06 23:16 ` Vishal Verma
  1 sibling, 0 replies; 3+ messages in thread
From: Vishal Verma @ 2017-11-06 23:16 UTC (permalink / raw)
  To: linux-nvdimm

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@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@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

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-06 23:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-06 23:16 [ndctl PATCH 1/3] libndctl: refactor returns in ndctl_bus_get_scrub_count Vishal Verma
2017-11-06 23:16 ` [ndctl PATCH 2/3] libndctl: add missing error handling in _wait_for_scrub_completion Vishal Verma
2017-11-06 23:16 ` [ndctl PATCH 3/3] ndctl, inject-error: remove unreachable code Vishal Verma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).