diff mbox series

[v7,49/74] linux-user: Remove sentinel from ioctl_entries

Message ID 20190519203726.20729-50-richard.henderson@linaro.org
State New
Headers show
Series linux-user: Split do_syscall | expand

Commit Message

Richard Henderson May 19, 2019, 8:37 p.m. UTC
Iterate based on the size of the array instead.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 linux-user/syscall-ioctl.inc.c | 14 +++++++-------
 linux-user/syscall.c           |  6 ++----
 2 files changed, 9 insertions(+), 11 deletions(-)

-- 
2.17.1
diff mbox series

Patch

diff --git a/linux-user/syscall-ioctl.inc.c b/linux-user/syscall-ioctl.inc.c
index 15d87b9663..fc7df62017 100644
--- a/linux-user/syscall-ioctl.inc.c
+++ b/linux-user/syscall-ioctl.inc.c
@@ -773,7 +773,6 @@  static IOCTLEntry ioctl_entries[] = {
 #define IOCTL_IGNORE(cmd)                       \
     { TARGET_ ## cmd, 0, #cmd },
 #include "ioctls.h"
-    { 0, 0, },
 };
 
 /* ??? Implement proper locking for ioctls.  */
@@ -789,16 +788,17 @@  SYSCALL_IMPL(ioctl)
     int target_size;
     void *argptr;
 
-    for (ie = ioctl_entries; ; ie++) {
-        if (ie->target_cmd == 0) {
-            gemu_log("Unsupported ioctl: cmd=0x%04x\n", cmd);
-            return -TARGET_ENOSYS;
-        }
+    for (ie = ioctl_entries;
+         ie < ioctl_entries + ARRAY_SIZE(ioctl_entries);
+         ie++) {
         if (ie->target_cmd == cmd) {
-            break;
+            goto found;
         }
     }
+    gemu_log("Unsupported ioctl: cmd=0x%04x\n", cmd);
+    return -TARGET_ENOSYS;
 
+ found:
     arg_type = ie->arg_type;
     if (ie->do_ioctl) {
         return ie->do_ioctl(ie, buf_temp, fd, cmd, arg);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8f90affe2f..5871d3e711 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8173,7 +8173,6 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 
 void syscall_init(void)
 {
-    IOCTLEntry *ie;
     const argtype *arg_type;
     int size;
     int i;
@@ -8203,8 +8202,8 @@  void syscall_init(void)
      * We patch the ioctl size if necessary.  We rely on the fact that
      * no ioctl has all the bits at '1' in the size field.
      */
-    ie = ioctl_entries;
-    while (ie->target_cmd != 0) {
+    for (i = 0; i < ARRAY_SIZE(ioctl_entries); i++) {
+        IOCTLEntry *ie = &ioctl_entries[i];
         if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) ==
             TARGET_IOC_SIZEMASK) {
             arg_type = ie->arg_type;
@@ -8228,6 +8227,5 @@  void syscall_init(void)
                     ie->name, ie->target_cmd, ie->host_cmd);
         }
 #endif
-        ie++;
     }
 }