All of lore.kernel.org
 help / color / mirror / Atom feed
From: imp@bsdimp.com
To: qemu-devel@nongnu.org
Cc: kevans@freebsd.org, arichardson@freebsd.org,
	Warner Losh <imp@bsdimp.com>
Subject: [PATCH v2 31/48] bsd-user: style tweak: use {} for all if statements, format else correctly
Date: Sat, 24 Apr 2021 09:59:59 -0600	[thread overview]
Message-ID: <20210424160016.15200-32-imp@bsdimp.com> (raw)
In-Reply-To: <20210424160016.15200-1-imp@bsdimp.com>

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/mmap.c | 112 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 74 insertions(+), 38 deletions(-)

diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index 0ff06d7349..1aec1916c0 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -48,17 +48,19 @@ bool have_mmap_lock(void)
 /* Grab lock to make sure things are in a consistent state after fork().  */
 void mmap_fork_start(void)
 {
-    if (mmap_lock_count)
+    if (mmap_lock_count) {
         abort();
+    }
     pthread_mutex_lock(&mmap_mutex);
 }
 
 void mmap_fork_end(int child)
 {
-    if (child)
+    if (child) {
         pthread_mutex_init(&mmap_mutex, NULL);
-    else
+    } else {
         pthread_mutex_unlock(&mmap_mutex);
+    }
 }
 
 /* NOTE: all the constants are the HOST ones, but addresses are target. */
@@ -75,15 +77,18 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
            prot & PROT_EXEC ? 'x' : '-');
 #endif
 
-    if ((start & ~TARGET_PAGE_MASK) != 0)
+    if ((start & ~TARGET_PAGE_MASK) != 0) {
         return -EINVAL;
+    }
     len = TARGET_PAGE_ALIGN(len);
     end = start + len;
-    if (end < start)
+    if (end < start) {
         return -EINVAL;
+    }
     prot &= PROT_READ | PROT_WRITE | PROT_EXEC;
-    if (len == 0)
+    if (len == 0) {
         return 0;
+    }
 
     mmap_lock();
     host_start = start & qemu_host_page_mask;
@@ -102,8 +107,9 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
         }
         ret = mprotect(g2h_untagged(host_start),
                        qemu_host_page_size, prot1 & PAGE_BITS);
-        if (ret != 0)
+        if (ret != 0) {
             goto error;
+        }
         host_start += qemu_host_page_size;
     }
     if (end < host_end) {
@@ -113,16 +119,18 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
         }
         ret = mprotect(g2h_untagged(host_end - qemu_host_page_size),
                        qemu_host_page_size, prot1 & PAGE_BITS);
-        if (ret != 0)
+        if (ret != 0) {
             goto error;
+        }
         host_end -= qemu_host_page_size;
     }
 
     /* handle the pages in the middle */
     if (host_start < host_end) {
         ret = mprotect(g2h_untagged(host_start), host_end - host_start, prot);
-        if (ret != 0)
+        if (ret != 0) {
             goto error;
+        }
     }
     page_set_flags(start, start + len, prot | PAGE_VALID);
     mmap_unlock();
@@ -147,16 +155,18 @@ static int mmap_frag(abi_ulong real_start,
     /* get the protection of the target pages outside the mapping */
     prot1 = 0;
     for (addr = real_start; addr < real_end; addr++) {
-        if (addr < start || addr >= end)
+        if (addr < start || addr >= end) {
             prot1 |= page_get_flags(addr);
+        }
     }
 
     if (prot1 == 0) {
         /* no page was there, so we allocate one */
         void *p = mmap(host_start, qemu_host_page_size, prot,
                        flags | MAP_ANON, -1, 0);
-        if (p == MAP_FAILED)
+        if (p == MAP_FAILED) {
             return -1;
+        }
         prot1 = prot;
     }
     prot1 &= PAGE_BITS;
@@ -168,19 +178,22 @@ static int mmap_frag(abi_ulong real_start,
          * while it is a shared mapping
          */
         if ((flags & TARGET_BSD_MAP_FLAGMASK) == MAP_SHARED &&
-            (prot & PROT_WRITE))
+            (prot & PROT_WRITE)) {
             return -1;
+        }
 
         /* adjust protection to be able to read */
-        if (!(prot1 & PROT_WRITE))
+        if (!(prot1 & PROT_WRITE)) {
             mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE);
+        }
 
         /* read the corresponding file data */
         pread(fd, g2h_untagged(start), end - start, offset);
 
         /* put final protection */
