Skip to content

Commit b63a07d

Browse files
rppttorvalds
authored andcommitted
arch: simplify several early memory allocations
There are several early memory allocations in arch/ code that use memblock_phys_alloc() to allocate memory, convert the returned physical address to the virtual address and then set the allocated memory to zero. Exactly the same behaviour can be achieved simply by calling memblock_alloc(): it allocates the memory in the same way as memblock_phys_alloc(), then it performs the phys_to_virt() conversion and clears the allocated memory. Replace the longer sequence with a simpler call to memblock_alloc(). Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Mike Rapoport <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: Greentime Hu <[email protected]> Cc: Guan Xuetao <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Jonas Bonn <[email protected]> Cc: Mark Salter <[email protected]> Cc: Martin Schwidefsky <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Michal Simek <[email protected]> Cc: Michal Simek <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Rich Felker <[email protected]> Cc: Russell King <[email protected]> Cc: Stafford Horne <[email protected]> Cc: Stefan Kristiansson <[email protected]> Cc: Vincent Chen <[email protected]> Cc: Yoshinori Sato <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1e8ffd5 commit b63a07d

File tree

10 files changed

+18
-43
lines changed

10 files changed

+18
-43
lines changed

arch/arm/mm/mmu.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,7 @@ EXPORT_SYMBOL(phys_mem_access_prot);
721721

722722
static void __init *early_alloc_aligned(unsigned long sz, unsigned long align)
723723
{
724-
void *ptr = __va(memblock_phys_alloc(sz, align));
725-
memset(ptr, 0, sz);
726-
return ptr;
724+
return memblock_alloc(sz, align);
727725
}
728726

729727
static void __init *early_alloc(unsigned long sz)

arch/c6x/mm/dma-coherent.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ void arch_dma_free(struct device *dev, size_t size, void *vaddr,
121121
*/
122122
void __init coherent_mem_init(phys_addr_t start, u32 size)
123123
{
124-
phys_addr_t bitmap_phys;
125-
126124
if (!size)
127125
return;
128126

@@ -138,11 +136,8 @@ void __init coherent_mem_init(phys_addr_t start, u32 size)
138136
if (dma_size & (PAGE_SIZE - 1))
139137
++dma_pages;
140138

141-
bitmap_phys = memblock_phys_alloc(BITS_TO_LONGS(dma_pages) * sizeof(long),
142-
sizeof(long));
143-
144-
dma_bitmap = phys_to_virt(bitmap_phys);
145-
memset(dma_bitmap, 0, dma_pages * PAGE_SIZE);
139+
dma_bitmap = memblock_alloc(BITS_TO_LONGS(dma_pages) * sizeof(long),
140+
sizeof(long));
146141
}
147142

148143
static void c6x_dma_sync(struct device *dev, phys_addr_t paddr, size_t size,

arch/nds32/mm/init.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ static void __init map_ram(void)
7878
}
7979

8080
/* Alloc one page for holding PTE's... */
81-
pte = (pte_t *) __va(memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE));
82-
memset(pte, 0, PAGE_SIZE);
81+
pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
8382
set_pmd(pme, __pmd(__pa(pte) + _PAGE_KERNEL_TABLE));
8483

8584
/* Fill the newly allocated page with PTE'S */
@@ -111,8 +110,7 @@ static void __init fixedrange_init(void)
111110
pgd = swapper_pg_dir + pgd_index(vaddr);
112111
pud = pud_offset(pgd, vaddr);
113112
pmd = pmd_offset(pud, vaddr);
114-
fixmap_pmd_p = (pmd_t *) __va(memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE));
115-
memset(fixmap_pmd_p, 0, PAGE_SIZE);
113+
fixmap_pmd_p = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
116114
set_pmd(pmd, __pmd(__pa(fixmap_pmd_p) + _PAGE_KERNEL_TABLE));
117115

118116
#ifdef CONFIG_HIGHMEM
@@ -124,8 +122,7 @@ static void __init fixedrange_init(void)
124122
pgd = swapper_pg_dir + pgd_index(vaddr);
125123
pud = pud_offset(pgd, vaddr);
126124
pmd = pmd_offset(pud, vaddr);
127-
pte = (pte_t *) __va(memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE));
128-
memset(pte, 0, PAGE_SIZE);
125+
pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
129126
set_pmd(pmd, __pmd(__pa(pte) + _PAGE_KERNEL_TABLE));
130127
pkmap_page_table = pte;
131128
#endif /* CONFIG_HIGHMEM */
@@ -150,8 +147,7 @@ void __init paging_init(void)
150147
fixedrange_init();
151148

