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
187 /* add to list */187 /* add to list */
188 strcpy(mod->name, modname);188 strcpy(mod->name, modname);
189 mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0);189 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
191 mod->next = modules;198 mod->next = modules;
192 modules = mod;199 modules = mod;
193 200
@@ -2012,10 +2019,8 @@ static void read_symbols(const char *modname) · 1818 unmodified lines
2012 if (!license)2019 if (!license)
2013 error("missing MODULE_LICENSE() in %s\n", modname);2020 error("missing MODULE_LICENSE() in %s\n", modname);
2014 while (license) {2021 while (license) {
2015 if (license_is_gpl_compatible(license))2022 if (!license_is_gpl_compatible(license)) {
2016 mod->gpl_compatible = 1;2023 mod->is_gpl_compatible = false;
2017 else {
2018 mod->gpl_compatible = 0;
2019 break;2024 break;
2020 }2025 }
2021 license = get_next_modinfo(&info, "license", license);2026 license = get_next_modinfo(&info, "license", license);
@@ -2183,7 +2188,7 @@ static void check_exports(struct module *mod) · 161 unmodified lines
2183 add_namespace(&mod->missing_namespaces, exp->namespace);2188 add_namespace(&mod->missing_namespaces, exp->namespace);
2184 }2189 }
2185 2190
2186 if (!mod->gpl_compatible)2191 if (!mod->is_gpl_compatible)
2187 check_for_gpl_usage(exp->export, basename, exp->name);2192 check_for_gpl_usage(exp->export, basename, exp->name);
2188 }2193 }
2189}2194}
scripts/mod/modpost.h+1−1
@@ -112,7 +112,7 @@ buf_write(struct buffer *buf, const char *s, int len); · 111 unmodified lines
112 112
113struct module {113struct module {
114 struct module *next;114 struct module *next;
115 int gpl_compatible;115 bool is_gpl_compatible;
116 struct symbol *unres;116 struct symbol *unres;
117 bool from_dump; /* true if module was loaded from *.symvers */117 bool from_dump; /* true if module was loaded from *.symvers */
118 bool is_vmlinux;118 bool is_vmlinux;