[Spice-devel] [PATCH 14/18] Make error simpler in reds_stat
Frediano Ziglio
fziglio at redhat.com
Mon Sep 26 08:12:47 UTC 2016
There's no reason for so hard optimisations so avoid
having to maintain multiple labels.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
tools/reds_stat.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/tools/reds_stat.c b/tools/reds_stat.c
index 07fd732..945659e 100644
--- a/tools/reds_stat.c
+++ b/tools/reds_stat.c
@@ -31,7 +31,7 @@
#define VALUE_TABS 7
#define INVALID_STAT_REF (~(uint32_t)0)
-static SpiceStat *reds_stat = NULL;
+static SpiceStat *reds_stat = (SpiceStat *)MAP_FAILED;
static uint64_t *values = NULL;
static inline void ignore_result(int res)
@@ -90,15 +90,15 @@ int main(int argc, char **argv)
reds_stat = (SpiceStat *)mmap(NULL, shm_size, PROT_READ, MAP_SHARED, fd, 0);
if (reds_stat == (SpiceStat *)MAP_FAILED) {
perror("mmap");
- goto error1;
+ goto error;
}
if (reds_stat->magic != SPICE_STAT_MAGIC) {
printf("bad magic %u\n", reds_stat->magic);
- goto error2;
+ goto error;
}
if (reds_stat->version != SPICE_STAT_VERSION) {
printf("bad version %u\n", reds_stat->version);
- goto error2;
+ goto error;
}
while (1) {
ignore_result(system("clear"));
@@ -110,12 +110,12 @@ int main(int argc, char **argv)
reds_stat = mremap(reds_stat, shm_old_size, shm_size, MREMAP_MAYMOVE);
if (reds_stat == (SpiceStat *)MAP_FAILED) {
perror("mremap");
- goto error3;
+ goto error;
}
values = (uint64_t *)realloc(values, num_of_nodes * sizeof(uint64_t));
if (values == NULL) {
perror("realloc");
- goto error3;
+ goto error;
}
memset(values, 0, num_of_nodes * sizeof(uint64_t));
}
@@ -124,11 +124,11 @@ int main(int argc, char **argv)
}
ret = 0;
-error3:
+error:
free(values);
-error2:
- munmap(reds_stat, shm_size);
-error1:
+ if (reds_stat != (SpiceStat *)MAP_FAILED) {
+ munmap(reds_stat, shm_size);
+ }
shm_unlink(shm_name);
free(shm_name);
return ret;
--
2.7.4
More information about the Spice-devel
mailing list