[PATCH 14/18] Make error simpler in reds_stat

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There's no reason for so hard optimisations so avoid
having to maintain multiple labels.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 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

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]