Skip to content

Commit 7306006

Browse files
author
H. Peter Anvin
committed
x86, realmode: Pointer walk cleanups, pull out invariant use of __pa()
The pointer arithmetic in this function was really bizarre, where in fact all we really wanted was a simple pointer array walk. Use the much more idiomatic construction for that (*ptr++). Factor an invariant use of __pa() out of the relocation loop. At least on 64 bits it seems gcc isn't capable of doing that automatically. Change the scope of a couple of variables to make it extra obvious that they are extremely local temp variables. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com> Link: http://lkml.kernel.org/n/tip-rd908t9c8kvcojdabtmm94mb@git.kernel.org
1 parent d8af4ce commit 7306006

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

arch/x86/realmode/init.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ void __init reserve_real_mode(void)
2929
void __init setup_real_mode(void)
3030
{
3131
u16 real_mode_seg;
32-
u32 *rel;
32+
const u32 *rel;
3333
u32 count;
34-
u32 *ptr;
35-
u16 *seg;
36-
int i;
3734
unsigned char *base;
35+
unsigned long phys_base;
3836
struct trampoline_header *trampoline_header;
3937
size_t size = PAGE_ALIGN(real_mode_blob_end - real_mode_blob);
4038
#ifdef CONFIG_X86_64
@@ -46,23 +44,23 @@ void __init setup_real_mode(void)
4644

4745
memcpy(base, real_mode_blob, size);
4846

49-
real_mode_seg = __pa(base) >> 4;
47+
phys_base = __pa(base);
48+
real_mode_seg = phys_base >> 4;
49+
5050
rel = (u32 *) real_mode_relocs;
5151

5252
/* 16-bit segment relocations. */
53-
count = rel[0];
54-
rel = &rel[1];
55-
for (i = 0; i < count; i++) {
56-
seg = (u16 *) (base + rel[i]);
53+
count = *rel++;
54+
while (count--) {
55+
u16 *seg = (u16 *) (base + *rel++);
5756
*seg = real_mode_seg;
5857
}
5958

6059
/* 32-bit linear relocations. */
61-
count = rel[i];
62-
rel = &rel[i + 1];
63-
for (i = 0; i < count; i++) {
64-
ptr = (u32 *) (base + rel[i]);
65-
*ptr += __pa(base);
60+
count = *rel++;
61+
while (count--) {
62+
u32 *ptr = (u32 *) (base + *rel++);
63+
*ptr += phys_base;
6664
}
6765

6866
/* Must be perfomed *after* relocation. */

0 commit comments

Comments
 (0)