patch-2.1.23 linux/arch/m68k/kernel/sys_m68k.c

Next file: linux/arch/m68k/mm/init.c
Previous file: linux/arch/m68k/kernel/ptrace.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.22/linux/arch/m68k/kernel/sys_m68k.c linux/arch/m68k/kernel/sys_m68k.c
@@ -9,6 +9,8 @@
 #include <linux/errno.h>
 #include <linux/sched.h>
 #include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
 #include <linux/sem.h>
 #include <linux/msg.h>
 #include <linux/shm.h>
@@ -31,15 +33,18 @@
 	int fd[2];
 	int error;
 
+	lock_kernel();
 	error = verify_area(VERIFY_WRITE,fildes,8);
 	if (error)
-		return error;
+		goto out;
 	error = do_pipe(fd);
 	if (error)
-		return error;
+		goto out;
 	put_user(fd[0],0+fildes);
 	put_user(fd[1],1+fildes);
-	return 0;
+out:
+	unlock_kernel();
+	return error;
 }
 
 /*
@@ -64,16 +69,20 @@
 	struct file * file = NULL;
 	struct mmap_arg_struct a;
 
+	lock_kernel();
 	error = verify_area(VERIFY_READ, arg, sizeof(*arg));
 	if (error)
-		return error;
+		goto out;
 	copy_from_user(&a, arg, sizeof(a));
 	if (!(a.flags & MAP_ANONYMOUS)) {
+		error = -EBADF;
 		if (a.fd >= NR_OPEN || !(file = current->files->fd[a.fd]))
-			return -EBADF;
+			goto out;
 	}
 	a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 	error = do_mmap(file, a.addr, a.len, a.prot, a.flags, a.offset);
+out:
+	unlock_kernel();
 	return error;
 }
 
@@ -89,10 +98,15 @@
 asmlinkage int old_select(struct sel_arg_struct *arg)
 {
 	struct sel_arg_struct a;
+	int ret = -EFAULT;
 
+	lock_kernel();
 	if (copy_from_user(&a, arg, sizeof(a)))
-		return -EFAULT;
-	return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
+		goto out;
+	ret = sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
+out:
+	unlock_kernel();
+	return ret;
 }
 
 /*
@@ -102,7 +116,7 @@
  */
 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth)
 {
-	int version;
+	int version, ret;
 
 	version = call >> 16; /* hack for backward compatibility */
 	call &= 0xffff;
@@ -110,46 +124,58 @@
 	if (call <= SEMCTL)
 		switch (call) {
 		case SEMOP:
-			return sys_semop (first, (struct sembuf *)ptr, second);
+			ret = sys_semop (first, (struct sembuf *)ptr, second);
+			goto out;
 		case SEMGET:
-			return sys_semget (first, second, third);
+			ret = sys_semget (first, second, third);
+			goto out;
 		case SEMCTL: {
 			union semun fourth;
-			int err;
+			ret = -EINVAL;
 			if (!ptr)
-				return -EINVAL;
-			if ((err = verify_area (VERIFY_READ, ptr, sizeof(long))))
-				return err;
+				goto out;
+			if ((ret = verify_area (VERIFY_READ, ptr, sizeof(long))))
+				goto out;
 			get_user(fourth.__pad, (void **)ptr);
-			return sys_semctl (first, second, third, fourth);
+			ret = sys_semctl (first, second, third, fourth);
+			goto out;
 			}
 		default:
-			return -EINVAL;
+			ret = -EINVAL;
+			goto out;
 		}
 	if (call <= MSGCTL) 
 		switch (call) {
 		case MSGSND:
-			return sys_msgsnd (first, (struct msgbuf *) ptr, 
-					   second, third);
+			ret = sys_msgsnd (first, (struct msgbuf *) ptr, 
+					  second, third);
+			goto out;
 		case MSGRCV:
 			switch (version) {
 			case 0: {
 				struct ipc_kludge tmp;
+				ret = -EINVAL;
 				if (!ptr)
-					return -EINVAL;
+					goto out;
+				ret = -EFAULT;
 				if (copy_from_user (&tmp, ptr, sizeof (tmp)))
-					return -EFAULT;
-				return sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp, third);
+					goto out;
+				ret = sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp, third);
+				goto out;
 				}
 			case 1: default:
-				return sys_msgrcv (first, (struct msgbuf *) ptr, second, fifth, third);
+				ret = sys_msgrcv (first, (struct msgbuf *) ptr, second, fifth, third);
+				goto out;
 			}
 		case MSGGET:
-			return sys_msgget ((key_t) first, second);
+			ret = sys_msgget ((key_t) first, second);
+			goto out;
 		case MSGCTL:
-			return sys_msgctl (first, second, (struct msqid_ds *) ptr);
+			ret = sys_msgctl (first, second, (struct msqid_ds *) ptr);
+			goto out;
 		default:
