diff options
author | Karel Zak | 2012-06-21 10:40:43 +0200 |
---|---|---|
committer | Karel Zak | 2012-06-21 10:40:43 +0200 |
commit | defa0710b63096f96b5616090c262d30b01bc60c (patch) | |
tree | 78e997be96600df083f7bca8c704c0352605b190 /lib/loopdev.c | |
parent | lib/sysfs: use warn_unused_result for sysfs_init() (diff) | |
download | kernel-qcow2-util-linux-defa0710b63096f96b5616090c262d30b01bc60c.tar.gz kernel-qcow2-util-linux-defa0710b63096f96b5616090c262d30b01bc60c.tar.xz kernel-qcow2-util-linux-defa0710b63096f96b5616090c262d30b01bc60c.zip |
lib/loopdev: use warn_unused_result forimportant functions
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/loopdev.c')
-rw-r--r-- | lib/loopdev.c | 65 |
1 files changed, 41 insertions, 24 deletions
diff --git a/lib/loopdev.c b/lib/loopdev.c index 8e5706735..b759f0c28 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -148,6 +148,7 @@ int loopcxt_has_device(struct loopdev_cxt *lc) */ int loopcxt_init(struct loopdev_cxt *lc, int flags) { + int rc; struct stat st; struct loopdev_cxt dummy = UL_LOOPDEVCXT_EMPTY; @@ -156,7 +157,10 @@ int loopcxt_init(struct loopdev_cxt *lc, int flags) memcpy(lc, &dummy, sizeof(dummy)); lc->flags = flags; - loopcxt_set_device(lc, NULL); + + rc = loopcxt_set_device(lc, NULL); + if (rc) + return rc; if (!(lc->flags & LOOPDEV_FL_NOSYSFS) && get_linux_version() >= KERNEL_VERSION(2,6,37)) @@ -188,7 +192,7 @@ void loopcxt_deinit(struct loopdev_cxt *lc) free(lc->filename); lc->filename = NULL; - loopcxt_set_device(lc, NULL); + ignore_result( loopcxt_set_device(lc, NULL) ); loopcxt_deinit_iterator(lc); errno = errsv; @@ -378,8 +382,8 @@ static int loopiter_set_device(struct loopdev_cxt *lc, const char *device) if ((lc->iter.flags & LOOPITER_FL_FREE) && !used) return 0; - DBG(lc, loopdev_debug("iter: setting device")); - loopcxt_set_device(lc, NULL); + DBG(lc, loopdev_debug("iter: unset device")); + ignore_result( loopcxt_set_device(lc, NULL) ); return 1; } @@ -1274,27 +1278,29 @@ int loopdev_is_autoclear(const char *device) if (!device) return 0; - loopcxt_init(&lc, 0); - loopcxt_set_device(&lc, device); - rc = loopcxt_is_autoclear(&lc); - loopcxt_deinit(&lc); + rc = loopcxt_init(&lc, 0); + if (!rc) + rc = loopcxt_set_device(&lc, device); + if (!rc) + rc = loopcxt_is_autoclear(&lc); + loopcxt_deinit(&lc); return rc; } char *loopdev_get_backing_file(const char *device) { struct loopdev_cxt lc; - char *res; + char *res = NULL; if (!device) return NULL; + if (loopcxt_init(&lc, 0)) + return NULL; + if (loopcxt_set_device(&lc, device) == 0) + res = loopcxt_get_backing_file(&lc); - loopcxt_init(&lc, 0); - loopcxt_set_device(&lc, device); - res = loopcxt_get_backing_file(&lc); loopcxt_deinit(&lc); - return res; } @@ -1311,8 +1317,11 @@ int loopdev_is_used(const char *device, const char *filename, if (!device || !filename) return 0; - loopcxt_init(&lc, 0); - loopcxt_set_device(&lc, device); + rc = loopcxt_init(&lc, 0); + if (!rc) + rc = loopcxt_set_device(&lc, device); + if (rc) + return rc; rc = !stat(filename, &st); rc = loopcxt_is_used(&lc, rc ? &st : NULL, filename, offset, flags); @@ -1329,8 +1338,9 @@ int loopdev_delete(const char *device) if (!device) return -EINVAL; - loopcxt_init(&lc, 0); - rc = loopcxt_set_device(&lc, device); + rc = loopcxt_init(&lc, 0); + if (!rc) + rc = loopcxt_set_device(&lc, device); if (!rc) rc = loopcxt_delete_device(&lc); loopcxt_deinit(&lc); @@ -1377,7 +1387,8 @@ char *loopdev_find_by_backing_file(const char *filename, uint64_t offset, int fl if (!filename) return NULL; - loopcxt_init(&lc, 0); + if (loopcxt_init(&lc, 0)) + return NULL; if (loopcxt_find_by_backing_file(&lc, filename, offset, flags)) res = loopcxt_strdup_device(&lc); loopcxt_deinit(&lc); @@ -1393,12 +1404,14 @@ char *loopdev_find_by_backing_file(const char *filename, uint64_t offset, int fl int loopdev_count_by_backing_file(const char *filename, char **loopdev) { struct loopdev_cxt lc; - int count = 0; + int count = 0, rc; if (!filename) return -1; - loopcxt_init(&lc, 0); + rc = loopcxt_init(&lc, 0); + if (rc) + return rc; if (loopcxt_init_iterator(&lc, LOOPITER_FL_USED)) return -1; @@ -1436,7 +1449,8 @@ static void test_loop_info(const char *device, int flags, int debug) char *p; uint64_t u64; - loopcxt_init(&lc, flags); + if (loopcxt_init(&lc, flags)) + return loopcxt_enable_debug(&lc, debug); if (loopcxt_set_device(&lc, device)) @@ -1462,7 +1476,8 @@ static void test_loop_scan(int flags, int debug) struct loopdev_cxt lc; int rc; - loopcxt_init(&lc, 0); + if (loopcxt_init(&lc, 0)) + return; loopcxt_enable_debug(&lc, debug); if (loopcxt_init_iterator(&lc, flags)) @@ -1488,9 +1503,11 @@ static void test_loop_scan(int flags, int debug) static int test_loop_setup(const char *filename, const char *device, int debug) { struct loopdev_cxt lc; - int rc = 0; + int rc; - loopcxt_init(&lc, 0); + rc = loopcxt_init(&lc, 0); + if (rc) + return rc; loopcxt_enable_debug(&lc, debug); if (device) { |