Skip to content

Commit 0b582db

Browse files
iamjpnmpe
authored andcommitted
powerpc: Make test_translate_branch() independent of instruction length
test_translate_branch() uses two pointers to instructions within a buffer, p and q, to test patch_branch(). The pointer arithmetic done on them assumes a size of 4. This will not work if the instruction length changes. Instead do the arithmetic relative to the void * to the buffer. Signed-off-by: Jordan Niethe <jniethe5@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Reviewed-by: Alistair Popple <alistair@popple.id.au> Link: https://lore.kernel.org/r/20200506034050.24806-21-jniethe5@gmail.com
1 parent 7fccfcf commit 0b582db

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎arch/powerpc/lib/code-patching.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ static void __init test_branch_bform(void)
572572
static void __init test_translate_branch(void)
573573
{
574574
unsigned long addr;
575-
struct ppc_inst *p, *q;
575+
void *p, *q;
576576
struct ppc_inst instr;
577577
void *buf;
578578

@@ -586,7 +586,7 @@ static void __init test_translate_branch(void)
586586
addr = (unsigned long)p;
587587
patch_branch(p, addr, 0);
588588
check(instr_is_branch_to_addr(p, addr));
589-
q = p + 1;
589+
q = p + 4;
590590
translate_branch(&instr, q, p);
591591
patch_instruction(q, instr);
592592
check(instr_is_branch_to_addr(q, addr));
@@ -642,7 +642,7 @@ static void __init test_translate_branch(void)
642642
create_cond_branch(&instr, p, addr, 0);
643643
patch_instruction(p, instr);
644644
check(instr_is_branch_to_addr(p, addr));
645-
q = p + 1;
645+
q = buf + 4;
646646
translate_branch(&instr, q, p);
647647
patch_instruction(q, instr);
648648
check(instr_is_branch_to_addr(q, addr));

0 commit comments

Comments
 (0)