-        if (prot_new != (prot1 | PROT_WRITE))
+        if (prot_new != (prot1 | PROT_WRITE)) {
             mprotect(host_start, qemu_host_page_size, prot_new);
+        }
     } else {
         /* just update the protection */
         if (prot_new != prot1) {
@@ -224,23 +237,27 @@ static abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size)
     size = HOST_PAGE_ALIGN(size);
     start = start & qemu_host_page_mask;
     addr = start;
-    if (addr == 0)
+    if (addr == 0) {
         addr = mmap_next_start;
+    }
     addr_start = addr;
     for (;;) {
         prot = 0;
         for (addr1 = addr; addr1 < (addr + size); addr1 += TARGET_PAGE_SIZE) {
             prot |= page_get_flags(addr1);
         }
-        if (prot == 0)
+        if (prot == 0) {
             break;
+        }
         addr += qemu_host_page_size;
         /* we found nothing */
-        if (addr == addr_start)
+        if (addr == addr_start) {
             return (abi_ulong)-1;
+        }
     }
-    if (start == 0)
+    if (start == 0) {
         mmap_next_start = addr + size;
+    }
     return addr;
 }
 
@@ -260,10 +277,12 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
                prot & PROT_READ ? 'r' : '-',
                prot & PROT_WRITE ? 'w' : '-',
                prot & PROT_EXEC ? 'x' : '-');
-        if (flags & MAP_FIXED)
+        if (flags & MAP_FIXED) {
             printf("MAP_FIXED ");
-        if (flags & MAP_ANON)
+        }
+        if (flags & MAP_ANON) {
             printf("MAP_ANON ");
+        }
         switch (flags & TARGET_BSD_MAP_FLAGMASK) {
         case MAP_PRIVATE:
             printf("MAP_PRIVATE ");
@@ -285,8 +304,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
     }
 
     len = TARGET_PAGE_ALIGN(len);
-    if (len == 0)
+    if (len == 0) {
         goto the_end;
+    }
     real_start = start & qemu_host_page_mask;
 
     if (!(flags & MAP_FIXED)) {
@@ -306,12 +326,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
          */
         p = mmap(g2h_untagged(mmap_start),
                  host_len, prot, flags | MAP_FIXED, fd, host_offset);
-        if (p == MAP_FAILED)
+        if (p == MAP_FAILED) {
             goto fail;
+        }
         /* update start so that it points to the file position at 'offset' */
         host_start = (unsigned long)p;
-        if (!(flags & MAP_ANON))
+        if (!(flags & MAP_ANON)) {
             host_start += offset - host_offset;
+        }
         start = h2g(host_start);
     } else {
         int flg;
@@ -350,8 +372,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
             retaddr = target_mmap(start, len, prot | PROT_WRITE,
                                   MAP_FIXED | MAP_PRIVATE | MAP_ANON,
                                   -1, 0);
-            if (retaddr == -1)
+            if (retaddr == -1) {
                 goto fail;
+            }
             pread(fd, g2h_untagged(start), len, offset);
             if (!(prot & PROT_WRITE)) {
                 ret = target_mprotect(start, len, prot);
@@ -369,14 +392,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
                 /* one single host page */
                 ret = mmap_frag(real_start, start, end,
                                 prot, flags, fd, offset);
-                if (ret == -1)
+                if (ret == -1) {
                     goto fail;
+                }
                 goto the_end1;
             }
             ret = mmap_frag(real_start, start, real_start + qemu_host_page_size,
                             prot, flags, fd, offset);
-            if (ret == -1)
+            if (ret == -1) {
                 goto fail;
+            }
             real_start += qemu_host_page_size;
         }
         /* handle the end of the mapping */
