Skip to content

Commit f33efa9

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: Code improvements in function pcpu_populate_pte()
Do some code improvements in function pcpu_populate_pte(): 1. Add memory allocation failure handling; 2. Replace pgd_populate() with p4d_populate(), it will be useful if there are four-level page tables. Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent ad3ff10 commit f33efa9

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

arch/loongarch/kernel/numa.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,32 +73,34 @@ void __init pcpu_populate_pte(unsigned long addr)
7373
pmd_t *pmd;
7474

7575
if (p4d_none(*p4d)) {
76-
pud_t *new;
77-
78-
new = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
79-
pgd_populate(&init_mm, pgd, new);
76+
pud = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
77+
if (!pud)
78+
panic("%s: Failed to allocate memory\n", __func__);
79+
p4d_populate(&init_mm, p4d, pud);
8080
#ifndef __PAGETABLE_PUD_FOLDED
81-
pud_init(new);
81+
pud_init(pud);
8282
#endif
8383
}
8484

8585
pud = pud_offset(p4d, addr);
8686
if (pud_none(*pud)) {
87-
pmd_t *new;
88-
89-
new = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
90-
pud_populate(&init_mm, pud, new);
87+
pmd = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
88+
if (!pmd)
89+
panic("%s: Failed to allocate memory\n", __func__);
90+
pud_populate(&init_mm, pud, pmd);
9191
#ifndef __PAGETABLE_PMD_FOLDED
92-
pmd_init(new);
92+
pmd_init(pmd);
9393
#endif
9494
}
9595

9696
pmd = pmd_offset(pud, addr);
9797
if (!pmd_present(*pmd)) {
98-
pte_t *new;
98+
pte_t *pte;
9999

100-
new = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
101-
pmd_populate_kernel(&init_mm, pmd, new);
100+
pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
101+
if (!pte)
102+
panic("%s: Failed to allocate memory\n", __func__);
103+
pmd_populate_kernel(&init_mm, pmd, pte);
102104
}
103105
}
104106

0 commit comments

Comments
 (0)