mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-20 19:23:57 +08:00
b24413180f
Many source files in the tree are missing licensing information, which makes it harder for compliance tools to determine the correct license. By default all files without license information are under the default license of the kernel, which is GPL version 2. Update the files which contain no license information with the 'GPL-2.0' SPDX license identifier. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This patch is based on work done by Thomas Gleixner and Kate Stewart and Philippe Ombredanne. How this work was done: Patches were generated and checked against linux-4.14-rc6 for a subset of the use cases: - file had no licensing information it it. - file was a */uapi/* one with no licensing information in it, - file was a */uapi/* one with existing licensing information, Further patches will be generated in subsequent months to fix up cases where non-standard license headers were used, and references to license had to be inferred by heuristics based on keywords. The analysis to determine which SPDX License Identifier to be applied to a file was done in a spreadsheet of side by side results from of the output of two independent scanners (ScanCode & Windriver) producing SPDX tag:value files created by Philippe Ombredanne. Philippe prepared the base worksheet, and did an initial spot review of a few 1000 files. The 4.13 kernel was the starting point of the analysis with 60,537 files assessed. Kate Stewart did a file by file comparison of the scanner results in the spreadsheet to determine which SPDX license identifier(s) to be applied to the file. She confirmed any determination that was not immediately clear with lawyers working with the Linux Foundation. Criteria used to select files for SPDX license identifier tagging was: - Files considered eligible had to be source code files. - Make and config files were included as candidates if they contained >5 lines of source - File already had some variant of a license header in it (even if <5 lines). All documentation files were explicitly excluded. The following heuristics were used to determine which SPDX license identifiers to apply. - when both scanners couldn't find any license traces, file was considered to have no license information in it, and the top level COPYING file license applied. For non */uapi/* files that summary was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 11139 and resulted in the first patch in this series. If that file was a */uapi/* path one, it was "GPL-2.0 WITH Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 WITH Linux-syscall-note 930 and resulted in the second patch in this series. - if a file had some form of licensing information in it, and was one of the */uapi/* ones, it was denoted with the Linux-syscall-note if any GPL family license was found in the file or had no licensing in it (per prior point). Results summary: SPDX license identifier # files ---------------------------------------------------|------ GPL-2.0 WITH Linux-syscall-note 270 GPL-2.0+ WITH Linux-syscall-note 169 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17 LGPL-2.1+ WITH Linux-syscall-note 15 GPL-1.0+ WITH Linux-syscall-note 14 ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5 LGPL-2.0+ WITH Linux-syscall-note 4 LGPL-2.1 WITH Linux-syscall-note 3 ((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3 ((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1 and that resulted in the third patch in this series. - when the two scanners agreed on the detected license(s), that became the concluded license(s). - when there was disagreement between the two scanners (one detected a license but the other didn't, or they both detected different licenses) a manual inspection of the file occurred. - In most cases a manual inspection of the information in the file resulted in a clear resolution of the license that should apply (and which scanner probably needed to revisit its heuristics). - When it was not immediately clear, the license identifier was confirmed with lawyers working with the Linux Foundation. - If there was any question as to the appropriate license identifier, the file was flagged for further research and to be revisited later in time. In total, over 70 hours of logged manual review was done on the spreadsheet to determine the SPDX license identifiers to apply to the source files by Kate, Philippe, Thomas and, in some cases, confirmation by lawyers working with the Linux Foundation. Kate also obtained a third independent scan of the 4.13 code base from FOSSology, and compared selected files where the other two scanners disagreed against that SPDX file, to see if there was new insights. The Windriver scanner is based on an older version of FOSSology in part, so they are related. Thomas did random spot checks in about 500 files from the spreadsheets for the uapi headers and agreed with SPDX license identifier in the files he inspected. For the non-uapi files Thomas did random spot checks in about 15000 files. In initial set of patches against 4.14-rc6, 3 files were found to have copy/paste license identifier errors, and have been fixed to reflect the correct identifier. Additionally Philippe spent 10 hours this week doing a detailed manual inspection and review of the 12,461 patched files from the initial patch version early this week with: - a full scancode scan run, collecting the matched texts, detected license ids and scores - reviewing anything where there was a license detected (about 500+ files) to ensure that the applied SPDX license was correct - reviewing anything where there was no detection but the patch license was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied SPDX license was correct This produced a worksheet with 20 files needing minor correction. This worksheet was then exported into 3 different .csv files for the different types of files to be modified. These .csv files were then reviewed by Greg. Thomas wrote a script to parse the csv files and add the proper SPDX tag to the file, in the format that the file expected. This script was further refined by Greg based on the output to detect more types of files automatically and to distinguish between header and source .c files (which need different comment types.) Finally Greg ran the script using the .csv files to generate the patches. Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
418 lines
12 KiB
C
418 lines
12 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef GENL_MAGIC_FUNC_H
|
|
#define GENL_MAGIC_FUNC_H
|
|
|
|
#include <linux/genl_magic_struct.h>
|
|
|
|
/*
|
|
* Magic: declare tla policy {{{1
|
|
* Magic: declare nested policies
|
|
* {{{2
|
|
*/
|
|
#undef GENL_mc_group
|
|
#define GENL_mc_group(group)
|
|
|
|
#undef GENL_notification
|
|
#define GENL_notification(op_name, op_num, mcast_group, tla_list)
|
|
|
|
#undef GENL_op
|
|
#define GENL_op(op_name, op_num, handler, tla_list)
|
|
|
|
#undef GENL_struct
|
|
#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
|
|
[tag_name] = { .type = NLA_NESTED },
|
|
|
|
static struct nla_policy CONCAT_(GENL_MAGIC_FAMILY, _tla_nl_policy)[] = {
|
|
#include GENL_MAGIC_INCLUDE_FILE
|
|
};
|
|
|
|
#undef GENL_struct
|
|
#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
|
|
static struct nla_policy s_name ## _nl_policy[] __read_mostly = \
|
|
{ s_fields };
|
|
|
|
#undef __field
|
|
#define __field(attr_nr, attr_flag, name, nla_type, _type, __get, \
|
|
__put, __is_signed) \
|
|
[attr_nr] = { .type = nla_type },
|
|
|
|
#undef __array
|
|
#define __array(attr_nr, attr_flag, name, nla_type, _type, maxlen, \
|
|
__get, __put, __is_signed) \
|
|
[attr_nr] = { .type = nla_type, \
|
|
.len = maxlen - (nla_type == NLA_NUL_STRING) },
|
|
|
|
#include GENL_MAGIC_INCLUDE_FILE
|
|
|
|
#ifndef __KERNEL__
|
|
#ifndef pr_info
|
|
#define pr_info(args...) fprintf(stderr, args);
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef GENL_MAGIC_DEBUG
|
|
static void dprint_field(const char *dir, int nla_type,
|
|
const char *name, void *valp)
|
|
{
|
|
__u64 val = valp ? *(__u32 *)valp : 1;
|
|
switch (nla_type) {
|
|
case NLA_U8: val = (__u8)val;
|
|
case NLA_U16: val = (__u16)val;
|
|
case NLA_U32: val = (__u32)val;
|
|
pr_info("%s attr %s: %d 0x%08x\n", dir,
|
|
name, (int)val, (unsigned)val);
|
|
break;
|
|
case NLA_U64:
|
|
val = *(__u64*)valp;
|
|
pr_info("%s attr %s: %lld 0x%08llx\n", dir,
|
|
name, (long long)val, (unsigned long long)val);
|
|
break;
|
|
case NLA_FLAG:
|
|
if (val)
|
|
pr_info("%s attr %s: set\n", dir, name);
|
|
break;
|
|
}
|
|
}
|
|
|
|
static void dprint_array(const char *dir, int nla_type,
|
|
const char *name, const char *val, unsigned len)
|
|
{
|
|
switch (nla_type) {
|
|
case NLA_NUL_STRING:
|
|
if (len && val[len-1] == '\0')
|
|
len--;
|
|
pr_info("%s attr %s: [len:%u] '%s'\n", dir, name, len, val);
|
|
break;
|
|
default:
|
|
/* we can always show 4 byte,
|
|
* thats what nlattr are aligned to. */
|
|
pr_info("%s attr %s: [len:%u] %02x%02x%02x%02x ...\n",
|
|
dir, name, len, val[0], val[1], val[2], val[3]);
|
|
}
|
|
}
|
|
|
|
#define DPRINT_TLA(a, op, b) pr_info("%s %s %s\n", a, op, b);
|
|
|
|
/* Name is a member field name of the struct s.
|
|
* If s is NULL (only parsing, no copy requested in *_from_attrs()),
|
|
* nla is supposed to point to the attribute containing the information
|
|
* corresponding to that struct member. */
|
|
#define DPRINT_FIELD(dir, nla_type, name, s, nla) \
|
|
do { \
|
|
if (s) \
|
|
dprint_field(dir, nla_type, #name, &s->name); \
|
|
else if (nla) \
|
|
dprint_field(dir, nla_type, #name, \
|
|
(nla_type == NLA_FLAG) ? NULL \
|
|
: nla_data(nla)); \
|
|
} while (0)
|
|
|
|
#define DPRINT_ARRAY(dir, nla_type, name, s, nla) \
|
|
do { \
|
|
if (s) \
|
|
dprint_array(dir, nla_type, #name, \
|
|
s->name, s->name ## _len); \
|
|
else if (nla) \
|
|
dprint_array(dir, nla_type, #name, \
|
|
nla_data(nla), nla_len(nla)); \
|
|
} while (0)
|
|
#else
|
|
#define DPRINT_TLA(a, op, b) do {} while (0)
|
|
#define DPRINT_FIELD(dir, nla_type, name, s, nla) do {} while (0)
|
|
#define DPRINT_ARRAY(dir, nla_type, name, s, nla) do {} while (0)
|
|
#endif
|
|
|
|
/*
|
|
* Magic: provide conversion functions {{{1
|
|
* populate struct from attribute table:
|
|
* {{{2
|
|
*/
|
|
|
|
/* processing of generic netlink messages is serialized.
|
|
* use one static buffer for parsing of nested attributes */
|
|
static struct nlattr *nested_attr_tb[128];
|
|
|
|
#ifndef BUILD_BUG_ON
|
|
/* Force a compilation error if condition is true */
|
|
#define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
|
|
/* Force a compilation error if condition is true, but also produce a
|
|
result (of value 0 and type size_t), so the expression can be used
|
|
e.g. in a structure initializer (or where-ever else comma expressions
|
|
aren't permitted). */
|
|
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
|
|
#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
|
|
#endif
|
|
|
|
#undef GENL_struct
|
|
#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
|
|
/* *_from_attrs functions are static, but potentially unused */ \
|
|
static int __ ## s_name ## _from_attrs(struct s_name *s, \
|
|
struct genl_info *info, bool exclude_invariants) \
|
|
{ \
|
|
const int maxtype = ARRAY_SIZE(s_name ## _nl_policy)-1; \
|
|
struct nlattr *tla = info->attrs[tag_number]; \
|
|
struct nlattr **ntb = nested_attr_tb; \
|
|
struct nlattr *nla; \
|
|
int err; \
|
|
BUILD_BUG_ON(ARRAY_SIZE(s_name ## _nl_policy) > ARRAY_SIZE(nested_attr_tb)); \
|
|
if (!tla) \
|
|
return -ENOMSG; \
|
|
DPRINT_TLA(#s_name, "<=-", #tag_name); \
|
|
err = drbd_nla_parse_nested(ntb, maxtype, tla, s_name ## _nl_policy); \
|
|
if (err) \
|
|
return err; \
|
|
\
|
|
s_fields \
|
|
return 0; \
|
|
} __attribute__((unused)) \
|
|
static int s_name ## _from_attrs(struct s_name *s, \
|
|
struct genl_info *info) \
|
|
{ \
|
|
return __ ## s_name ## _from_attrs(s, info, false); \
|
|
} __attribute__((unused)) \
|
|
static int s_name ## _from_attrs_for_change(struct s_name *s, \
|
|
struct genl_info *info) \
|
|
{ \
|
|
return __ ## s_name ## _from_attrs(s, info, true); \
|
|
} __attribute__((unused)) \
|
|
|
|
#define __assign(attr_nr, attr_flag, name, nla_type, type, assignment...) \
|
|
nla = ntb[attr_nr]; \
|
|
if (nla) { \
|
|
if (exclude_invariants && !!((attr_flag) & DRBD_F_INVARIANT)) { \
|
|
pr_info("<< must not change invariant attr: %s\n", #name); \
|
|
return -EEXIST; \
|
|
} \
|
|
assignment; \
|
|
} else if (exclude_invariants && !!((attr_flag) & DRBD_F_INVARIANT)) { \
|
|
/* attribute missing from payload, */ \
|
|
/* which was expected */ \
|
|
} else if ((attr_flag) & DRBD_F_REQUIRED) { \
|
|
pr_info("<< missing attr: %s\n", #name); \
|
|
return -ENOMSG; \
|
|
}
|
|
|
|
#undef __field
|
|
#define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \
|
|
__is_signed) \
|
|
__assign(attr_nr, attr_flag, name, nla_type, type, \
|
|
if (s) \
|
|
s->name = __get(nla); \
|
|
DPRINT_FIELD("<<", nla_type, name, s, nla))
|
|
|
|
/* validate_nla() already checked nla_len <= maxlen appropriately. */
|
|
#undef __array
|
|
#define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \
|
|
__get, __put, __is_signed) \
|
|
__assign(attr_nr, attr_flag, name, nla_type, type, \
|
|
if (s) \
|
|
s->name ## _len = \
|
|
__get(s->name, nla, maxlen); \
|
|
DPRINT_ARRAY("<<", nla_type, name, s, nla))
|
|
|
|
#include GENL_MAGIC_INCLUDE_FILE
|
|
|
|
#undef GENL_struct
|
|
#define GENL_struct(tag_name, tag_number, s_name, s_fields)
|
|
|
|
/*
|
|
* Magic: define op number to op name mapping {{{1
|
|
* {{{2
|
|
*/
|
|
const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
|
|
{
|
|
switch (cmd) {
|
|
#undef GENL_op
|
|
#define GENL_op(op_name, op_num, handler, tla_list) \
|
|
case op_num: return #op_name;
|
|
#include GENL_MAGIC_INCLUDE_FILE
|
|
default:
|
|
return "unknown";
|
|
}
|
|
}
|
|
|
|
#ifdef __KERNEL__
|
|
#include <linux/stringify.h>
|
|
/*
|
|
* Magic: define genl_ops {{{1
|
|
* {{{2
|
|
*/
|
|
|
|
#undef GENL_op
|
|
#define GENL_op(op_name, op_num, handler, tla_list) \
|
|
{ \
|
|
handler \
|
|
.cmd = op_name, \
|
|
.policy = CONCAT_(GENL_MAGIC_FAMILY, _tla_nl_policy), \
|
|
},
|
|
|
|
#define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
|
|
static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
|
|
#include GENL_MAGIC_INCLUDE_FILE
|
|
};
|
|
|
|
#undef GENL_op
|
|
#define GENL_op(op_name, op_num, handler, tla_list)
|
|
|
|
/*
|
|
* Define the genl_family, multicast groups, {{{1
|
|
* and provide register/unregister functions.
|
|
* {{{2
|
|
*/
|
|
#define ZZZ_genl_family CONCAT_(GENL_MAGIC_FAMILY, _genl_family)
|
|
static struct genl_family ZZZ_genl_family;
|
|
/*
|
|
* Magic: define multicast groups
|
|
* Magic: define multicast group registration helper
|
|
*/
|
|
#define ZZZ_genl_mcgrps CONCAT_(GENL_MAGIC_FAMILY, _genl_mcgrps)
|
|
static const struct genl_multicast_group ZZZ_genl_mcgrps[] = {
|
|
#undef GENL_mc_group
|
|
#define GENL_mc_group(group) { .name = #group, },
|
|
#include GENL_MAGIC_INCLUDE_FILE
|
|
};
|
|
|
|
enum CONCAT_(GENL_MAGIC_FAMILY, group_ids) {
|
|
#undef GENL_mc_group
|
|
#define GENL_mc_group(group) CONCAT_(GENL_MAGIC_FAMILY, _group_ ## group),
|
|
#include GENL_MAGIC_INCLUDE_FILE
|
|
};
|
|
|
|
#undef GENL_mc_group
|
|
#define GENL_mc_group(group) \
|
|
static int CONCAT_(GENL_MAGIC_FAMILY, _genl_multicast_ ## group)( \
|
|
struct sk_buff *skb, gfp_t flags) \
|
|
{ \
|
|
unsigned int group_id = \
|
|
CONCAT_(GENL_MAGIC_FAMILY, _group_ ## group); \
|
|
return genlmsg_multicast(&ZZZ_genl_family, skb, 0, \
|
|
group_id, flags); \
|
|
}
|
|
|
|
#include GENL_MAGIC_INCLUDE_FILE
|
|
|
|
#undef GENL_mc_group
|
|
#define GENL_mc_group(group)
|
|
|
|
static struct genl_family ZZZ_genl_family __ro_after_init = {
|
|
.name = __stringify(GENL_MAGIC_FAMILY),
|
|
.version = GENL_MAGIC_VERSION,
|
|
#ifdef GENL_MAGIC_FAMILY_HDRSZ
|
|
.hdrsize = NLA_ALIGN(GENL_MAGIC_FAMILY_HDRSZ),
|
|
#endif
|
|
.maxattr = ARRAY_SIZE(drbd_tla_nl_policy)-1,
|
|
.ops = ZZZ_genl_ops,
|
|
.n_ops = ARRAY_SIZE(ZZZ_genl_ops),
|
|
.mcgrps = ZZZ_genl_mcgrps,
|
|
.n_mcgrps = ARRAY_SIZE(ZZZ_genl_mcgrps),
|
|
.module = THIS_MODULE,
|
|
};
|
|
|
|
int CONCAT_(GENL_MAGIC_FAMILY, _genl_register)(void)
|
|
{
|
|
return genl_register_family(&ZZZ_genl_family);
|
|
}
|
|
|
|
void CONCAT_(GENL_MAGIC_FAMILY, _genl_unregister)(void)
|
|
{
|
|
genl_unregister_family(&ZZZ_genl_family);
|
|
}
|
|
|
|
/*
|
|
* Magic: provide conversion functions {{{1
|
|
* populate skb from struct.
|
|
* {{{2
|
|
*/
|
|
|
|
#undef GENL_op
|
|
#define GENL_op(op_name, op_num, handler, tla_list)
|
|
|
|
#undef GENL_struct
|
|
#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
|
|
static int s_name ## _to_skb(struct sk_buff *skb, struct s_name *s, \
|
|
const bool exclude_sensitive) \
|
|
{ \
|
|
struct nlattr *tla = nla_nest_start(skb, tag_number); \
|
|
if (!tla) \
|
|
goto nla_put_failure; \
|
|
DPRINT_TLA(#s_name, "-=>", #tag_name); \
|
|
s_fields \
|
|
nla_nest_end(skb, tla); \
|
|
return 0; \
|
|
\
|
|
nla_put_failure: \
|
|
if (tla) \
|
|
nla_nest_cancel(skb, tla); \
|
|
return -EMSGSIZE; \
|
|
} \
|
|
static inline int s_name ## _to_priv_skb(struct sk_buff *skb, \
|
|
struct s_name *s) \
|
|
{ \
|
|
return s_name ## _to_skb(skb, s, 0); \
|
|
} \
|
|
static inline int s_name ## _to_unpriv_skb(struct sk_buff *skb, \
|
|
struct s_name *s) \
|
|
{ \
|
|
return s_name ## _to_skb(skb, s, 1); \
|
|
}
|
|
|
|
|
|
#undef __field
|
|
#define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \
|
|
__is_signed) \
|
|
if (!exclude_sensitive || !((attr_flag) & DRBD_F_SENSITIVE)) { \
|
|
DPRINT_FIELD(">>", nla_type, name, s, NULL); \
|
|
if (__put(skb, attr_nr, s->name)) \
|
|
goto nla_put_failure; \
|
|
}
|
|
|
|
#undef __array
|
|
#define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \
|
|
__get, __put, __is_signed) \
|
|
if (!exclude_sensitive || !((attr_flag) & DRBD_F_SENSITIVE)) { \
|
|
DPRINT_ARRAY(">>",nla_type, name, s, NULL); \
|
|
if (__put(skb, attr_nr, min_t(int, maxlen, \
|
|
s->name ## _len + (nla_type == NLA_NUL_STRING)),\
|
|
s->name)) \
|
|
goto nla_put_failure; \
|
|
}
|
|
|
|
#include GENL_MAGIC_INCLUDE_FILE
|
|
|
|
|
|
/* Functions for initializing structs to default values. */
|
|
|
|
#undef __field
|
|
#define __field(attr_nr, attr_flag, name, nla_type, type, __get, __put, \
|
|
__is_signed)
|
|
#undef __array
|
|
#define __array(attr_nr, attr_flag, name, nla_type, type, maxlen, \
|
|
__get, __put, __is_signed)
|
|
#undef __u32_field_def
|
|
#define __u32_field_def(attr_nr, attr_flag, name, default) \
|
|
x->name = default;
|
|
#undef __s32_field_def
|
|
#define __s32_field_def(attr_nr, attr_flag, name, default) \
|
|
x->name = default;
|
|
#undef __flg_field_def
|
|
#define __flg_field_def(attr_nr, attr_flag, name, default) \
|
|
x->name = default;
|
|
#undef __str_field_def
|
|
#define __str_field_def(attr_nr, attr_flag, name, maxlen) \
|
|
memset(x->name, 0, sizeof(x->name)); \
|
|
x->name ## _len = 0;
|
|
#undef GENL_struct
|
|
#define GENL_struct(tag_name, tag_number, s_name, s_fields) \
|
|
static void set_ ## s_name ## _defaults(struct s_name *x) __attribute__((unused)); \
|
|
static void set_ ## s_name ## _defaults(struct s_name *x) { \
|
|
s_fields \
|
|
}
|
|
|
|
#include GENL_MAGIC_INCLUDE_FILE
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
/* }}}1 */
|
|
#endif /* GENL_MAGIC_FUNC_H */
|
|
/* vim: set foldmethod=marker foldlevel=1 nofoldenable : */
|