@@ -385,8 +410,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
                             real_end - qemu_host_page_size, real_end,
                             prot, flags, fd,
                             offset + real_end - qemu_host_page_size - start);
-            if (ret == -1)
+            if (ret == -1) {
                 goto fail;
+            }
             real_end -= qemu_host_page_size;
         }
 
@@ -394,14 +420,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
         if (real_start < real_end) {
             void *p;
             unsigned long offset1;
-            if (flags & MAP_ANON)
+            if (flags & MAP_ANON) {
                 offset1 = 0;
-            else
+            } else {
                 offset1 = offset + real_start - start;
+            }
             p = mmap(g2h_untagged(real_start), real_end - real_start,
                      prot, flags, fd, offset1);
-            if (p == MAP_FAILED)
+            if (p == MAP_FAILED) {
                 goto fail;
+            }
         }
     }
  the_end1:
@@ -427,11 +455,13 @@ int target_munmap(abi_ulong start, abi_ulong len)
 #ifdef DEBUG_MMAP
     printf("munmap: start=0x%lx len=0x%lx\n", start, len);
 #endif
-    if (start & ~TARGET_PAGE_MASK)
+    if (start & ~TARGET_PAGE_MASK) {
         return -EINVAL;
+    }
     len = TARGET_PAGE_ALIGN(len);
-    if (len == 0)
+    if (len == 0) {
         return -EINVAL;
+    }
     mmap_lock();
     end = start + len;
     real_start = start & qemu_host_page_mask;
@@ -449,16 +479,18 @@ int target_munmap(abi_ulong start, abi_ulong len)
             }
             end = real_end;
         }
-        if (prot != 0)
+        if (prot != 0) {
             real_start += qemu_host_page_size;
+        }
     }
     if (end < real_end) {
         prot = 0;
         for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
             prot |= page_get_flags(addr);
         }
-        if (prot != 0)
+        if (prot != 0) {
             real_end -= qemu_host_page_size;
+        }
     }
 
     ret = 0;
@@ -467,8 +499,9 @@ int target_munmap(abi_ulong start, abi_ulong len)
         ret = munmap(g2h_untagged(real_start), real_end - real_start);
     }
 
-    if (ret == 0)
+    if (ret == 0) {
         page_set_flags(start, start + len, 0);
+    }
     mmap_unlock();
     return ret;
 }
