Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 30606
b: refs/heads/master
c: b817f6f
h: refs/heads/master
v: v3
  • Loading branch information
Sam Ravnborg committed Jun 9, 2006
1 parent 6ae5c32 commit d4f12e3
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: bd5cbcedf446e2f37cf2a37f533a7e1d7dff9312
refs/heads/master: b817f6feff4a565b08f0e699a5790b4008b8f494
14 changes: 14 additions & 0 deletions trunk/include/linux/license.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef __LICENSE_H
#define __LICENSE_H

static inline int license_is_gpl_compatible(const char *license)
{
return (strcmp(license, "GPL") == 0
|| strcmp(license, "GPL v2") == 0
|| strcmp(license, "GPL and additional rights") == 0
|| strcmp(license, "Dual BSD/GPL") == 0
|| strcmp(license, "Dual MIT/GPL") == 0
|| strcmp(license, "Dual MPL/GPL") == 0);
}

#endif
11 changes: 1 addition & 10 deletions trunk/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <asm/uaccess.h>
#include <asm/semaphore.h>
#include <asm/cacheflush.h>
#include <linux/license.h>

#if 0
#define DEBUGP printk
Expand Down Expand Up @@ -1248,16 +1249,6 @@ static void layout_sections(struct module *mod,
}
}

static inline int license_is_gpl_compatible(const char *license)
{
return (strcmp(license, "GPL") == 0
|| strcmp(license, "GPL v2") == 0
|| strcmp(license, "GPL and additional rights") == 0
|| strcmp(license, "Dual BSD/GPL") == 0
|| strcmp(license, "Dual MIT/GPL") == 0
|| strcmp(license, "Dual MPL/GPL") == 0);
}

static void set_license(struct module *mod, const char *license)
{
if (!license)
Expand Down
71 changes: 69 additions & 2 deletions trunk/scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <ctype.h>
#include "modpost.h"
#include "../../include/linux/license.h"

/* Are we using CONFIG_MODVERSIONS? */
int modversions = 0;
Expand Down Expand Up @@ -99,6 +100,7 @@ static struct module *new_module(char *modname)

/* add to list */
mod->name = p;
mod->gpl_compatible = -1;
mod->next = modules;
modules = mod;

Expand Down Expand Up @@ -493,20 +495,32 @@ static char *next_string(char *string, unsigned long *secsize)
return string;
}

static char *get_modinfo(void *modinfo, unsigned long modinfo_len,
const char *tag)
static char *get_next_modinfo(void *modinfo, unsigned long modinfo_len,
const char *tag, char *info)
{
char *p;
unsigned int taglen = strlen(tag);
unsigned long size = modinfo_len;

if (info) {
size -= info - (char *)modinfo;
modinfo = next_string(info, &size);
}

for (p = modinfo; p; p = next_string(p, &size)) {
if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=')
return p + taglen + 1;
}
return NULL;
}

static char *get_modinfo(void *modinfo, unsigned long modinfo_len,
const char *tag)

{
return get_next_modinfo(modinfo, modinfo_len, tag, NULL);
}

/**
* Test if string s ends in string sub
* return 0 if match
Expand Down Expand Up @@ -981,6 +995,7 @@ static void read_symbols(char *modname)
{
const char *symname;
char *version;
char *license;
struct module *mod;
struct elf_info info = { };
Elf_Sym *sym;
Expand All @@ -996,6 +1011,18 @@ static void read_symbols(char *modname)
mod->skip = 1;
}

license = get_modinfo(info.modinfo, info.modinfo_len, "license");
while (license) {
if (license_is_gpl_compatible(license))
mod->gpl_compatible = 1;
else {
mod->gpl_compatible = 0;
break;
}
license = get_next_modinfo(info.modinfo, info.modinfo_len,
"license", license);
}

for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
symname = info.strtab + sym->st_name;

Expand Down Expand Up @@ -1052,6 +1079,40 @@ void buf_write(struct buffer *buf, const char *s, int len)
buf->pos += len;
}

void check_license(struct module *mod)
{
struct symbol *s, *exp;

for (s = mod->unres; s; s = s->next) {
if (mod->gpl_compatible == 1) {
/* GPL-compatible modules may use all symbols */
continue;
}
exp = find_symbol(s->name);
if (!exp || exp->module == mod)
continue;
const char *basename = strrchr(mod->name, '/');
if (basename)
basename++;
switch (exp->export) {
case export_gpl:
fatal("modpost: GPL-incompatible module %s "
"uses GPL-only symbol '%s'\n",
basename ? basename : mod->name,
exp->name);
break;
case export_gpl_future:
warn("modpost: GPL-incompatible module %s "
"uses future GPL-only symbol '%s'\n",
basename ? basename : mod->name,
exp->name);
break;
case export_plain: /* ignore */ break;
case export_unknown: /* ignore */ break;
}
}
}

/**
* Header for the generated file
**/
Expand Down Expand Up @@ -1325,6 +1386,12 @@ int main(int argc, char **argv)
read_symbols(argv[optind++]);
}

for (mod = modules; mod; mod = mod->next) {
if (mod->skip)
continue;
check_license(mod);
}

for (mod = modules; mod; mod = mod->next) {
if (mod->skip)
continue;
Expand Down
1 change: 1 addition & 0 deletions trunk/scripts/mod/modpost.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ buf_write(struct buffer *buf, const char *s, int len);
struct module {
struct module *next;
const char *name;
int gpl_compatible;
struct symbol *unres;
int seen;
int skip;
Expand Down

0 comments on commit d4f12e3

Please sign in to comment.