Found by Fedora's static analysis [1]. [1] https://openscanhub.fedoraproject.org/task/51915/log/device-mapper-multipath-0.11.1-1.fc43/scan-results.html#def43
Signed-off-by: Martin Wilck <mwi...@suse.com> Reviewed-by: Benjamin Marzinski <bmarz...@redhat.com> --- kpartx/kpartx.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c index 46cb76b..a1495e5 100644 --- a/kpartx/kpartx.c +++ b/kpartx/kpartx.c @@ -404,13 +404,6 @@ main(int argc, char **argv){ set_delimiter(mapname, delim); } - fd = open(device, O_RDONLY | O_DIRECT); - - if (fd == -1) { - perror(device); - exit(1); - } - /* add/remove partitions to the kernel devmapper tables */ int r = 0; @@ -429,6 +422,13 @@ main(int argc, char **argv){ goto end; } + fd = open(device, O_RDONLY | O_DIRECT); + + if (fd == -1) { + perror(device); + exit(1); + } + for (i = 0; i < ptct; i++) { ptp = &pts[i]; -- 2.49.0