@@ -477,14 +510,17 @@ int target_msync(abi_ulong start, abi_ulong len, int flags)
 {
     abi_ulong end;
 
-    if (start & ~TARGET_PAGE_MASK)
+    if (start & ~TARGET_PAGE_MASK) {
         return -EINVAL;
+    }
     len = TARGET_PAGE_ALIGN(len);
     end = start + len;
-    if (end < start)
+    if (end < start) {
         return -EINVAL;
-    if (end == start)
+    }
+    if (end == start) {
         return 0;
+    }
 
     start &= qemu_host_page_mask;
     return msync(g2h_untagged(start), end - start, flags);
-- 
2.22.1



  parent reply	other threads:[~2021-04-24 16:27 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
2021-04-24 15:59 ` [PATCH v2 01/48] bsd-user: whitespace changes imp
2021-04-24 15:59 ` [PATCH v2 02/48] " imp
2021-04-24 15:59 ` [PATCH v2 03/48] " imp
2021-04-24 15:59 ` [PATCH v2 04/48] bsd-user: style tweak: keyword space ( imp
2021-04-24 15:59 ` [PATCH v2 05/48] " imp
2021-04-24 15:59 ` [PATCH v2 06/48] " imp
2021-04-24 15:59 ` [PATCH v2 07/48] " imp
2021-04-24 15:59 ` [PATCH v2 08/48] bsd-user: style tweak: use C not C++ comments imp
2021-04-24 15:59 ` [PATCH v2 09/48] " imp
2021-04-24 15:59 ` [PATCH v2 10/48] bsd-user: Remove commented out code imp
2021-04-24 17:19   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 11/48] bsd-user: style tweak: Remove #if 0'd code imp
2021-04-24 17:21   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 12/48] " imp
2021-04-24 17:23   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 13/48] " imp
2021-04-24 17:23   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 14/48] " imp
2021-04-24 17:24   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 15/48] bsd-user: style tweak: return is not a function, eliminate () imp
2021-04-24 17:24   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 16/48] bsd-user: style tweak: Put {} around all if/else/for statements imp
2021-04-24 17:25   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 17/48] bsd-user: style tweak: Fix commentary issues imp
2021-04-24 15:59 ` [PATCH v2 18/48] bsd-user: style tweak: Use preferred block comments imp
2021-04-24 15:59 ` [PATCH v2 19/48] bsd-user: style tweak: move extern to header file imp
2021-04-24 15:59 ` [PATCH v2 20/48] bsd-user: style tweak: use {} consistently in for / if / else statements imp
2021-04-24 15:59 ` [PATCH v2 21/48] bsd-user: style nits: return is not a function imp
2021-04-24 17:27   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 22/48] bsd-user: use qemu_strtoul in preference to strtol imp
2021-04-24 17:34   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 23/48] bsd-user: introduce host_os.h for bsd-specific code and defaults imp
2021-04-24 15:59 ` [PATCH v2 24/48] bsd-user: create target_arch_cpu.h imp
2021-04-24 15:59 ` [PATCH v2 25/48] bsd-user: move x86 (i386 and x86_64) cpu_loop to target_arch_cpu.h imp
2021-04-24 17:43   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 26/48] bsd-user: move sparc cpu_loop into target_arch_cpu.h as target_cpu_loop imp
2021-04-24 17:45   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 27/48] bsd-user: style tweak: space pedantry imp
2021-04-24 17:46   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 28/48] bsd-user: style tweak: comments imp
2021-04-24 17:51   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 29/48] bsd-user: style tweak: use {} correctly imp
2021-04-24 17:55   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 30/48] bsd-user: style tweak: fix block comments imp
2021-04-24 17:59   ` Richard Henderson
2021-04-24 15:59 ` imp [this message]
2021-04-24 18:01   ` [PATCH v2 31/48] bsd-user: style tweak: use {} for all if statements, format else correctly Richard Henderson
2021-04-24 16:00 ` [PATCH v2 32/48] bsd-user: style tweak: remove spacing after '*' and add after } imp
2021-04-24 18:03   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 33/48] bsd-user: style tweak: Use preferred block comments imp
2021-04-24 18:07   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 34/48] bsd-user: style tweak: don't assign in if statements imp
2021-04-24 18:09   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 35/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
2021-04-24 18:12   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 36/48] bsd-user: style tweak: Use preferred block comments imp
2021-04-24 18:13   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 37/48] bsd-user: style tweak: don't assign in if statements imp
2021-04-24 18:14   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 38/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
2021-04-24 18:15   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 39/48] bsd-user: style tweak: spaces around =, remove stray space imp
2021-04-24 18:16   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 40/48] bsd-user: style tweak: Use preferred block comments imp
2021-04-24 18:16   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 41/48] bsd-user: style tweak: don't assign in if statements imp
2021-04-24 18:17   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 42/48] bsd-user: style tweak: spaces around operators and commas imp
2021-04-24 18:18   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 43/48] bsd-user: style tweak: fold long lines imp
2021-04-24 18:18   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 44/48] bsd-user: style tweak: use preferred block comments imp
2021-04-24 18:19   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 45/48] bsd-user: style tweak: Use preferred {} in if/else statements imp
2021-04-24 18:21   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 46/48] bsd-user: style tweak: Return is not a function call imp
2021-04-24 18:21   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 47/48] bsd-user: style tweak: don't assign in if statement imp
2021-04-24 18:21   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 48/48] bsd-user: put back a break; that had gone missing imp
2021-04-24 18:22   ` Richard Henderson
2021-04-24 16:55 ` [PATCH v2 00/48] bsd-user style and reorg patches no-reply
2021-04-24 17:00   ` Warner Losh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210424160016.15200-32-imp@bsdimp.com \
    --to=imp@bsdimp.com \
    --cc=arichardson@freebsd.org \
    --cc=kevans@freebsd.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.