[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/3] qemu-bridge-helper: Reverse return value settin
From: |
Michal Privoznik |
Subject: |
[Qemu-devel] [PATCH 2/3] qemu-bridge-helper: Reverse return value setting logic in parse_acl_file |
Date: |
Tue, 30 May 2017 10:23:34 +0200 |
Just like in the previous commit, it's better to have just a
single point of exit from a function as we can have cleanup code
just once instead of copying it all over the place.
Signed-off-by: Michal Privoznik <address@hidden>
---
qemu-bridge-helper.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c
index af6613ea18..a7f9bf06cc 100644
--- a/qemu-bridge-helper.c
+++ b/qemu-bridge-helper.c
@@ -65,6 +65,7 @@ static int parse_acl_file(const char *filename, ACLList
*acl_list)
FILE *f;
char line[4096];
ACLRule *acl_rule;
+ int ret = -1;
f = fopen(filename, "r");
if (f == NULL) {
@@ -92,9 +93,8 @@ static int parse_acl_file(const char *filename, ACLList
*acl_list)
if (arg == NULL) {
fprintf(stderr, "Invalid config line:\n %s\n", line);
- fclose(f);
errno = EINVAL;
- return -1;
+ goto cleanup;
}
*arg = 0;
@@ -132,15 +132,16 @@ static int parse_acl_file(const char *filename, ACLList
*acl_list)
parse_acl_file(arg, acl_list);
} else {
fprintf(stderr, "Unknown command `%s'\n", cmd);
- fclose(f);
errno = EINVAL;
- return -1;
+ goto cleanup;
}
}
- fclose(f);
+ ret = 0;
- return 0;
+ cleanup:
+ fclose(f);
+ return ret;
}
static bool has_vnet_hdr(int fd)
--
2.13.0