qemu-trivial
[Top][All Lists]
Advanced

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

[Qemu-trivial] [PATCH] linux-user/syscall.c: Let all lock_user_struct()


From: Chen Gang S
Subject: [Qemu-trivial] [PATCH] linux-user/syscall.c: Let all lock_user_struct() and unlock_user_struct() paired with each other
Date: Sun, 25 Jan 2015 20:06:38 +0800
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.4.0

lock_user_struct() and unlock_user_struct() need always be paired with
each other, or will cause resource leak.

Also remove redundant check for 'target_mb' in abi_long do_msgrcv().

Also match the coding styles found by "./scripts/checkpatch.pl".

Signed-off-by: Chen Gang <address@hidden>
---
 linux-user/syscall.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ec9e4fc..b2da432 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2518,8 +2518,10 @@ static inline abi_long target_to_host_semid_ds(struct 
semid_ds *host_sd,
 
     if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1))
         return -TARGET_EFAULT;
-    if (target_to_host_ipc_perm(&(host_sd->sem_perm),target_addr))
+    if (target_to_host_ipc_perm(&(host_sd->sem_perm), target_addr)) {
+        unlock_user_struct(target_sd, target_addr, 0);
         return -TARGET_EFAULT;
+    }
     host_sd->sem_nsems = tswapal(target_sd->sem_nsems);
     host_sd->sem_otime = tswapal(target_sd->sem_otime);
     host_sd->sem_ctime = tswapal(target_sd->sem_ctime);
@@ -2534,8 +2536,10 @@ static inline abi_long host_to_target_semid_ds(abi_ulong 
target_addr,
 
     if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0))
         return -TARGET_EFAULT;
-    if (host_to_target_ipc_perm(target_addr,&(host_sd->sem_perm)))
+    if (host_to_target_ipc_perm(target_addr, &(host_sd->sem_perm))) {
+        unlock_user_struct(target_sd, target_addr, 0);
         return -TARGET_EFAULT;
+    }
     target_sd->sem_nsems = tswapal(host_sd->sem_nsems);
     target_sd->sem_otime = tswapal(host_sd->sem_otime);
     target_sd->sem_ctime = tswapal(host_sd->sem_ctime);
@@ -2796,8 +2800,10 @@ static inline abi_long target_to_host_msqid_ds(struct 
msqid_ds *host_md,
 
     if (!lock_user_struct(VERIFY_READ, target_md, target_addr, 1))
         return -TARGET_EFAULT;
-    if (target_to_host_ipc_perm(&(host_md->msg_perm),target_addr))
+    if (target_to_host_ipc_perm(&(host_md->msg_perm), target_addr)) {
+        unlock_user_struct(target_md, target_addr, 0);
         return -TARGET_EFAULT;
+    }
     host_md->msg_stime = tswapal(target_md->msg_stime);
     host_md->msg_rtime = tswapal(target_md->msg_rtime);
     host_md->msg_ctime = tswapal(target_md->msg_ctime);
@@ -2817,8 +2823,10 @@ static inline abi_long host_to_target_msqid_ds(abi_ulong 
target_addr,
 
     if (!lock_user_struct(VERIFY_WRITE, target_md, target_addr, 0))
         return -TARGET_EFAULT;
-    if (host_to_target_ipc_perm(target_addr,&(host_md->msg_perm)))
+    if (host_to_target_ipc_perm(target_addr, &(host_md->msg_perm))) {
+        unlock_user_struct(target_md, target_addr, 0);
         return -TARGET_EFAULT;
+    }
     target_md->msg_stime = tswapal(host_md->msg_stime);
     target_md->msg_rtime = tswapal(host_md->msg_rtime);
     target_md->msg_ctime = tswapal(host_md->msg_ctime);
@@ -2953,8 +2961,7 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
     target_mb->mtype = tswapal(host_mb->mtype);
 
 end:
-    if (target_mb)
-        unlock_user_struct(target_mb, msgp, 1);
+    unlock_user_struct(target_mb, msgp, 1);
     g_free(host_mb);
     return ret;
 }
@@ -2966,8 +2973,10 @@ static inline abi_long target_to_host_shmid_ds(struct 
shmid_ds *host_sd,
 
     if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1))
         return -TARGET_EFAULT;
-    if (target_to_host_ipc_perm(&(host_sd->shm_perm), target_addr))
+    if (target_to_host_ipc_perm(&(host_sd->shm_perm), target_addr)) {
+        unlock_user_struct(target_sd, target_addr, 0);
         return -TARGET_EFAULT;
+    }
     __get_user(host_sd->shm_segsz, &target_sd->shm_segsz);
     __get_user(host_sd->shm_atime, &target_sd->shm_atime);
     __get_user(host_sd->shm_dtime, &target_sd->shm_dtime);
@@ -2986,8 +2995,10 @@ static inline abi_long host_to_target_shmid_ds(abi_ulong 
target_addr,
 
     if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0))
         return -TARGET_EFAULT;
-    if (host_to_target_ipc_perm(target_addr, &(host_sd->shm_perm)))
+    if (host_to_target_ipc_perm(target_addr, &(host_sd->shm_perm))) {
+        unlock_user_struct(target_sd, target_addr, 0);
         return -TARGET_EFAULT;
+    }
     __put_user(host_sd->shm_segsz, &target_sd->shm_segsz);
     __put_user(host_sd->shm_atime, &target_sd->shm_atime);
     __put_user(host_sd->shm_dtime, &target_sd->shm_dtime);
-- 
1.9.3



reply via email to

[Prev in Thread] Current Thread [Next in Thread]