]> err.no Git - linux-2.6/blobdiff - arch/x86/kernel/ldt_32.c
x86: prepare arch/x86/kernel/ldt_32/64.c for merging
[linux-2.6] / arch / x86 / kernel / ldt_32.c
index e0b2d17f4f10a879758419116a1cadae42f93a71..bb15753abaf276c6189c561d03b942ea84673d8b 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * linux/arch/i386/kernel/ldt.c
- *
  * Copyright (C) 1992 Krishna Balasubramanian and Linus Torvalds
  * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
  */
@@ -19,7 +17,7 @@
 #include <asm/desc.h>
 #include <asm/mmu_context.h>
 
-#ifdef CONFIG_SMP /* avoids "defined but not used" warnig */
+#ifdef CONFIG_SMP
 static void flush_ldt(void *null)
 {
        if (current->active_mm)
@@ -29,26 +27,26 @@ static void flush_ldt(void *null)
 
 static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
 {
-       void *oldldt;
-       void *newldt;
+       void *oldldt, *newldt;
        int oldsize;
 
        if (mincount <= pc->size)
                return 0;
        oldsize = pc->size;
-       mincount = (mincount+511)&(~511);
-       if (mincount*LDT_ENTRY_SIZE > PAGE_SIZE)
-               newldt = vmalloc(mincount*LDT_ENTRY_SIZE);
+       mincount = (mincount + 511) & (~511);
+       if (mincount * LDT_ENTRY_SIZE > PAGE_SIZE)
+               newldt = vmalloc(mincount * LDT_ENTRY_SIZE);
        else
-               newldt = kmalloc(mincount*LDT_ENTRY_SIZE, GFP_KERNEL);
+               newldt = kmalloc(mincount * LDT_ENTRY_SIZE, GFP_KERNEL);
 
        if (!newldt)
                return -ENOMEM;
 
        if (oldsize)
-               memcpy(newldt, pc->ldt, oldsize*LDT_ENTRY_SIZE);
+               memcpy(newldt, pc->ldt, oldsize * LDT_ENTRY_SIZE);
        oldldt = pc->ldt;
-       memset(newldt+oldsize*LDT_ENTRY_SIZE, 0, (mincount-oldsize)*LDT_ENTRY_SIZE);
+       memset(newldt + oldsize * LDT_ENTRY_SIZE, 0,
+              (mincount - oldsize) * LDT_ENTRY_SIZE);
        pc->ldt = newldt;
        wmb();
        pc->size = mincount;
@@ -57,6 +55,7 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
        if (reload) {
 #ifdef CONFIG_SMP
                cpumask_t mask;
+
                preempt_disable();
                load_LDT(pc);
                mask = cpumask_of_cpu(smp_processor_id());
@@ -68,7 +67,7 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
 #endif
        }
        if (oldsize) {
-               if (oldsize*LDT_ENTRY_SIZE > PAGE_SIZE)
+               if (oldsize * LDT_ENTRY_SIZE > PAGE_SIZE)
                        vfree(oldldt);
                else
                        kfree(oldldt);
@@ -79,9 +78,10 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
 static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
 {
        int err = alloc_ldt(new, old->size, 0);
+
        if (err < 0)
                return err;
-       memcpy(new->ldt, old->ldt, old->size*LDT_ENTRY_SIZE);
+       memcpy(new->ldt, old->ldt, old->size * LDT_ENTRY_SIZE);
        return 0;
 }
 
@@ -91,16 +91,16 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
  */
 int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
 {
-       struct mm_struct * old_mm;
+       struct mm_struct *old_mm;
        int retval = 0;
 
-       init_MUTEX(&mm->context.sem);
+       mutex_init(&mm->context.lock);
        mm->context.size = 0;
        old_mm = current->mm;
        if (old_mm && old_mm->context.size > 0) {
-               down(&old_mm->context.sem);
+               mutex_lock(&old_mm->context.lock);
                retval = copy_ldt(&mm->context, &old_mm->context);
-               up(&old_mm->context.sem);
+               mutex_unlock(&old_mm->context.lock);
        }
        return retval;
 }
@@ -113,7 +113,7 @@ void destroy_context(struct mm_struct *mm)
        if (mm->context.size) {
                if (mm == current->active_mm)
                        clear_LDT();
-               if (mm->context.size*LDT_ENTRY_SIZE > PAGE_SIZE)
+               if (mm->context.size * LDT_ENTRY_SIZE > PAGE_SIZE)
                        vfree(mm->context.ldt);
                else
                        kfree(mm->context.ldt);
@@ -121,31 +121,31 @@ void destroy_context(struct mm_struct *mm)
        }
 }
 
-static int read_ldt(void __user * ptr, unsigned long bytecount)
+static int read_ldt(void __user *ptr, unsigned long bytecount)
 {
        int err;
        unsigned long size;
-       struct mm_struct * mm = current->mm;
+       struct mm_struct *mm = current->mm;
 
        if (!mm->context.size)
                return 0;
-       if (bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES)
-               bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES;
+       if (bytecount > LDT_ENTRY_SIZE * LDT_ENTRIES)
+               bytecount = LDT_ENTRY_SIZE * LDT_ENTRIES;
 
-       down(&mm->context.sem);
-       size = mm->context.size*LDT_ENTRY_SIZE;
+       mutex_lock(&mm->context.lock);
+       size = mm->context.size * LDT_ENTRY_SIZE;
        if (size > bytecount)
                size = bytecount;
 
        err = 0;
        if (copy_to_user(ptr, mm->context.ldt, size))
                err = -EFAULT;
-       up(&mm->context.sem);
+       mutex_unlock(&mm->context.lock);
        if (err < 0)
                goto error_return;
        if (size != bytecount) {
                /* zero-fill the rest */
-               if (clear_user(ptr+size, bytecount-size) != 0) {
+               if (clear_user(ptr + size, bytecount - size) != 0) {
                        err = -EFAULT;
                        goto error_return;
                }
@@ -155,13 +155,13 @@ error_return:
        return err;
 }
 
-static int read_default_ldt(void __user * ptr, unsigned long bytecount)
+static int read_default_ldt(void __user *ptr, unsigned long bytecount)
 {
        int err;
        unsigned long size;
 
        err = 0;
-       size = 5*sizeof(struct desc_struct);
+       size = 5 * sizeof(struct desc_struct);
        if (size > bytecount)
                size = bytecount;
 
@@ -172,9 +172,9 @@ static int read_default_ldt(void __user * ptr, unsigned long bytecount)
        return err;
 }
 
-static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
+static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
 {
-       struct mm_struct * mm = current->mm;
+       struct mm_struct *mm = current->mm;
        __u32 entry_1, entry_2;
        int error;
        struct user_desc ldt_info;
@@ -182,7 +182,7 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
        error = -EINVAL;
        if (bytecount != sizeof(ldt_info))
                goto out;
-       error = -EFAULT;        
+       error = -EFAULT;
        if (copy_from_user(&ldt_info, ptr, sizeof(ldt_info)))
                goto out;
 
@@ -196,15 +196,16 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
                        goto out;
        }
 
-       down(&mm->context.sem);
+       mutex_lock(&mm->context.lock);
        if (ldt_info.entry_number >= mm->context.size) {
-               error = alloc_ldt(&current->mm->context, ldt_info.entry_number+1, 1);
+               error = alloc_ldt(&current->mm->context,
+                                 ldt_info.entry_number + 1, 1);
                if (error < 0)
                        goto out_unlock;
        }
 
-       /* Allow LDTs to be cleared by the user. */
-       if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
+       /* Allow LDTs to be cleared by the user. */
+       if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
                if (oldmode || LDT_empty(&ldt_info)) {
                        entry_1 = 0;
                        entry_2 = 0;
@@ -219,16 +220,18 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
 
        /* Install the new entry ...  */
 install:
-       write_ldt_entry(mm->context.ldt, ldt_info.entry_number, entry_1, entry_2);
+       write_ldt_entry(mm->context.ldt, ldt_info.entry_number, entry_1,
+                       entry_2);
        error = 0;
 
 out_unlock:
-       up(&mm->context.sem);
+       mutex_unlock(&mm->context.lock);
 out:
        return error;
 }
 
-asmlinkage int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
+asmlinkage int sys_modify_ldt(int func, void __user *ptr,
+                             unsigned long bytecount)
 {
        int ret = -ENOSYS;