Skip to content

Commit

Permalink
modpost: get the *.mod file path more simply
Browse files Browse the repository at this point in the history
get_src_version() strips 'o' or 'lto.o' from the end of the object file
path (so, postfixlen is 1 or 5), then adds 'mod'.

If you look at the code closely, mod->name already holds the base path
with the extension stripped.

Most of the code changes made by commit 7ac204b ("modpost: lto:
strip .lto from module names") was actually unneeded.

sumversion.c does not need strends(), so it can get back local in
modpost.c again.

Signed-off-by: Masahiro Yamada <[email protected]>
  • Loading branch information
masahir0y committed Sep 2, 2021
1 parent 1439ebd commit e54dd93
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
11 changes: 10 additions & 1 deletion scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <stdbool.h>
#include <errno.h>
#include "modpost.h"
#include "../../include/linux/license.h"
Expand Down Expand Up @@ -89,6 +90,14 @@ modpost_log(enum loglevel loglevel, const char *fmt, ...)
error_occurred = true;
}

static inline bool strends(const char *str, const char *postfix)
{
if (strlen(str) < strlen(postfix))
return false;

return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
}

void *do_nofail(void *ptr, const char *expr)
{
if (!ptr)
Expand Down Expand Up @@ -2060,7 +2069,7 @@ static void read_symbols(const char *modname)
if (!mod->is_vmlinux) {
version = get_modinfo(&info, "version");
if (version || all_versions)
get_src_version(modname, mod->srcversion,
get_src_version(mod->name, mod->srcversion,
sizeof(mod->srcversion) - 1);
}

Expand Down
9 changes: 0 additions & 9 deletions scripts/mod/modpost.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -178,14 +177,6 @@ static inline unsigned int get_secindex(const struct elf_info *info,
return info->symtab_shndx_start[sym - info->symtab_start];
}

static inline bool strends(const char *str, const char *postfix)
{
if (strlen(str) < strlen(postfix))
return false;

return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
}

/* file2alias.c */
extern unsigned int cross_build;
void handle_moddevtable(struct module *mod, struct elf_info *info,
Expand Down
7 changes: 1 addition & 6 deletions scripts/mod/sumversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,9 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
struct md4_ctx md;
char *fname;
char filelist[PATH_MAX + 1];
int postfix_len = 1;

if (strends(modname, ".lto.o"))
postfix_len = 5;

/* objects for a module are listed in the first line of *.mod file. */
snprintf(filelist, sizeof(filelist), "%.*smod",
(int)strlen(modname) - postfix_len, modname);
snprintf(filelist, sizeof(filelist), "%s.mod", modname);

buf = read_text_file(filelist);

Expand Down

0 comments on commit e54dd93

Please sign in to comment.