libndctl: refactor returns in ndctl_bus_get_scrub_count
Vishal Verma
maintainerPATCH 1/3 libndctl: refactor returns in ndctl_bus_get_scrub_count
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.
--- ndctl/lib/libndctl.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
ndctl/lib/libndctl.c +1 -7
@@ -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 ;
Signature · 6 lines
2.9.5 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH 2/3 libndctl: add missing error handling in _wait_for_scrub_completion
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().
--- ndctl/lib/libndctl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
ndctl/lib/libndctl.c +7 -1
@@ -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 ; }
Signature · 6 lines
2.9.5 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH 3/3 ndctl, inject-error: remove unreachable code
In reply to Vishal VermaThe 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.
--- ndctl/inject-error.c | 3 --- 1 file changed, 3 deletions(-)
ndctl/inject-error.c +0 -3
@@ -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);
Signature · 6 lines
2.9.5 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm