Skip to content

Commit

Permalink
modpost: squash if...else-if in find_elf_symbol2()
Browse files Browse the repository at this point in the history
if ((addr - sym->st_value) < distance) {
            distance = addr - sym->st_value;
            near = sym;
    } else if ((addr - sym->st_value) == distance) {
            near = sym;
    }

is equivalent to:

    if (addr - sym->st_value <= distance) {
            distance = addr - sym->st_value;
            near = sym;
    }

(The else-if block can overwrite 'distance' with the same value).

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
  • Loading branch information
masahir0y committed May 27, 2022
1 parent c5c468d commit 68fef67
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,13 +1270,9 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
continue;
if (!is_valid_name(elf, sym))
continue;
if (sym->st_value <= addr) {
if ((addr - sym->st_value) < distance) {
distance = addr - sym->st_value;
near = sym;
} else if ((addr - sym->st_value) == distance) {
near = sym;
}
if (sym->st_value <= addr && addr - sym->st_value <= distance) {
distance = addr - sym->st_value;
near = sym;
}
}
return near;
Expand Down

0 comments on commit 68fef67

Please sign in to comment.