summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-12-06 05:19:03 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2017-12-06 13:19:03 +0900
commit93719c6b0e96dd59e2c1fcb40b5259f055841803 (patch)
tree159fa4d90ecab710fe3fa9c74e3d64269a120f65 /src/basic
parenta0605ddfcfd0916d382323d53f78550c1151ec6b (diff)
downloadsystemd-93719c6b0e96dd59e2c1fcb40b5259f055841803.tar.gz
systemd-93719c6b0e96dd59e2c1fcb40b5259f055841803.tar.bz2
systemd-93719c6b0e96dd59e2c1fcb40b5259f055841803.zip
mount-util: shorten the loop a bit (#7545)
The loop preparation and part of the loop contents are actually the same, let's merge this. Also, it's so much fun tweaking around in the name_to_handle_at() code, let's do more of it with this patch! (This also adds two NULL assignments, that aren't strictly necessary. However, I figured its safer to place them in there, just in case the for() condition is changed later. After all the freeing of the handle and the invalidation of the cleanup-controller pointer to it are otherwise really far away from each other...)
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/mount-util.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c
index 7f8b53f2b5..f8d615dd89 100644
--- a/src/basic/mount-util.c
+++ b/src/basic/mount-util.c
@@ -55,7 +55,7 @@ int name_to_handle_at_loop(
int *ret_mnt_id,
int flags) {
- _cleanup_free_ struct file_handle *h;
+ _cleanup_free_ struct file_handle *h = NULL;
size_t n = ORIGINAL_MAX_HANDLE_SZ;
/* We need to invoke name_to_handle_at() in a loop, given that it might return EOVERFLOW when the specified
@@ -65,15 +65,15 @@ int name_to_handle_at_loop(
* This improves on raw name_to_handle_at() also in one other regard: ret_handle and ret_mnt_id can be passed
* as NULL if there's no interest in either. */
- h = malloc0(offsetof(struct file_handle, f_handle) + n);
- if (!h)
- return -ENOMEM;
-
- h->handle_bytes = n;
-
for (;;) {
int mnt_id = -1;
+ h = malloc0(offsetof(struct file_handle, f_handle) + n);
+ if (!h)
+ return -ENOMEM;
+
+ h->handle_bytes = n;
+
if (name_to_handle_at(fd, path, h, &mnt_id, flags) >= 0) {
if (ret_handle) {
@@ -110,12 +110,7 @@ int name_to_handle_at_loop(
if (offsetof(struct file_handle, f_handle) + n < n) /* check for addition overflow */
return -EOVERFLOW;
- free(h);
- h = malloc0(offsetof(struct file_handle, f_handle) + n);
- if (!h)
- return -ENOMEM;
-
- h->handle_bytes = n;
+ h = mfree(h);
}
}