modpost: clean up is_executable_section()
authorMasahiro Yamada <masahiroy@kernel.org>
Sun, 14 May 2023 15:27:24 +0000 (00:27 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Mon, 22 May 2023 01:34:38 +0000 (10:34 +0900)
SHF_EXECINSTR is a bit flag (#define SHF_EXECINSTR 0x4).
Compare the masked flag to '!= 0'.

There is no good reason to stop modpost immediately even if a special
section index is given. You will get a section mismatch error anyway.

Also, change the return type to bool.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
scripts/mod/modpost.c

index bb7d1d8..0bda2f2 100644 (file)
@@ -1207,6 +1207,14 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
        return near;
 }
 
+static bool is_executable_section(struct elf_info *elf, unsigned int secndx)
+{
+       if (secndx > elf->num_sections)
+               return false;
+
+       return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0;
+}
+
 static void default_mismatch_handler(const char *modname, struct elf_info *elf,
                                     const struct sectioncheck* const mismatch,
                                     Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
@@ -1252,14 +1260,6 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
        }
 }
 
-static int is_executable_section(struct elf_info* elf, unsigned int section_index)
-{
-       if (section_index > elf->num_sections)
-               fatal("section_index is outside elf->num_sections!\n");
-
-       return ((elf->sechdrs[section_index].sh_flags & SHF_EXECINSTR) == SHF_EXECINSTR);
-}
-
 static void extable_mismatch_handler(const char* modname, struct elf_info *elf,
                                     const struct sectioncheck* const mismatch,
                                     Elf_Rela* r, Elf_Sym* sym,