Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[pandora-kernel.git] / arch / mips / kernel / kspd.c
index 29eadd4..998c4ef 100644 (file)
@@ -17,6 +17,7 @@
  */
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/sched.h>
 #include <linux/unistd.h>
 #include <linux/file.h>
 #include <linux/fs.h>
@@ -88,7 +89,7 @@ static int sp_stopping = 0;
 #define MTSP_O_EXCL            0x0800
 #define MTSP_O_BINARY          0x8000
 
-#define SP_VPE 1
+extern int tclimit;
 
 struct apsp_table  {
        int sp;
@@ -117,11 +118,11 @@ struct apsp_table syscall_command_table[] = {
 
 static int sp_syscall(int num, int arg0, int arg1, int arg2, int arg3)
 {
-       register long int _num  __asm__ ("$2") = num;
-       register long int _arg0  __asm__ ("$4") = arg0;
-       register long int _arg1  __asm__ ("$5") = arg1;
-       register long int _arg2  __asm__ ("$6") = arg2;
-       register long int _arg3  __asm__ ("$7") = arg3;
+       register long int _num  __asm__("$2") = num;
+       register long int _arg0  __asm__("$4") = arg0;
+       register long int _arg1  __asm__("$5") = arg1;
+       register long int _arg2  __asm__("$6") = arg2;
+       register long int _arg3  __asm__("$7") = arg3;
 
        mm_segment_t old_fs;
 
@@ -160,8 +161,7 @@ static unsigned int translate_open_flags(int flags)
        int i;
        unsigned int ret = 0;
 
-       for (i = 0; i < (sizeof(open_flags_table) / sizeof(struct apsp_table));
-            i++) {
+       for (i = 0; i < ARRAY_SIZE(open_flags_table); i++) {
                if( (flags & open_flags_table[i].sp) ) {
                        ret |= open_flags_table[i].ap;
                }
@@ -198,7 +198,6 @@ void sp_work_handle_request(void)
        int cmd;
 
        char *vcwd;
-       mm_segment_t old_fs;
        int size;
 
        ret.retval = -1;
@@ -222,11 +221,11 @@ void sp_work_handle_request(void)
                }
        }
 
-       /* Run the syscall at the priviledge of the user who loaded the
+       /* Run the syscall at the privilege of the user who loaded the
           SP program */
 
-       if (vpe_getuid(SP_VPE))
-               sp_setfsuidgid( vpe_getuid(SP_VPE), vpe_getgid(SP_VPE));
+       if (vpe_getuid(tclimit))
+               sp_setfsuidgid(vpe_getuid(tclimit), vpe_getgid(tclimit));
 
        switch (sc.cmd) {
        /* needs the flags argument translating from SDE kit to
@@ -239,15 +238,13 @@ void sp_work_handle_request(void)
        case MTSP_SYSCALL_GETTOD:
                memset(&tz, 0, sizeof(tz));
                if ((ret.retval = sp_syscall(__NR_gettimeofday, (int)&tv,
-                                            (int)&tz, 0,0)) == 0)
+                                            (int)&tz, 0, 0)) == 0)
                ret.retval = tv.tv_sec;
-
-               ret.errno = errno;
                break;
 
        case MTSP_SYSCALL_EXIT:
                list_for_each_entry(n, &kspd_notifylist, list)
-                       n->kspd_sp_exit(SP_VPE);
+                       n->kspd_sp_exit(tclimit);
                sp_stopping = 1;
 
                printk(KERN_DEBUG "KSPD got exit syscall from SP exitcode %d\n",
@@ -257,7 +254,7 @@ void sp_work_handle_request(void)
        case MTSP_SYSCALL_OPEN:
                generic.arg1 = translate_open_flags(generic.arg1);
 
-               vcwd = vpe_getcwd(SP_VPE);
+               vcwd = vpe_getcwd(tclimit);
 
                /* change to the cwd of the process that loaded the SP program */
                old_fs = get_fs();
@@ -279,14 +276,13 @@ void sp_work_handle_request(void)
                if (cmd >= 0) {
                        ret.retval = sp_syscall(cmd, generic.arg0, generic.arg1,
                                                generic.arg2, generic.arg3);
-                       ret.errno = errno;
                } else
                        printk(KERN_WARNING
                               "KSPD: Unknown SP syscall number %d\n", sc.cmd);
                break;
        } /* switch */
 
-       if (vpe_getuid(SP_VPE))
+       if (vpe_getuid(tclimit))
                sp_setfsuidgid( 0, 0);
 
        old_fs = get_fs();
@@ -367,10 +363,9 @@ static void startwork(int vpe)
                }
 
                INIT_WORK(&work, sp_work);
-               queue_work(workqueue, &work);
-       } else
-               queue_work(workqueue, &work);
+       }
 
+       queue_work(workqueue, &work);
 }
 
 static void stopwork(int vpe)
@@ -392,7 +387,7 @@ static int kspd_module_init(void)
 
        notify.start = startwork;
        notify.stop = stopwork;
-       vpe_notify(SP_VPE, &notify);
+       vpe_notify(tclimit, &notify);
 
        return 0;
 }