-			return -EINVAL;
+			ret = -EINVAL;
+			goto out;
 		}
 	if (call <= SHMCTL) 
 		switch (call) {
@@ -157,30 +183,40 @@
 			switch (version) {
 			case 0: default: {
 				ulong raddr;
-				int err;
-				if ((err = verify_area(VERIFY_WRITE, (ulong*) third, sizeof(ulong))))
-					return err;
-				err = sys_shmat (first, (char *) ptr, second, &raddr);
-				if (err)
-					return err;
+				if ((ret = verify_area(VERIFY_WRITE, (ulong*) third, sizeof(ulong))))
+					goto out;
+				ret = sys_shmat (first, (char *) ptr, second, &raddr);
+				if (ret)
+					goto out;
 				put_user (raddr, (ulong *) third);
-				return 0;
+				ret = 0;
+				goto out;
 				}
 			case 1:	/* iBCS2 emulator entry point */
+				ret = -EINVAL;
 				if (get_fs() != get_ds())
-					return -EINVAL;
-				return sys_shmat (first, (char *) ptr, second, (ulong *) third);
+					goto out;
+				ret = sys_shmat (first, (char *) ptr, second, (ulong *) third);
+				goto out;
 			}
 		case SHMDT: 
-			return sys_shmdt ((char *)ptr);
+			ret = sys_shmdt ((char *)ptr);
+			goto out;
 		case SHMGET:
-			return sys_shmget (first, second, third);
+			ret = sys_shmget (first, second, third);
+			goto out;
 		case SHMCTL:
-			return sys_shmctl (first, second, (struct shmid_ds *) ptr);
+			ret = sys_shmctl (first, second, (struct shmid_ds *) ptr);
+			goto out;
 		default:
-			return -EINVAL;
+			ret = -EINVAL;
+			goto out;
 		}
-	return -EINVAL;
+	else
+		ret = -EINVAL;
+out:
+	unlock_kernel();
+	return ret;
 }
 
 asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int on)
@@ -496,60 +532,63 @@
 asmlinkage int
 sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
 {
-  struct vm_area_struct *vma;
-
-  if (scope < FLUSH_SCOPE_LINE || scope > FLUSH_SCOPE_ALL
-      || cache & ~FLUSH_CACHE_BOTH)
-    return -EINVAL;
+	struct vm_area_struct *vma;
+	int ret = -EINVAL;
 
-  if (scope == FLUSH_SCOPE_ALL)
-    {
-      /* Only the superuser may flush the whole cache. */
-      if (!suser ())
-	return -EPERM;
-    }
-  else
-    {
-      /* Verify that the specified address region actually belongs to
-	 this process.  */
-      vma = find_vma (current->mm, addr);
-      if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end)
-	return -EINVAL;
-    }
+	lock_kernel();
+	if (scope < FLUSH_SCOPE_LINE || scope > FLUSH_SCOPE_ALL ||
+	    cache & ~FLUSH_CACHE_BOTH)
+		goto out;
+
+	if (scope == FLUSH_SCOPE_ALL) {
+		/* Only the superuser may flush the whole cache. */
+		ret = -EPERM;
+		if (!suser ())
+			goto out;
+	} else {
+		/* Verify that the specified address region actually belongs to
+		 * this process.
+		 */
+		vma = find_vma (current->mm, addr);
+		ret = -EINVAL;
+		if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end)
+			goto out;
+	}
 
-  if (CPU_IS_020_OR_030) {
-    if (scope == FLUSH_SCOPE_LINE)
-      {
-	unsigned long cacr;
-	__asm__ ("movec %%cacr, %0" : "=r" (cacr));
-	if (cache & FLUSH_CACHE_INSN)
-	  cacr |= 4;
-	if (cache & FLUSH_CACHE_DATA)
-	  cacr |= 0x400;
-	len >>= 4;
-	while (len--)
-	  {
-	    __asm__ __volatile__ ("movec %1, %%caar\n\t"
-				  "movec %0, %%cacr"
-				  : /* no outputs */
-				  : "r" (cacr), "r" (addr));
-	    addr += 16;
-	  }
-      }
-    else
-      {
-	/* Flush the whole cache, even if page granularity is requested.  */
-	unsigned long cacr;
-	__asm__ ("movec %%cacr, %0" : "=r" (cacr));
-	if (cache & FLUSH_CACHE_INSN)
-	  cacr |= 8;
-	if (cache & FLUSH_CACHE_DATA)
-	  cacr |= 0x800;
-	__asm__ __volatile__ ("movec %0, %%cacr" : : "r" (cacr));
-      }
-    return 0;
-  } else if (CPU_IS_040)
-    return cache_flush_040 (addr, scope, cache, len);
-  else if (CPU_IS_060)
-    return cache_flush_060 (addr, scope, cache, len);
+	if (CPU_IS_020_OR_030) {
+		if (scope == FLUSH_SCOPE_LINE) {
+			unsigned long cacr;
+			__asm__ ("movec %%cacr, %0" : "=r" (cacr));
+			if (cache & FLUSH_CACHE_INSN)
+				cacr |= 4;
+			if (cache & FLUSH_CACHE_DATA)
+				cacr |= 0x400;
+			len >>= 4;
+			while (len--) {
+				__asm__ __volatile__ ("movec %1, %%caar\n\t"
+						      "movec %0, %%cacr"
+						      : /* no outputs */
+						      : "r" (cacr), "r" (addr));
+				addr += 16;
+			}
+		} else {
+			/* Flush the whole cache, even if page granularity requested. */
+			unsigned long cacr;
+			__asm__ ("movec %%cacr, %0" : "=r" (cacr));
+			if (cache & FLUSH_CACHE_INSN)
+				cacr |= 8;
+			if (cache & FLUSH_CACHE_DATA)
+				cacr |= 0x800;
+			__asm__ __volatile__ ("movec %0, %%cacr" : : "r" (cacr));
+		}
+		ret = 0;
+		goto out;
+	} else if (CPU_IS_040) {
+		ret = cache_flush_040 (addr, scope, cache, len);
+	} else if (CPU_IS_060) {
+		ret = cache_flush_060 (addr, scope, cache, len);
+	}
+out:
+	unlock_kernel();
+	return ret;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov