diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2008-01-30 07:30:13 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-01-30 07:30:13 -0500 |
commit | 78aa1f66f77da078357bd263fcac95fbf6bca15b (patch) | |
tree | ca42e3ed0d6ed3359c3c3c88f539caaa7740f51f /arch/x86/kernel/ldt_64.c | |
parent | 2f36fa13ce49ffd000249feaedfcbefbcc83a72f (diff) |
x86: clean up arch/x86/kernel/ldt_32/64.c
White space and coding style clenaup.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86/kernel/ldt_64.c')
-rw-r--r-- | arch/x86/kernel/ldt_64.c | 69 |
1 files changed, 36 insertions, 33 deletions
diff --git a/arch/x86/kernel/ldt_64.c b/arch/x86/kernel/ldt_64.c index 60e57abb8e90..6c41db367de8 100644 --- a/arch/x86/kernel/ldt_64.c +++ b/arch/x86/kernel/ldt_64.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * Copyright (C) 1992 Krishna Balasubramanian and Linus Torvalds | 2 | * Copyright (C) 1992 Krishna Balasubramanian and Linus Torvalds |
3 | * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com> | 3 | * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com> |
4 | * Copyright (C) 2002 Andi Kleen | 4 | * Copyright (C) 2002 Andi Kleen |
5 | * | 5 | * |
6 | * This handles calls from both 32bit and 64bit mode. | 6 | * This handles calls from both 32bit and 64bit mode. |
7 | */ | 7 | */ |
8 | 8 | ||
@@ -20,11 +20,11 @@ | |||
20 | #include <asm/desc.h> | 20 | #include <asm/desc.h> |
21 | #include <asm/proto.h> | 21 | #include <asm/proto.h> |
22 | 22 | ||
23 | #ifdef CONFIG_SMP /* avoids "defined but not used" warnig */ | 23 | #ifdef CONFIG_SMP |
24 | static void flush_ldt(void *null) | 24 | static void flush_ldt(void *null) |
25 | { | 25 | { |
26 | if (current->active_mm) | 26 | if (current->active_mm) |
27 | load_LDT(¤t->active_mm->context); | 27 | load_LDT(¤t->active_mm->context); |
28 | } | 28 | } |
29 | #endif | 29 | #endif |
30 | 30 | ||
@@ -37,19 +37,20 @@ static int alloc_ldt(mm_context_t *pc, unsigned mincount, int reload) | |||
37 | if (mincount <= (unsigned)pc->size) | 37 | if (mincount <= (unsigned)pc->size) |
38 | return 0; | 38 | return 0; |
39 | oldsize = pc->size; | 39 | oldsize = pc->size; |
40 | mincount = (mincount+511)&(~511); | 40 | mincount = (mincount + 511) & (~511); |
41 | if (mincount*LDT_ENTRY_SIZE > PAGE_SIZE) | 41 | if (mincount * LDT_ENTRY_SIZE > PAGE_SIZE) |
42 | newldt = vmalloc(mincount*LDT_ENTRY_SIZE); | 42 | newldt = vmalloc(mincount * LDT_ENTRY_SIZE); |
43 | else | 43 | else |
44 | newldt = kmalloc(mincount*LDT_ENTRY_SIZE, GFP_KERNEL); | 44 | newldt = kmalloc(mincount * LDT_ENTRY_SIZE, GFP_KERNEL); |
45 | 45 | ||
46 | if (!newldt) | 46 | if (!newldt) |
47 | return -ENOMEM; | 47 | return -ENOMEM; |
48 | 48 | ||
49 | if (oldsize) | 49 | if (oldsize) |
50 | memcpy(newldt, pc->ldt, oldsize*LDT_ENTRY_SIZE); | 50 | memcpy(newldt, pc->ldt, oldsize * LDT_ENTRY_SIZE); |
51 | oldldt = pc->ldt; | 51 | oldldt = pc->ldt; |
52 | memset(newldt+oldsize*LDT_ENTRY_SIZE, 0, (mincount-oldsize)*LDT_ENTRY_SIZE); | 52 | memset(newldt + oldsize * LDT_ENTRY_SIZE, 0, |
53 | (mincount - oldsize) * LDT_ENTRY_SIZE); | ||
53 | wmb(); | 54 | wmb(); |
54 | pc->ldt = newldt; | 55 | pc->ldt = newldt; |
55 | wmb(); | 56 | wmb(); |
@@ -70,7 +71,7 @@ static int alloc_ldt(mm_context_t *pc, unsigned mincount, int reload) | |||
70 | #endif | 71 | #endif |
71 | } | 72 | } |
72 | if (oldsize) { | 73 | if (oldsize) { |
73 | if (oldsize*LDT_ENTRY_SIZE > PAGE_SIZE) | 74 | if (oldsize * LDT_ENTRY_SIZE > PAGE_SIZE) |
74 | vfree(oldldt); | 75 | vfree(oldldt); |
75 | else | 76 | else |
76 | kfree(oldldt); | 77 | kfree(oldldt); |
@@ -81,9 +82,10 @@ static int alloc_ldt(mm_context_t *pc, unsigned mincount, int reload) | |||
81 | static inline int copy_ldt(mm_context_t *new, mm_context_t *old) | 82 | static inline int copy_ldt(mm_context_t *new, mm_context_t *old) |
82 | { | 83 | { |
83 | int err = alloc_ldt(new, old->size, 0); | 84 | int err = alloc_ldt(new, old->size, 0); |
85 | |||
84 | if (err < 0) | 86 | if (err < 0) |
85 | return err; | 87 | return err; |
86 | memcpy(new->ldt, old->ldt, old->size*LDT_ENTRY_SIZE); | 88 | memcpy(new->ldt, old->ldt, old->size * LDT_ENTRY_SIZE); |
87 | return 0; | 89 | return 0; |
88 | } | 90 | } |
89 | 91 | ||
@@ -93,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old) | |||
93 | */ | 95 | */ |
94 | int init_new_context(struct task_struct *tsk, struct mm_struct *mm) | 96 | int init_new_context(struct task_struct *tsk, struct mm_struct *mm) |
95 | { | 97 | { |
96 | struct mm_struct * old_mm; | 98 | struct mm_struct *old_mm; |
97 | int retval = 0; | 99 | int retval = 0; |
98 | 100 | ||
99 | mutex_init(&mm->context.lock); | 101 | mutex_init(&mm->context.lock); |
@@ -108,13 +110,12 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm) | |||
108 | } | 110 | } |
109 | 111 | ||
110 | /* | 112 | /* |
111 | * | ||
112 | * Don't touch the LDT register - we're already in the next thread. | 113 | * Don't touch the LDT register - we're already in the next thread. |
113 | */ | 114 | */ |
114 | void destroy_context(struct mm_struct *mm) | 115 | void destroy_context(struct mm_struct *mm) |
115 | { | 116 | { |
116 | if (mm->context.size) { | 117 | if (mm->context.size) { |
117 | if ((unsigned)mm->context.size*LDT_ENTRY_SIZE > PAGE_SIZE) | 118 | if ((unsigned)mm->context.size * LDT_ENTRY_SIZE > PAGE_SIZE) |
118 | vfree(mm->context.ldt); | 119 | vfree(mm->context.ldt); |
119 | else | 120 | else |
120 | kfree(mm->context.ldt); | 121 | kfree(mm->context.ldt); |
@@ -122,19 +123,19 @@ void destroy_context(struct mm_struct *mm) | |||
122 | } | 123 | } |
123 | } | 124 | } |
124 | 125 | ||
125 | static int read_ldt(void __user * ptr, unsigned long bytecount) | 126 | static int read_ldt(void __user *ptr, unsigned long bytecount) |
126 | { | 127 | { |
127 | int err; | 128 | int err; |
128 | unsigned long size; | 129 | unsigned long size; |
129 | struct mm_struct * mm = current->mm; | 130 | struct mm_struct *mm = current->mm; |
130 | 131 | ||
131 | if (!mm->context.size) | 132 | if (!mm->context.size) |
132 | return 0; | 133 | return 0; |
133 | if (bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES) | 134 | if (bytecount > LDT_ENTRY_SIZE * LDT_ENTRIES) |
134 | bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES; | 135 | bytecount = LDT_ENTRY_SIZE * LDT_ENTRIES; |
135 | 136 | ||
136 | mutex_lock(&mm->context.lock); | 137 | mutex_lock(&mm->context.lock); |
137 | size = mm->context.size*LDT_ENTRY_SIZE; | 138 | size = mm->context.size * LDT_ENTRY_SIZE; |
138 | if (size > bytecount) | 139 | if (size > bytecount) |
139 | size = bytecount; | 140 | size = bytecount; |
140 | 141 | ||
@@ -146,7 +147,7 @@ static int read_ldt(void __user * ptr, unsigned long bytecount) | |||
146 | goto error_return; | 147 | goto error_return; |
147 | if (size != bytecount) { | 148 | if (size != bytecount) { |
148 | /* zero-fill the rest */ | 149 | /* zero-fill the rest */ |
149 | if (clear_user(ptr+size, bytecount-size) != 0) { | 150 | if (clear_user(ptr + size, bytecount - size) != 0) { |
150 | err = -EFAULT; | 151 | err = -EFAULT; |
151 | goto error_return; | 152 | goto error_return; |
152 | } | 153 | } |
@@ -156,21 +157,21 @@ error_return: | |||
156 | return err; | 157 | return err; |
157 | } | 158 | } |
158 | 159 | ||
159 | static int read_default_ldt(void __user * ptr, unsigned long bytecount) | 160 | static int read_default_ldt(void __user *ptr, unsigned long bytecount) |
160 | { | 161 | { |
161 | /* Arbitrary number */ | 162 | /* Arbitrary number */ |
162 | /* x86-64 default LDT is all zeros */ | 163 | /* x86-64 default LDT is all zeros */ |
163 | if (bytecount > 128) | 164 | if (bytecount > 128) |
164 | bytecount = 128; | 165 | bytecount = 128; |
165 | if (clear_user(ptr, bytecount)) | 166 | if (clear_user(ptr, bytecount)) |
166 | return -EFAULT; | 167 | return -EFAULT; |
167 | return bytecount; | 168 | return bytecount; |
168 | } | 169 | } |
169 | 170 | ||
170 | static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode) | 171 | static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode) |
171 | { | 172 | { |
172 | struct task_struct *me = current; | 173 | struct task_struct *me = current; |
173 | struct mm_struct * mm = me->mm; | 174 | struct mm_struct *mm = me->mm; |
174 | __u32 entry_1, entry_2, *lp; | 175 | __u32 entry_1, entry_2, *lp; |
175 | int error; | 176 | int error; |
176 | struct user_desc ldt_info; | 177 | struct user_desc ldt_info; |
@@ -179,7 +180,7 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode) | |||
179 | 180 | ||
180 | if (bytecount != sizeof(ldt_info)) | 181 | if (bytecount != sizeof(ldt_info)) |
181 | goto out; | 182 | goto out; |
182 | error = -EFAULT; | 183 | error = -EFAULT; |
183 | if (copy_from_user(&ldt_info, ptr, bytecount)) | 184 | if (copy_from_user(&ldt_info, ptr, bytecount)) |
184 | goto out; | 185 | goto out; |
185 | 186 | ||
@@ -195,15 +196,16 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode) | |||
195 | 196 | ||
196 | mutex_lock(&mm->context.lock); | 197 | mutex_lock(&mm->context.lock); |
197 | if (ldt_info.entry_number >= (unsigned)mm->context.size) { | 198 | if (ldt_info.entry_number >= (unsigned)mm->context.size) { |
198 | error = alloc_ldt(¤t->mm->context, ldt_info.entry_number+1, 1); | 199 | error = alloc_ldt(¤t->mm->context, |
200 | ldt_info.entry_number + 1, 1); | ||
199 | if (error < 0) | 201 | if (error < 0) |
200 | goto out_unlock; | 202 | goto out_unlock; |
201 | } | 203 | } |
202 | 204 | ||
203 | lp = (__u32 *) ((ldt_info.entry_number << 3) + (char *) mm->context.ldt); | 205 | lp = (__u32 *)((ldt_info.entry_number << 3) + (char *)mm->context.ldt); |
204 | 206 | ||
205 | /* Allow LDTs to be cleared by the user. */ | 207 | /* Allow LDTs to be cleared by the user. */ |
206 | if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { | 208 | if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { |
207 | if (oldmode || LDT_empty(&ldt_info)) { | 209 | if (oldmode || LDT_empty(&ldt_info)) { |
208 | entry_1 = 0; | 210 | entry_1 = 0; |
209 | entry_2 = 0; | 211 | entry_2 = 0; |
@@ -228,7 +230,8 @@ out: | |||
228 | return error; | 230 | return error; |
229 | } | 231 | } |
230 | 232 | ||
231 | asmlinkage int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount) | 233 | asmlinkage int sys_modify_ldt(int func, void __user *ptr, |
234 | unsigned long bytecount) | ||
232 | { | 235 | { |
233 | int ret = -ENOSYS; | 236 | int ret = -ENOSYS; |
234 | 237 | ||