diff --git a/lib/utils_loop.c b/lib/utils_loop.c index 9f6d3075..9b654c85 100644 --- a/lib/utils_loop.c +++ b/lib/utils_loop.c @@ -252,7 +252,12 @@ static char *_sysfs_backing_file(const char *loop) char *crypt_loop_backing_file(const char *loop) { - char *bf = _sysfs_backing_file(loop); + char *bf; + + if (!crypt_loop_device(loop)) + return NULL; + + bf = _sysfs_backing_file(loop); return bf ?: _ioctl_backing_file(loop); } diff --git a/src/cryptsetup.c b/src/cryptsetup.c index 014c154f..593cb159 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -736,8 +736,7 @@ static int action_status(void) log_std(" integrity keysize: %d bits\n", ip.integrity_key_size * 8); device = crypt_get_device_name(cd); log_std(" device: %s\n", device); - if (crypt_loop_device(device)) { - backing_file = crypt_loop_backing_file(device); + if ((backing_file = crypt_loop_backing_file(device))) { log_std(" loop: %s\n", backing_file); free(backing_file); } diff --git a/src/integritysetup.c b/src/integritysetup.c index 6fbe60f4..b0c56a81 100644 --- a/src/integritysetup.c +++ b/src/integritysetup.c @@ -402,15 +402,13 @@ static int action_status(int arg) device = crypt_get_device_name(cd); metadata_device = crypt_get_metadata_device_name(cd); log_std(" device: %s%s\n", device, metadata_device ? " (detached)" : ""); - if (crypt_loop_device(device)) { - backing_file = crypt_loop_backing_file(device); + if ((backing_file = crypt_loop_backing_file(device))) { log_std(" loop: %s\n", backing_file); free(backing_file); } if (metadata_device) { log_std(" metadata device: %s\n", metadata_device); - if (crypt_loop_device(metadata_device)) { - backing_file = crypt_loop_backing_file(metadata_device); + if ((backing_file = crypt_loop_backing_file(metadata_device))) { log_std(" loop: %s\n", backing_file); free(backing_file); } diff --git a/src/veritysetup.c b/src/veritysetup.c index c36a494b..7a4f4abd 100644 --- a/src/veritysetup.c +++ b/src/veritysetup.c @@ -287,8 +287,7 @@ static int action_status(int arg) log_std("\n"); log_std(" data device: %s\n", vp.data_device); - if (crypt_loop_device(vp.data_device)) { - backing_file = crypt_loop_backing_file(vp.data_device); + if ((backing_file = crypt_loop_backing_file(vp.data_device))) { log_std(" data loop: %s\n", backing_file); free(backing_file); } @@ -297,8 +296,7 @@ static int action_status(int arg) "readonly" : "read/write"); log_std(" hash device: %s\n", vp.hash_device); - if (crypt_loop_device(vp.hash_device)) { - backing_file = crypt_loop_backing_file(vp.hash_device); + if ((backing_file = crypt_loop_backing_file(vp.hash_device))) { log_std(" hash loop: %s\n", backing_file); free(backing_file); } @@ -307,8 +305,7 @@ static int action_status(int arg) if (vp.fec_device) { log_std(" FEC device: %s\n", vp.fec_device); - if (crypt_loop_device(vp.fec_device)) { - backing_file = crypt_loop_backing_file(vp.fec_device); + if ((backing_file = crypt_loop_backing_file(vp.fec_device))) { log_std(" FEC loop: %s\n", backing_file); free(backing_file); }