Skip to contentSkip to conversation

modpost: simplify modpost_log()

PATCH Superseded Masahiro Yamada 3 participants 4 messages Aug 12, 2024 – Aug 16, 2024 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 modpost: simplify modpost_log()

With commit cda5f94e88b4 ("modpost: avoid using the alias attribute"), only two log levels remain: LOG_WARN and LOG_ERROR. Simplify this by making it a boolean variable.

---

 scripts/mod/modpost.c | 17 ++++++-----------
 scripts/mod/modpost.h | 11 +++--------
 2 files changed, 9 insertions(+), 19 deletions(-)
scripts/mod/modpost.c +6 -11
index d0f138803207..c896872862dc 100644
@@ -67,20 +67,15 @@ static unsigned int nr_unresolved;
 
 #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
 
-void modpost_log(enum loglevel loglevel, const char *fmt, ...)
+void modpost_log(bool is_error, const char *fmt, ...)
 {
 	va_list arglist;
 
-	switch (loglevel) {
-	case LOG_WARN:
-		fprintf(stderr, "WARNING: ");
-		break;
-	case LOG_ERROR:
+	if (is_error) {
 		fprintf(stderr, "ERROR: ");
 		error_occurred = true;
-		break;
-	default: /* invalid loglevel, ignore */
-		break;
+	} else {
+		fprintf(stderr, "WARNING: ");
 	}
 
 	fprintf(stderr, "modpost: ");
@@ -1692,7 +1687,7 @@ static void check_exports(struct module *mod)
 		exp = find_symbol(s->name);
 		if (!exp) {
 			if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS)
-				modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR,
+				modpost_log(warn_unresolved,
 					    "\"%s\" [%s.ko] undefined!\n",
 					    s->name, mod->name);
 			continue;
@@ -1715,7 +1710,7 @@ static void check_exports(struct module *mod)
 			basename = mod->name;
 
 		if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) {
-			modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR,
+			modpost_log(allow_missing_ns_imports,
 				    "module %s uses symbol %s from namespace %s, but does not import it.\n",
 				    basename, exp->name, exp->namespace);
 			add_namespace(&mod->missing_namespaces, exp->namespace);
scripts/mod/modpost.h +3 -8
index f756e6578b9e..6f418f0afd04 100644
@@ -184,13 +184,8 @@ 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);
 
-enum loglevel {
-	LOG_WARN,
-	LOG_ERROR,
-};
-
 void __attribute__((format(printf, 2, 3)))
-modpost_log(enum loglevel loglevel, const char *fmt, ...);
+modpost_log(bool is_error, const char *fmt, ...);
 
 /*
  * warn - show the given message, then let modpost continue running, still
@@ -205,6 +200,6 @@ modpost_log(enum loglevel loglevel, const char *fmt, ...);
  * fatal - show the given message, and bail out immediately. This should be
  *         used when there is no point to continue running modpost.
  */
-#define warn(fmt, args...)	modpost_log(LOG_WARN, fmt, ##args)
-#define error(fmt, args...)	modpost_log(LOG_ERROR, fmt, ##args)
+#define warn(fmt, args...)	modpost_log(false, fmt, ##args)
+#define error(fmt, args...)	modpost_log(true, fmt, ##args)
 #define fatal(fmt, args...)	do { error(fmt, ##args); exit(1); } while (1)
Signature · 1 line
2.43.0
#1 lore raw

Hi Masahiro,

Quoted 41 lines · Masahiro Yamada

With commit cda5f94e88b4 ("modpost: avoid using the alias attribute"), only two log levels remain: LOG_WARN and LOG_ERROR. Simplify this by making it a boolean variable.

---

 scripts/mod/modpost.c | 17 ++++++-----------
 scripts/mod/modpost.h | 11 +++--------
 2 files changed, 9 insertions(+), 19 deletions(-)
scripts/mod/modpost.c +4 -9
index d0f138803207..c896872862dc 100644
@@ -67,20 +67,15 @@ static unsigned int nr_unresolved;
 
 #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
 
-void modpost_log(enum loglevel loglevel, const char *fmt, ...)
+void modpost_log(bool is_error, const char *fmt, ...)
 {
 	va_list arglist;
 
-	switch (loglevel) {
-	case LOG_WARN:
-		fprintf(stderr, "WARNING: ");
-		break;
-	case LOG_ERROR:
+	if (is_error) {
 		fprintf(stderr, "ERROR: ");
 		error_occurred = true;
-		break;
-	default: /* invalid loglevel, ignore */
-		break;
+	} else {
+		fprintf(stderr, "WARNING: ");
 	}
 
 	fprintf(stderr, "modpost: ");

scripts/mod/modpost.c static void check_exports(struct module *mod) · line 1690

Quoted 5 lines
scripts/mod/modpost.c +1 -1
@@ -1692,7 +1687,7 @@ static void check_exports(struct module *mod)
 		exp = find_symbol(s->name);
 		if (!exp) {
 			if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS)
-				modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR,
+				modpost_log(warn_unresolved,

I think the logic is reversed here? If warn_unresolved was true before, LOG_WARN would be used but I think warn_unresolved being true with this change would trigger the behavior of LOG_ERROR. Should it be '!warn_unresolved'?

scripts/mod/modpost.c static void check_exports(struct module *mod) · line 1713

Quoted 9 lines
scripts/mod/modpost.c +1 -1
 					    "\"%s\" [%s.ko] undefined!\n",
 					    s->name, mod->name);
 			continue;
@@ -1715,7 +1710,7 @@ static void check_exports(struct module *mod)
 			basename = mod->name;
 
 		if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) {
-			modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR,
+			modpost_log(allow_missing_ns_imports,

Same thing here?

Alternatively, I suppose the logic could be reversed in modpost_log() and is_error could be turned into no_error or something?

Quoted 23 lines
scripts/mod/modpost.c +0 -0
 				    "module %s uses symbol %s from namespace %s, but does not import it.\n",
 				    basename, exp->name, exp->namespace);
 			add_namespace(&mod->missing_namespaces, exp->namespace);
scripts/mod/modpost.h +1 -6
index f756e6578b9e..6f418f0afd04 100644
@@ -184,13 +184,8 @@ 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);
 
-enum loglevel {
-	LOG_WARN,
-	LOG_ERROR,
-};
-
 void __attribute__((format(printf, 2, 3)))
-modpost_log(enum loglevel loglevel, const char *fmt, ...);
+modpost_log(bool is_error, const char *fmt, ...);
 
 /*
  * warn - show the given message, then let modpost continue running, still

scripts/mod/modpost.h modpost_log(enum loglevel loglevel, const char *fmt, ...); · line 204

Quoted 7 lines
scripts/mod/modpost.h +2 -2
@@ -205,6 +200,6 @@ modpost_log(enum loglevel loglevel, const char *fmt, ...);
  * fatal - show the given message, and bail out immediately. This should be
  *         used when there is no point to continue running modpost.
  */
-#define warn(fmt, args...)	modpost_log(LOG_WARN, fmt, ##args)
-#define error(fmt, args...)	modpost_log(LOG_ERROR, fmt, ##args)
+#define warn(fmt, args...)	modpost_log(false, fmt, ##args)
+#define error(fmt, args...)	modpost_log(true, fmt, ##args)

I suppose the declaration of modpost_log() is close enough to see what the true/false argument means but maybe something like

modpost_log(/* is_error = */ false, ...)

could be nice? No strong opinion here though, feel free to just ignore this whole comment entirely if you disagree!

Quoted 4 lines
scripts/mod/modpost.h +0 -0
 #define fatal(fmt, args...)	do { error(fmt, ##args); exit(1); } while (1)
Signature · 1 line
2.43.0
#2 lore raw
Quoted 43 lines · Nathan Chancellor

Hi Masahiro,

Quoted 39 lines · Masahiro Yamada

With commit cda5f94e88b4 ("modpost: avoid using the alias attribute"), only two log levels remain: LOG_WARN and LOG_ERROR. Simplify this by making it a boolean variable.

---

 scripts/mod/modpost.c | 17 ++++++-----------
 scripts/mod/modpost.h | 11 +++--------
 2 files changed, 9 insertions(+), 19 deletions(-)
scripts/mod/modpost.c +4 -9
index d0f138803207..c896872862dc 100644
@@ -67,20 +67,15 @@ static unsigned int nr_unresolved;
 
 #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
 
-void modpost_log(enum loglevel loglevel, const char *fmt, ...)
+void modpost_log(bool is_error, const char *fmt, ...)
 {
      va_list arglist;
 
-     switch (loglevel) {
-     case LOG_WARN:
-             fprintf(stderr, "WARNING: ");
-             break;
-     case LOG_ERROR:
+     if (is_error) {
              fprintf(stderr, "ERROR: ");
              error_occurred = true;
-             break;
-     default: /* invalid loglevel, ignore */
-             break;
+     } else {
+             fprintf(stderr, "WARNING: ");
      }
 
Quoted 12 lines

scripts/mod/modpost.c static void check_exports(struct module *mod) · line 1690

Quoted 7 lines
scripts/mod/modpost.c +1 -1
      fprintf(stderr, "modpost: ");
@@ -1692,7 +1687,7 @@ static void check_exports(struct module *mod)
              exp = find_symbol(s->name);
              if (!exp) {
                      if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS)
-                             modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR,
+                             modpost_log(warn_unresolved,

I think the logic is reversed here? If warn_unresolved was true before, LOG_WARN would be used but I think warn_unresolved being true with this change would trigger the behavior of LOG_ERROR. Should it be '!warn_unresolved'?

Thanks, I will fix this in v2.

Quoted 59 lines

scripts/mod/modpost.c static void check_exports(struct module *mod) · line 1713

Quoted 10 lines
scripts/mod/modpost.c +1 -1
                                          "\"%s\" [%s.ko] undefined!\n",
                                          s->name, mod->name);
                      continue;
@@ -1715,7 +1710,7 @@ static void check_exports(struct module *mod)
                      basename = mod->name;
 
              if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) {
-                     modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR,
+                     modpost_log(allow_missing_ns_imports,

Same thing here?

Alternatively, I suppose the logic could be reversed in modpost_log() and is_error could be turned into no_error or something?

Quoted 23 lines
scripts/mod/modpost.c +0 -0
                                  "module %s uses symbol %s from namespace %s, but does not import it.\n",
                                  basename, exp->name, exp->namespace);
                      add_namespace(&mod->missing_namespaces, exp->namespace);
scripts/mod/modpost.h +1 -6
index f756e6578b9e..6f418f0afd04 100644
@@ -184,13 +184,8 @@ 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);
 
-enum loglevel {
-     LOG_WARN,
-     LOG_ERROR,
-};
-
 void __attribute__((format(printf, 2, 3)))
-modpost_log(enum loglevel loglevel, const char *fmt, ...);
+modpost_log(bool is_error, const char *fmt, ...);
 
 /*
  * warn - show the given message, then let modpost continue running, still

scripts/mod/modpost.h modpost_log(enum loglevel loglevel, const char *fmt, ...); · line 204

Quoted 7 lines
scripts/mod/modpost.h +2 -2
@@ -205,6 +200,6 @@ modpost_log(enum loglevel loglevel, const char *fmt, ...);
  * fatal - show the given message, and bail out immediately. This should be
  *         used when there is no point to continue running modpost.
  */
-#define warn(fmt, args...)   modpost_log(LOG_WARN, fmt, ##args)
-#define error(fmt, args...)  modpost_log(LOG_ERROR, fmt, ##args)
+#define warn(fmt, args...)   modpost_log(false, fmt, ##args)
+#define error(fmt, args...)  modpost_log(true, fmt, ##args)

I suppose the declaration of modpost_log() is close enough to see what the true/false argument means but maybe something like

modpost_log(/* is_error = */ false, ...)

could be nice? No strong opinion here though, feel free to just ignore this whole comment entirely if you disagree!

Quoted 4 lines
scripts/mod/modpost.h +0 -1
 #define fatal(fmt, args...)  do { error(fmt, ##args); exit(1); } while (1)
--

2.43.0

Signature · 2 lines
Best Regards
Masahiro Yamada
#3 lore raw
In reply to Masahiro Yamada
kernel test robot noticed the following build warnings:

Hi Masahiro,

kernel test robot noticed the following build warnings:

[auto build test WARNING on masahiroy-kbuild/for-next]
[also build test WARNING on masahiroy-kbuild/fixes linus/master v6.11-rc3 next-20240813] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Masahiro-Yamada/modpost-simplify-modpost_log/20240813-003654
base:   https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next
patch link:    https://lore.kernel.org/r/20240812144542.2121342-1-masahiroy%40kernel.org
patch subject: [PATCH] modpost: simplify modpost_log()
config: loongarch-randconfig-001-20240813 (https://download.01.org/0day-ci/archive/20240813/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240813/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>, old ones prefixed by <<):

WARNING: modpost: missing MODULE_DESCRIPTION() in mm/kasan/kasan_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in mm/kasan/kasan_test_module.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_powersave.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fpga/tests/fpga-mgr-test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fpga/tests/fpga-bridge-test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fpga/tests/fpga-region-test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-core.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-hub.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-aspeed.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-gpio.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-scom.o

>> WARNING: modpost: "kvm_restore_lsx" [arch/loongarch/kvm/kvm.ko] undefined!
>> WARNING: modpost: "kvm_restore_lasx" [arch/loongarch/kvm/kvm.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki