Skip to contentSkip to conversation

ndctl: fix ordering of closing vs invalidating flush_fd

PATCH In review Vishal Verma 2 participants 2 messages Apr 16, 2018 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Vishal Verma

author maintainer
#0 lore raw

PATCH 1/1 ndctl: fix ordering of closing vs invalidating flush_fd

Static analysis warns that we may be closing a negative 'fd'. Fix this by closing before invalidating the flush_fd with a -1 in add_region()

Fixes commit c64cc15 ("ndctl: add support in libndctl to provide deep flush")
Cc Dave Jiang <[email protected]>
---
 ndctl/lib/libndctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ndctl/lib/libndctl.c +1 -1
index ad5ab9a..59ea82a 100644
@@ -1929,8 +1929,8 @@ static void *add_region(void *parent, int id, const char *region_base)
 
 	perm = strtol(buf, NULL, 0);
 	if (perm == 0) {
-		region->flush_fd = -1;
 		close(region->flush_fd);
+		region->flush_fd = -1;
 	}
 
  out:
Signature · 6 lines
2.14.3

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Vishal Verma

Static analysis warns that we may be closing a negative 'fd'. Fix this by closing before invalidating the flush_fd with a -1 in add_region()

Fixes commit c64cc15 ("ndctl: add support in libndctl to provide deep flush")
Cc Dave Jiang <[email protected]>

Good catch!

Quoted 10 lines
---
 ndctl/lib/libndctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ndctl/lib/libndctl.c +0 -0
index ad5ab9a..59ea82a 100644

ndctl/lib/libndctl.c static void *add_region(void *parent, int id, const char *region_base) · line 1936

Quoted 9 lines
ndctl/lib/libndctl.c +1 -1
@@ -1929,8 +1929,8 @@ static void *add_region(void *parent, int id, const char *region_base)
 
 	perm = strtol(buf, NULL, 0);
 	if (perm == 0) {
-		region->flush_fd = -1;
 		close(region->flush_fd);
+		region->flush_fd = -1;
 	}
 
  out:

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm