group statfs&fstatfs together, eliminate goto into
a different case label, eliminate struct statfs global
to all syscalls.  Ditto for statfs64.

This makes code more readable and less scattered.

While at it, drop `#ifdef TARGET_NR_fstatfs` -- assume fstatfs()
is present together with statfs() - just like for fstatfs64.

Signed-off-by: Michael Tokarev <[email protected]>
---
 linux-user/syscall.c | 62 +++++++++++++++++++++++---------------------
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index d32299dddb..1f84c296d5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9457,10 +9457,6 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int 
num, abi_long arg1,
     || defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64) \
     || defined(TARGET_NR_statx)
     struct stat st;
-#endif
-#if defined(TARGET_NR_statfs) || defined(TARGET_NR_statfs64) \
-    || defined(TARGET_NR_fstatfs)
-    struct statfs stfs;
 #endif
     void *p;
 
@@ -10978,15 +10974,22 @@ static abi_long do_syscall1(CPUArchState *cpu_env, 
int num, abi_long arg1,
         return get_errno(setpriority(arg1, arg2, arg3));
 #ifdef TARGET_NR_statfs
     case TARGET_NR_statfs:
-        if (!(p = lock_user_string(arg1))) {
-            return -TARGET_EFAULT;
-        }
-        ret = get_errno(statfs(path(p), &stfs));
-        unlock_user(p, arg1, 0);
-    convert_statfs:
-        if (!is_error(ret)) {
+    case TARGET_NR_fstatfs:
+        {
+            struct statf stfs;
             struct target_statfs *target_stfs;
-
+            if (num == TARGET_NR_statfs) {
+                if (!(p = lock_user_string(arg1))) {
+                    return -TARGET_EFAULT;
+                }
+                ret = get_errno(statfs(path(p), &stfs));
+                unlock_user(p, arg1, 0);
+            } else /* if (num == TARGET_NR_fstatfs) */ {
+                ret = get_errno(fstatfs(arg1, &stfs));
+            }
+            if (is_error(ret)) {
+                return ret;
+            }
             if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg2, 0))
                 return -TARGET_EFAULT;
             __put_user(stfs.f_type, &target_stfs->f_type);
@@ -11003,25 +11006,27 @@ static abi_long do_syscall1(CPUArchState *cpu_env, 
int num, abi_long arg1,
             __put_user(stfs.f_flags, &target_stfs->f_flags);
             memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare));
             unlock_user_struct(target_stfs, arg2, 1);
+            return ret;
         }
-        return ret;
-#endif
-#ifdef TARGET_NR_fstatfs
-    case TARGET_NR_fstatfs:
-        ret = get_errno(fstatfs(arg1, &stfs));
-        goto convert_statfs;
 #endif
 #ifdef TARGET_NR_statfs64
     case TARGET_NR_statfs64:
-        if (!(p = lock_user_string(arg1))) {
-            return -TARGET_EFAULT;
-        }
-        ret = get_errno(statfs(path(p), &stfs));
-        unlock_user(p, arg1, 0);
-    convert_statfs64:
-        if (!is_error(ret)) {
+    case TARGET_NR_fstatfs64:
+        {
+            struct statfs stfs;
             struct target_statfs64 *target_stfs;
-
+            if (num == TARGET_NR_statfs64) {
+                if (!(p = lock_user_string(arg1))) {
+                    return -TARGET_EFAULT;
+                }
+                ret = get_errno(statfs(path(p), &stfs));
+                unlock_user(p, arg1, 0);
+                } else /* if (num == TARGET_NR_fstatfs64) */ {
+                ret = get_errno(fstatfs(arg1, &stfs));
+            }
+            if (is_error(ret)) {
+                return ret;
+            }
             if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg3, 0))
                 return -TARGET_EFAULT;
             __put_user(stfs.f_type, &target_stfs->f_type);
@@ -11038,11 +11043,8 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int 
num, abi_long arg1,
             __put_user(stfs.f_flags, &target_stfs->f_flags);
             memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare));
             unlock_user_struct(target_stfs, arg3, 1);
+            return ret;
         }
-        return ret;
-    case TARGET_NR_fstatfs64:
-        ret = get_errno(fstatfs(arg1, &stfs));
-        goto convert_statfs64;
 #endif
 #ifdef TARGET_NR_socketcall
     case TARGET_NR_socketcall:
-- 
2.47.3


Reply via email to