Move the arch-based addend_*_rel() calls into addend_rel() to be reused.

Signed-off-by: Mauricio Faria de Oliveira <[email protected]>
---
 scripts/mod/modpost.c | 35 +++++++++++++++++++----------------
 scripts/mod/modpost.h |  2 ++
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 
75374c64b8cc78bb4d01fa4c64254c7d7cd80e8f..d18a87b882a67f06d5f75ee92f4c26dc713d83b8
 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1296,6 +1296,24 @@ static Elf_Addr addend_mips_rel(uint32_t *location, 
unsigned int r_type)
        return (Elf_Addr)(-1);
 }
 
+Elf_Addr addend_rel(struct elf_info *elf, unsigned int secndx,
+                   unsigned int r_type, Elf_Addr r_offset, Elf_Sym *tsym)
+{
+       void *loc = sym_get_data_by_offset(elf, secndx, r_offset);
+
+       switch (elf->hdr->e_machine) {
+       case EM_386:
+               return addend_386_rel(loc, r_type);
+       case EM_ARM:
+               return addend_arm_rel(loc, tsym, r_type);
+       case EM_MIPS:
+               return addend_mips_rel(loc, r_type);
+       }
+
+       fatal("Please add code to calculate addend for this architecture\n");
+       return (Elf_Addr)(-1);
+}
+
 #ifndef EM_RISCV
 #define EM_RISCV               243
 #endif
@@ -1402,27 +1420,12 @@ static void section_rel(struct module *mod, struct 
elf_info *elf,
                Elf_Sym *tsym;
                Elf_Addr taddr, r_offset;
                unsigned int r_type, r_sym;
-               void *loc;
 
                r_offset = TO_NATIVE(rel->r_offset);
                get_rel_type_and_sym(elf, rel->r_info, &r_type, &r_sym);
 
-               loc = sym_get_data_by_offset(elf, fsecndx, r_offset);
                tsym = elf->symtab_start + r_sym;
-
-               switch (elf->hdr->e_machine) {
-               case EM_386:
-                       taddr = addend_386_rel(loc, r_type);
-                       break;
-               case EM_ARM:
-                       taddr = addend_arm_rel(loc, tsym, r_type);
-                       break;
-               case EM_MIPS:
-                       taddr = addend_mips_rel(loc, r_type);
-                       break;
-               default:
-                       fatal("Please add code to calculate addend for this 
architecture\n");
-               }
+               taddr = addend_rel(elf, fsecndx, r_type, r_offset, tsym);
 
                check_section_mismatch(mod, elf, tsym,
                                       fsecndx, fromsec, r_offset, taddr);
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 
d5f6d82837d5b4fbd671ff9dab9bbe353442f6cf..a98811552bd2996c31cf73fd3619e6c58bac8a6d
 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -222,6 +222,8 @@ const char *get_basename(const char *path);
 char *read_text_file(const char *filename);
 char *get_line(char **stringp);
 void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym);
+Elf_Addr addend_rel(struct elf_info *elf, unsigned int secndx,
+                   unsigned int r_type, Elf_Addr r_offset, Elf_Sym *tsym);
 
 void __attribute__((format(printf, 3, 4)))
 modpost_log(bool is_error, struct module *mod, const char *fmt, ...);

-- 
2.47.3


Reply via email to