Skip to content

Commit 6b21af7

Browse files
chleroympe
authored andcommitted
powerpc/code-patching: Reorganise do_patch_instruction() to ease error handling
Split do_patch_instruction() in two functions, the caller doing the spin locking and the callee doing everything else. And remove a few unnecessary initialisations and intermediate variables. This allows the callee to return from anywhere in the function. Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/dbc85980a0d2a935731b272e8907e8bb1d8fc8c5.1638446239.git.christophe.leroy@csgroup.eu
1 parent a3483c3 commit 6b21af7

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

arch/powerpc/lib/code-patching.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,30 @@ static void unmap_patch_area(unsigned long addr)
129129
flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
130130
}
131131

132+
static int __do_patch_instruction(u32 *addr, ppc_inst_t instr)
133+
{
134+
int err;
135+
u32 *patch_addr;
136+
unsigned long text_poke_addr;
137+
138+
text_poke_addr = (unsigned long)__this_cpu_read(text_poke_area)->addr;
139+
patch_addr = (u32 *)(text_poke_addr + offset_in_page(addr));
140+
141+
err = map_patch_area(addr, text_poke_addr);
142+
if (err)
143+
return err;
144+
145+
err = __patch_instruction(addr, instr, patch_addr);
146+
147+
unmap_patch_area(text_poke_addr);
148+
149+
return err;
150+
}
151+
132152
static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
133153
{
134154
int err;
135-
u32 *patch_addr = NULL;
136155
unsigned long flags;
137-
unsigned long text_poke_addr;
138-
unsigned long kaddr = (unsigned long)addr;
139156

140157
/*
141158
* During early early boot patch_instruction is called
@@ -146,19 +163,7 @@ static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
146163
return raw_patch_instruction(addr, instr);
147164

148165
local_irq_save(flags);
149-
150-
text_poke_addr = (unsigned long)__this_cpu_read(text_poke_area)->addr;
151-
err = map_patch_area(addr, text_poke_addr);
152-
if (err)
153-
goto out;
154-
155-
patch_addr = (u32 *)(text_poke_addr + (kaddr & ~PAGE_MASK));
156-
157-
err = __patch_instruction(addr, instr, patch_addr);
158-
159-
unmap_patch_area(text_poke_addr);
160-
161-
out:
166+
err = __do_patch_instruction(addr, instr);
162167
local_irq_restore(flags);
163168

164169
return err;

0 commit comments

Comments
 (0)