[LTP] [PATCH v3 3/4] tst_find_free_loopdev: Check return value of set_dev_loop_path
Edward Liaw
edliaw@google.com
Fri Mar 24 01:24:40 CET 2023
tst_find_free_loopdev does not check the return value of set_dev_loop_path
and will return the last attempted path even if it does not pass a stat
check. Change it to return TBROK if it fails to acquire a loop device.
Signed-off-by: Edward Liaw <edliaw@google.com>
---
lib/tst_device.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/tst_device.c b/lib/tst_device.c
index 2c83fb764..ba46b7613 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -88,8 +88,8 @@ int tst_find_free_loopdev(char *path, size_t path_len)
rc = ioctl(ctl_fd, LOOP_CTL_GET_FREE);
close(ctl_fd);
if (rc >= 0) {
- if (path)
- set_dev_loop_path(rc, path, path_len);
+ if (path && set_dev_loop_path(rc, path, path_len))
+ tst_brkm(TBROK, NULL, "Could not stat loop device %i", rc);
tst_resm(TINFO, "Found free device %d '%s'",
rc, path ?: "");
return rc;
--
2.40.0.348.gf938b09366-goog
More information about the ltp
mailing list