mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-05 18:14:07 +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>
429 lines
8.6 KiB
C
429 lines
8.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* SCLP control program identification sysfs interface
|
|
*
|
|
* Copyright IBM Corp. 2001, 2007
|
|
* Author(s): Martin Peschke <mpeschke@de.ibm.com>
|
|
* Michael Ernst <mernst@de.ibm.com>
|
|
*/
|
|
|
|
#define KMSG_COMPONENT "sclp_cpi"
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/stat.h>
|
|
#include <linux/device.h>
|
|
#include <linux/string.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/kmod.h>
|
|
#include <linux/timer.h>
|
|
#include <linux/err.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/completion.h>
|
|
#include <linux/export.h>
|
|
#include <asm/ebcdic.h>
|
|
#include <asm/sclp.h>
|
|
|
|
#include "sclp.h"
|
|
#include "sclp_rw.h"
|
|
#include "sclp_cpi_sys.h"
|
|
|
|
#define CPI_LENGTH_NAME 8
|
|
#define CPI_LENGTH_LEVEL 16
|
|
|
|
static DEFINE_MUTEX(sclp_cpi_mutex);
|
|
|
|
struct cpi_evbuf {
|
|
struct evbuf_header header;
|
|
u8 id_format;
|
|
u8 reserved0;
|
|
u8 system_type[CPI_LENGTH_NAME];
|
|
u64 reserved1;
|
|
u8 system_name[CPI_LENGTH_NAME];
|
|
u64 reserved2;
|
|
u64 system_level;
|
|
u64 reserved3;
|
|
u8 sysplex_name[CPI_LENGTH_NAME];
|
|
u8 reserved4[16];
|
|
} __attribute__((packed));
|
|
|
|
struct cpi_sccb {
|
|
struct sccb_header header;
|
|
struct cpi_evbuf cpi_evbuf;
|
|
} __attribute__((packed));
|
|
|
|
static struct sclp_register sclp_cpi_event = {
|
|
.send_mask = EVTYP_CTLPROGIDENT_MASK,
|
|
};
|
|
|
|
static char system_name[CPI_LENGTH_NAME + 1];
|
|
static char sysplex_name[CPI_LENGTH_NAME + 1];
|
|
static char system_type[CPI_LENGTH_NAME + 1];
|
|
static u64 system_level;
|
|
|
|
static void set_data(char *field, char *data)
|
|
{
|
|
memset(field, ' ', CPI_LENGTH_NAME);
|
|
memcpy(field, data, strlen(data));
|
|
sclp_ascebc_str(field, CPI_LENGTH_NAME);
|
|
}
|
|
|
|
static void cpi_callback(struct sclp_req *req, void *data)
|
|
{
|
|
struct completion *completion = data;
|
|
|
|
complete(completion);
|
|
}
|
|
|
|
static struct sclp_req *cpi_prepare_req(void)
|
|
{
|
|
struct sclp_req *req;
|
|
struct cpi_sccb *sccb;
|
|
struct cpi_evbuf *evb;
|
|
|
|
req = kzalloc(sizeof(struct sclp_req), GFP_KERNEL);
|
|
if (!req)
|
|
return ERR_PTR(-ENOMEM);
|
|
sccb = (struct cpi_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
|
|
if (!sccb) {
|
|
kfree(req);
|
|
return ERR_PTR(-ENOMEM);
|
|
}
|
|
|
|
/* setup SCCB for Control-Program Identification */
|
|
sccb->header.length = sizeof(struct cpi_sccb);
|
|
sccb->cpi_evbuf.header.length = sizeof(struct cpi_evbuf);
|
|
sccb->cpi_evbuf.header.type = EVTYP_CTLPROGIDENT;
|
|
evb = &sccb->cpi_evbuf;
|
|
|
|
/* set system type */
|
|
set_data(evb->system_type, system_type);
|
|
|
|
/* set system name */
|
|
set_data(evb->system_name, system_name);
|
|
|
|
/* set system level */
|
|
evb->system_level = system_level;
|
|
|
|
/* set sysplex name */
|
|
set_data(evb->sysplex_name, sysplex_name);
|
|
|
|
/* prepare request data structure presented to SCLP driver */
|
|
req->command = SCLP_CMDW_WRITE_EVENT_DATA;
|
|
req->sccb = sccb;
|
|
req->status = SCLP_REQ_FILLED;
|
|
req->callback = cpi_callback;
|
|
return req;
|
|
}
|
|
|
|
static void cpi_free_req(struct sclp_req *req)
|
|
{
|
|
free_page((unsigned long) req->sccb);
|
|
kfree(req);
|
|
}
|
|
|
|
static int cpi_req(void)
|
|
{
|
|
struct completion completion;
|
|
struct sclp_req *req;
|
|
int rc;
|
|
int response;
|
|
|
|
rc = sclp_register(&sclp_cpi_event);
|
|
if (rc)
|
|
goto out;
|
|
if (!(sclp_cpi_event.sclp_receive_mask & EVTYP_CTLPROGIDENT_MASK)) {
|
|
rc = -EOPNOTSUPP;
|
|
goto out_unregister;
|
|
}
|
|
|
|
req = cpi_prepare_req();
|
|
if (IS_ERR(req)) {
|
|
rc = PTR_ERR(req);
|
|
goto out_unregister;
|
|
}
|
|
|
|
init_completion(&completion);
|
|
req->callback_data = &completion;
|
|
|
|
/* Add request to sclp queue */
|
|
rc = sclp_add_request(req);
|
|
if (rc)
|
|
goto out_free_req;
|
|
|
|
wait_for_completion(&completion);
|
|
|
|
if (req->status != SCLP_REQ_DONE) {
|
|
pr_warn("request failed (status=0x%02x)\n", req->status);
|
|
rc = -EIO;
|
|
goto out_free_req;
|
|
}
|
|
|
|
response = ((struct cpi_sccb *) req->sccb)->header.response_code;
|
|
if (response != 0x0020) {
|
|
pr_warn("request failed with response code 0x%x\n", response);
|
|
rc = -EIO;
|
|
}
|
|
|
|
out_free_req:
|
|
cpi_free_req(req);
|
|
|
|
out_unregister:
|
|
sclp_unregister(&sclp_cpi_event);
|
|
|
|
out:
|
|
return rc;
|
|
}
|
|
|
|
static int check_string(const char *attr, const char *str)
|
|
{
|
|
size_t len;
|
|
size_t i;
|
|
|
|
len = strlen(str);
|
|
|
|
if ((len > 0) && (str[len - 1] == '\n'))
|
|
len--;
|
|
|
|
if (len > CPI_LENGTH_NAME)
|
|
return -EINVAL;
|
|
|
|
for (i = 0; i < len ; i++) {
|
|
if (isalpha(str[i]) || isdigit(str[i]) ||
|
|
strchr("$@# ", str[i]))
|
|
continue;
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void set_string(char *attr, const char *value)
|
|
{
|
|
size_t len;
|
|
size_t i;
|
|
|
|
len = strlen(value);
|
|
|
|
if ((len > 0) && (value[len - 1] == '\n'))
|
|
len--;
|
|
|
|
for (i = 0; i < CPI_LENGTH_NAME; i++) {
|
|
if (i < len)
|
|
attr[i] = toupper(value[i]);
|
|
else
|
|
attr[i] = ' ';
|
|
}
|
|
}
|
|
|
|
static ssize_t system_name_show(struct kobject *kobj,
|
|
struct kobj_attribute *attr, char *page)
|
|
{
|
|
int rc;
|
|
|
|
mutex_lock(&sclp_cpi_mutex);
|
|
rc = snprintf(page, PAGE_SIZE, "%s\n", system_name);
|
|
mutex_unlock(&sclp_cpi_mutex);
|
|
return rc;
|
|
}
|
|
|
|
static ssize_t system_name_store(struct kobject *kobj,
|
|
struct kobj_attribute *attr,
|
|
const char *buf,
|
|
size_t len)
|
|
{
|
|
int rc;
|
|
|
|
rc = check_string("system_name", buf);
|
|
if (rc)
|
|
return rc;
|
|
|
|
mutex_lock(&sclp_cpi_mutex);
|
|
set_string(system_name, buf);
|
|
mutex_unlock(&sclp_cpi_mutex);
|
|
|
|
return len;
|
|
}
|
|
|
|
static struct kobj_attribute system_name_attr =
|
|
__ATTR(system_name, 0644, system_name_show, system_name_store);
|
|
|
|
static ssize_t sysplex_name_show(struct kobject *kobj,
|
|
struct kobj_attribute *attr, char *page)
|
|
{
|
|
int rc;
|
|
|
|
mutex_lock(&sclp_cpi_mutex);
|
|
rc = snprintf(page, PAGE_SIZE, "%s\n", sysplex_name);
|
|
mutex_unlock(&sclp_cpi_mutex);
|
|
return rc;
|
|
}
|
|
|
|
static ssize_t sysplex_name_store(struct kobject *kobj,
|
|
struct kobj_attribute *attr,
|
|
const char *buf,
|
|
size_t len)
|
|
{
|
|
int rc;
|
|
|
|
rc = check_string("sysplex_name", buf);
|
|
if (rc)
|
|
return rc;
|
|
|
|
mutex_lock(&sclp_cpi_mutex);
|
|
set_string(sysplex_name, buf);
|
|
mutex_unlock(&sclp_cpi_mutex);
|
|
|
|
return len;
|
|
}
|
|
|
|
static struct kobj_attribute sysplex_name_attr =
|
|
__ATTR(sysplex_name, 0644, sysplex_name_show, sysplex_name_store);
|
|
|
|
static ssize_t system_type_show(struct kobject *kobj,
|
|
struct kobj_attribute *attr, char *page)
|
|
{
|
|
int rc;
|
|
|
|
mutex_lock(&sclp_cpi_mutex);
|
|
rc = snprintf(page, PAGE_SIZE, "%s\n", system_type);
|
|
mutex_unlock(&sclp_cpi_mutex);
|
|
return rc;
|
|
}
|
|
|
|
static ssize_t system_type_store(struct kobject *kobj,
|
|
struct kobj_attribute *attr,
|
|
const char *buf,
|
|
size_t len)
|
|
{
|
|
int rc;
|
|
|
|
rc = check_string("system_type", buf);
|
|
if (rc)
|
|
return rc;
|
|
|
|
mutex_lock(&sclp_cpi_mutex);
|
|
set_string(system_type, buf);
|
|
mutex_unlock(&sclp_cpi_mutex);
|
|
|
|
return len;
|
|
}
|
|
|
|
static struct kobj_attribute system_type_attr =
|
|
__ATTR(system_type, 0644, system_type_show, system_type_store);
|
|
|
|
static ssize_t system_level_show(struct kobject *kobj,
|
|
struct kobj_attribute *attr, char *page)
|
|
{
|
|
unsigned long long level;
|
|
|
|
mutex_lock(&sclp_cpi_mutex);
|
|
level = system_level;
|
|
mutex_unlock(&sclp_cpi_mutex);
|
|
return snprintf(page, PAGE_SIZE, "%#018llx\n", level);
|
|
}
|
|
|
|
static ssize_t system_level_store(struct kobject *kobj,
|
|
struct kobj_attribute *attr,
|
|
const char *buf,
|
|
size_t len)
|
|
{
|
|
unsigned long long level;
|
|
char *endp;
|
|
|
|
level = simple_strtoull(buf, &endp, 16);
|
|
|
|
if (endp == buf)
|
|
return -EINVAL;
|
|
if (*endp == '\n')
|
|
endp++;
|
|
if (*endp)
|
|
return -EINVAL;
|
|
|
|
mutex_lock(&sclp_cpi_mutex);
|
|
system_level = level;
|
|
mutex_unlock(&sclp_cpi_mutex);
|
|
return len;
|
|
}
|
|
|
|
static struct kobj_attribute system_level_attr =
|
|
__ATTR(system_level, 0644, system_level_show, system_level_store);
|
|
|
|
static ssize_t set_store(struct kobject *kobj,
|
|
struct kobj_attribute *attr,
|
|
const char *buf, size_t len)
|
|
{
|
|
int rc;
|
|
|
|
mutex_lock(&sclp_cpi_mutex);
|
|
rc = cpi_req();
|
|
mutex_unlock(&sclp_cpi_mutex);
|
|
if (rc)
|
|
return rc;
|
|
|
|
return len;
|
|
}
|
|
|
|
static struct kobj_attribute set_attr = __ATTR(set, 0200, NULL, set_store);
|
|
|
|
static struct attribute *cpi_attrs[] = {
|
|
&system_name_attr.attr,
|
|
&sysplex_name_attr.attr,
|
|
&system_type_attr.attr,
|
|
&system_level_attr.attr,
|
|
&set_attr.attr,
|
|
NULL,
|
|
};
|
|
|
|
static struct attribute_group cpi_attr_group = {
|
|
.attrs = cpi_attrs,
|
|
};
|
|
|
|
static struct kset *cpi_kset;
|
|
|
|
int sclp_cpi_set_data(const char *system, const char *sysplex, const char *type,
|
|
const u64 level)
|
|
{
|
|
int rc;
|
|
|
|
rc = check_string("system_name", system);
|
|
if (rc)
|
|
return rc;
|
|
rc = check_string("sysplex_name", sysplex);
|
|
if (rc)
|
|
return rc;
|
|
rc = check_string("system_type", type);
|
|
if (rc)
|
|
return rc;
|
|
|
|
mutex_lock(&sclp_cpi_mutex);
|
|
set_string(system_name, system);
|
|
set_string(sysplex_name, sysplex);
|
|
set_string(system_type, type);
|
|
system_level = level;
|
|
|
|
rc = cpi_req();
|
|
mutex_unlock(&sclp_cpi_mutex);
|
|
|
|
return rc;
|
|
}
|
|
EXPORT_SYMBOL(sclp_cpi_set_data);
|
|
|
|
static int __init cpi_init(void)
|
|
{
|
|
int rc;
|
|
|
|
cpi_kset = kset_create_and_add("cpi", NULL, firmware_kobj);
|
|
if (!cpi_kset)
|
|
return -ENOMEM;
|
|
|
|
rc = sysfs_create_group(&cpi_kset->kobj, &cpi_attr_group);
|
|
if (rc)
|
|
kset_unregister(cpi_kset);
|
|
|
|
return rc;
|
|
}
|
|
|
|
__initcall(cpi_init);
|