152149
/* allocate space for empty_zero_page */
153-
zero_page = __va(memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE));
154-
memset(zero_page, 0, PAGE_SIZE);
150+
zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
155151
zone_sizes_init();
156152

157153
empty_zero_page = virt_to_page(zero_page);

arch/powerpc/kernel/setup-common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ void __init smp_setup_cpu_maps(void)
459459

460460
DBG("smp_setup_cpu_maps()\n");
461461

462-
cpu_to_phys_id = __va(memblock_phys_alloc(nr_cpu_ids * sizeof(u32), __alignof__(u32)));
463-
memset(cpu_to_phys_id, 0, nr_cpu_ids * sizeof(u32));
462+
cpu_to_phys_id = memblock_alloc(nr_cpu_ids * sizeof(u32),
463+
__alignof__(u32));
464464

465465
for_each_node_by_type(dn, "cpu") {
466466
const __be32 *intserv;

arch/powerpc/mm/ppc_mmu_32.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ void __init MMU_init_hw(void)
211211
* Find some memory for the hash table.
212212
*/
213213
if ( ppc_md.progress ) ppc_md.progress("hash:find piece", 0x322);
214-
Hash = __va(memblock_phys_alloc(Hash_size, Hash_size));
215-
memset(Hash, 0, Hash_size);
214+
Hash = memblock_alloc(Hash_size, Hash_size);
216215
_SDR1 = __pa(Hash) | SDR1_LOW_BITS;
217216

218217
Hash_end = (struct hash_pte *) ((unsigned long)Hash + Hash_size);

arch/powerpc/platforms/powernv/opal.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ int __init early_init_dt_scan_recoverable_ranges(unsigned long node,
171171
/*
172172
* Allocate a buffer to hold the MC recoverable ranges.
173173
*/
174-
mc_recoverable_range =__va(memblock_phys_alloc(size, __alignof__(u64)));
175-
memset(mc_recoverable_range, 0, size);
174+
mc_recoverable_range = memblock_alloc(size, __alignof__(u64));
176175

177176
for (i = 0; i < mc_recoverable_range_len; i++) {
178177
mc_recoverable_range[i].start_addr =

arch/s390/numa/numa.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ int numa_debug_enabled;
6262
*/
6363
static __init pg_data_t *alloc_node_data(void)
6464
{
65-
pg_data_t *res;
66-
67-
res = (pg_data_t *) memblock_phys_alloc(sizeof(pg_data_t), 8);
68-
memset(res, 0, sizeof(pg_data_t));
69-
return res;
65+
return memblock_alloc(sizeof(pg_data_t), 8);
7066
}
7167

7268
/*

arch/sparc/kernel/prom_64.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,13 @@
3434

3535
void * __init prom_early_alloc(unsigned long size)
3636
{
37-
unsigned long paddr = memblock_phys_alloc(size, SMP_CACHE_BYTES);
38-
void *ret;
37+
void *ret = memblock_alloc(size, SMP_CACHE_BYTES);
3938

40-
if (!paddr) {
39+
if (!ret) {
4140
prom_printf("prom_early_alloc(%lu) failed\n", size);
4241
prom_halt();
4342
}
4443

45-
ret = __va(paddr);
46-
memset(ret, 0, size);
4744
prom_early_allocated += size;
4845

4946
return ret;

arch/sparc/mm/init_64.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,16 +1089,13 @@ static void __init allocate_node_data(int nid)
10891089
struct pglist_data *p;
10901090
unsigned long start_pfn, end_pfn;
10911091
#ifdef CONFIG_NEED_MULTIPLE_NODES
1092-
unsigned long paddr;
10931092

1094-
paddr = memblock_phys_alloc_try_nid(sizeof(struct pglist_data),
1095-
SMP_CACHE_BYTES, nid);
1096-
if (!paddr) {
1093+
NODE_DATA(nid) = memblock_alloc_node(sizeof(struct pglist_data),
1094+
SMP_CACHE_BYTES, nid);
1095+
if (!NODE_DATA(nid)) {
10971096
prom_printf("Cannot allocate pglist_data for nid[%d]\n", nid);
10981097
prom_halt();
10991098
}
1100-
NODE_DATA(nid) = __va(paddr);
1101-
memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
11021099

11031100
NODE_DATA(nid)->node_id = nid;
11041101
#endif

arch/unicore32/mm/mmu.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ static void __init build_mem_type_table(void)
143143

144144
static void __init *early_alloc(unsigned long sz)
145145
{
146-
void *ptr = __va(memblock_phys_alloc(sz, sz));
147-
memset(ptr, 0, sz);
148-
return ptr;
146+
return memblock_alloc(sz, sz);
149147
}
150148

151149
static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr,

0 commit comments

Comments
 (0)