History

modpost: change mod->gpl_compatible to bool type

Currently, mod->gpl_compatible is tristate; it is set to -1 by default, then to 1 or 0 when MODULE_LICENSE() is found. Maybe, -1 was chosen to represent the 'unknown' license, but it is not useful. The current code: if (!mod->gpl_compatible) check_for_gpl_usage(exp->export, basename, exp->name); ... only cares whether gpl_compatible is zero or not. Change it to a bool type with the initial value 'true', which has no functional change. The default value should be 'true' instead of 'false'. Since commit 1d6cd3929360 ("modpost: turn missing MODULE_LICENSE() into error"), unknown module license is an error. The error message, "missing MODULE_LICENSE()" is enough to explain the issue. It is not sensible to show another message, "GPL-incompatible module ... uses GPL-only symbol". Add comments to explain this. While I was here, I renamed gpl_compatible to is_gpl_compatible for clarification, and also slightly refactored the code.

Masahiro Yamada committed 4 years ago

Commit 50667431 parent 58e01fc2 files · +12 −7Browse files

Showing the changes to scripts (2 of 2 files). Show all

Unified · Split

2 files
  1. scripts/mod/modpost.c +11 −6
  2. scripts/mod/modpost.h +1 −1
scripts/mod/modpost.c+11−6
@@ -187,7 +187,14 @@ static struct module *new_module(const char *modname) · 186 unmodified lines
187187 /* add to list */
188188 strcpy(mod->name, modname);
189189 mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0);
190− mod->gpl_compatible = -1;
190+
191+ /*
192+ * Set mod->is_gpl_compatible to true by default. If MODULE_LICENSE()
193+ * is missing, do not check the use for EXPORT_SYMBOL_GPL() becasue
194+ * modpost will exit wiht error anyway.
195+ */
196+ mod->is_gpl_compatible = true;
197+
191198 mod->next = modules;
192199 modules = mod;
193200
@@ -2012,10 +2019,8 @@ static void read_symbols(const char *modname) · 1818 unmodified lines
20122019 if (!license)
20132020 error("missing MODULE_LICENSE() in %s\n", modname);
20142021 while (license) {
2015− if (license_is_gpl_compatible(license))
2016− mod->gpl_compatible = 1;
2017− else {
2018− mod->gpl_compatible = 0;
2022+ if (!license_is_gpl_compatible(license)) {
2023+ mod->is_gpl_compatible = false;
20192024 break;
20202025 }
20212026 license = get_next_modinfo(&info, "license", license);
@@ -2183,7 +2188,7 @@ static void check_exports(struct module *mod) · 161 unmodified lines
21832188 add_namespace(&mod->missing_namespaces, exp->namespace);
21842189 }
21852190
2186− if (!mod->gpl_compatible)
2191+ if (!mod->is_gpl_compatible)
21872192 check_for_gpl_usage(exp->export, basename, exp->name);
21882193 }
21892194 }
scripts/mod/modpost.h+1−1
@@ -112,7 +112,7 @@ buf_write(struct buffer *buf, const char *s, int len); · 111 unmodified lines
112112
113113 struct module {
114114 struct module *next;
115− int gpl_compatible;
115+ bool is_gpl_compatible;
116116 struct symbol *unres;
117117 bool from_dump; /* true if module was loaded from *.symvers */
118118 bool is_vmlinux;