diff options
Diffstat (limited to 'arch/i386/kernel/cpu/mtrr/if.c')
-rw-r--r-- | arch/i386/kernel/cpu/mtrr/if.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/arch/i386/kernel/cpu/mtrr/if.c b/arch/i386/kernel/cpu/mtrr/if.c index 5ac051bb9d55..5ae1705eafa6 100644 --- a/arch/i386/kernel/cpu/mtrr/if.c +++ b/arch/i386/kernel/cpu/mtrr/if.c | |||
@@ -17,7 +17,7 @@ extern unsigned int *usage_table; | |||
17 | 17 | ||
18 | #define FILE_FCOUNT(f) (((struct seq_file *)((f)->private_data))->private) | 18 | #define FILE_FCOUNT(f) (((struct seq_file *)((f)->private_data))->private) |
19 | 19 | ||
20 | static char *mtrr_strings[MTRR_NUM_TYPES] = | 20 | static const char *const mtrr_strings[MTRR_NUM_TYPES] = |
21 | { | 21 | { |
22 | "uncachable", /* 0 */ | 22 | "uncachable", /* 0 */ |
23 | "write-combining", /* 1 */ | 23 | "write-combining", /* 1 */ |
@@ -28,7 +28,7 @@ static char *mtrr_strings[MTRR_NUM_TYPES] = | |||
28 | "write-back", /* 6 */ | 28 | "write-back", /* 6 */ |
29 | }; | 29 | }; |
30 | 30 | ||
31 | char *mtrr_attrib_to_str(int x) | 31 | const char *mtrr_attrib_to_str(int x) |
32 | { | 32 | { |
33 | return (x <= 6) ? mtrr_strings[x] : "?"; | 33 | return (x <= 6) ? mtrr_strings[x] : "?"; |
34 | } | 34 | } |
@@ -44,10 +44,9 @@ mtrr_file_add(unsigned long base, unsigned long size, | |||
44 | 44 | ||
45 | max = num_var_ranges; | 45 | max = num_var_ranges; |
46 | if (fcount == NULL) { | 46 | if (fcount == NULL) { |
47 | fcount = kmalloc(max * sizeof *fcount, GFP_KERNEL); | 47 | fcount = kzalloc(max * sizeof *fcount, GFP_KERNEL); |
48 | if (!fcount) | 48 | if (!fcount) |
49 | return -ENOMEM; | 49 | return -ENOMEM; |
50 | memset(fcount, 0, max * sizeof *fcount); | ||
51 | FILE_FCOUNT(file) = fcount; | 50 | FILE_FCOUNT(file) = fcount; |
52 | } | 51 | } |
53 | if (!page) { | 52 | if (!page) { |
@@ -155,6 +154,7 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) | |||
155 | { | 154 | { |
156 | int err = 0; | 155 | int err = 0; |
157 | mtrr_type type; | 156 | mtrr_type type; |
157 | unsigned long size; | ||
158 | struct mtrr_sentry sentry; | 158 | struct mtrr_sentry sentry; |
159 | struct mtrr_gentry gentry; | 159 | struct mtrr_gentry gentry; |
160 | void __user *arg = (void __user *) __arg; | 160 | void __user *arg = (void __user *) __arg; |
@@ -235,15 +235,15 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) | |||
235 | case MTRRIOC_GET_ENTRY: | 235 | case MTRRIOC_GET_ENTRY: |
236 | if (gentry.regnum >= num_var_ranges) | 236 | if (gentry.regnum >= num_var_ranges) |
237 | return -EINVAL; | 237 | return -EINVAL; |
238 | mtrr_if->get(gentry.regnum, &gentry.base, &gentry.size, &type); | 238 | mtrr_if->get(gentry.regnum, &gentry.base, &size, &type); |
239 | 239 | ||
240 | /* Hide entries that go above 4GB */ | 240 | /* Hide entries that go above 4GB */ |
241 | if (gentry.base + gentry.size > 0x100000 | 241 | if (gentry.base + size - 1 >= (1UL << (8 * sizeof(gentry.size) - PAGE_SHIFT)) |
242 | || gentry.size == 0x100000) | 242 | || size >= (1UL << (8 * sizeof(gentry.size) - PAGE_SHIFT))) |
243 | gentry.base = gentry.size = gentry.type = 0; | 243 | gentry.base = gentry.size = gentry.type = 0; |
244 | else { | 244 | else { |
245 | gentry.base <<= PAGE_SHIFT; | 245 | gentry.base <<= PAGE_SHIFT; |
246 | gentry.size <<= PAGE_SHIFT; | 246 | gentry.size = size << PAGE_SHIFT; |
247 | gentry.type = type; | 247 | gentry.type = type; |
248 | } | 248 | } |
249 | 249 | ||
@@ -273,8 +273,14 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) | |||
273 | case MTRRIOC_GET_PAGE_ENTRY: | 273 | case MTRRIOC_GET_PAGE_ENTRY: |
274 | if (gentry.regnum >= num_var_ranges) | 274 | if (gentry.regnum >= num_var_ranges) |
275 | return -EINVAL; | 275 | return -EINVAL; |
276 | mtrr_if->get(gentry.regnum, &gentry.base, &gentry.size, &type); | 276 | mtrr_if->get(gentry.regnum, &gentry.base, &size, &type); |
277 | gentry.type = type; | 277 | /* Hide entries that would overflow */ |
278 | if (size != (__typeof__(gentry.size))size) | ||
279 | gentry.base = gentry.size = gentry.type = 0; | ||
280 | else { | ||
281 | gentry.size = size; | ||
282 | gentry.type = type; | ||
283 | } | ||
278 | break; | 284 | break; |
279 | } | 285 | } |
280 | 286 | ||
@@ -353,8 +359,7 @@ static int mtrr_seq_show(struct seq_file *seq, void *offset) | |||
353 | char factor; | 359 | char factor; |
354 | int i, max, len; | 360 | int i, max, len; |
355 | mtrr_type type; | 361 | mtrr_type type; |
356 | unsigned long base; | 362 | unsigned long base, size; |
357 | unsigned int size; | ||
358 | 363 | ||
359 | len = 0; | 364 | len = 0; |
360 | max = num_var_ranges; | 365 | max = num_var_ranges; |
@@ -373,7 +378,7 @@ static int mtrr_seq_show(struct seq_file *seq, void *offset) | |||
373 | } | 378 | } |
374 | /* RED-PEN: base can be > 32bit */ | 379 | /* RED-PEN: base can be > 32bit */ |
375 | len += seq_printf(seq, | 380 | len += seq_printf(seq, |
376 | "reg%02i: base=0x%05lx000 (%4liMB), size=%4i%cB: %s, count=%d\n", | 381 | "reg%02i: base=0x%05lx000 (%4luMB), size=%4lu%cB: %s, count=%d\n", |
377 | i, base, base >> (20 - PAGE_SHIFT), size, factor, | 382 | i, base, base >> (20 - PAGE_SHIFT), size, factor, |
378 | mtrr_attrib_to_str(type), usage_table[i]); | 383 | mtrr_attrib_to_str(type), usage_table[i]); |
379 | } | 384 | } |