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>
464 lines
9.9 KiB
C
464 lines
9.9 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* net/atm/resources.c - Statically allocated resources */
|
|
|
|
/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
|
|
|
|
/* Fixes
|
|
* Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
* 2002/01 - don't free the whole struct sock on sk->destruct time,
|
|
* use the default destruct function initialized by sock_init_data */
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
|
|
|
|
#include <linux/ctype.h>
|
|
#include <linux/string.h>
|
|
#include <linux/atmdev.h>
|
|
#include <linux/sonet.h>
|
|
#include <linux/kernel.h> /* for barrier */
|
|
#include <linux/module.h>
|
|
#include <linux/bitops.h>
|
|
#include <linux/capability.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <net/sock.h> /* for struct sock */
|
|
|
|
#include "common.h"
|
|
#include "resources.h"
|
|
#include "addr.h"
|
|
|
|
|
|
LIST_HEAD(atm_devs);
|
|
DEFINE_MUTEX(atm_dev_mutex);
|
|
|
|
static struct atm_dev *__alloc_atm_dev(const char *type)
|
|
{
|
|
struct atm_dev *dev;
|
|
|
|
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
|
|
if (!dev)
|
|
return NULL;
|
|
dev->type = type;
|
|
dev->signal = ATM_PHY_SIG_UNKNOWN;
|
|
dev->link_rate = ATM_OC3_PCR;
|
|
spin_lock_init(&dev->lock);
|
|
INIT_LIST_HEAD(&dev->local);
|
|
INIT_LIST_HEAD(&dev->lecs);
|
|
|
|
return dev;
|
|
}
|
|
|
|
static struct atm_dev *__atm_dev_lookup(int number)
|
|
{
|
|
struct atm_dev *dev;
|
|
struct list_head *p;
|
|
|
|
list_for_each(p, &atm_devs) {
|
|
dev = list_entry(p, struct atm_dev, dev_list);
|
|
if (dev->number == number) {
|
|
atm_dev_hold(dev);
|
|
return dev;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
struct atm_dev *atm_dev_lookup(int number)
|
|
{
|
|
struct atm_dev *dev;
|
|
|
|
mutex_lock(&atm_dev_mutex);
|
|
dev = __atm_dev_lookup(number);
|
|
mutex_unlock(&atm_dev_mutex);
|
|
return dev;
|
|
}
|
|
EXPORT_SYMBOL(atm_dev_lookup);
|
|
|
|
struct atm_dev *atm_dev_register(const char *type, struct device *parent,
|
|
const struct atmdev_ops *ops, int number,
|
|
unsigned long *flags)
|
|
{
|
|
struct atm_dev *dev, *inuse;
|
|
|
|
dev = __alloc_atm_dev(type);
|
|
if (!dev) {
|
|
pr_err("no space for dev %s\n", type);
|
|
return NULL;
|
|
}
|
|
mutex_lock(&atm_dev_mutex);
|
|
if (number != -1) {
|
|
inuse = __atm_dev_lookup(number);
|
|
if (inuse) {
|
|
atm_dev_put(inuse);
|
|
mutex_unlock(&atm_dev_mutex);
|
|
kfree(dev);
|
|
return NULL;
|
|
}
|
|
dev->number = number;
|
|
} else {
|
|
dev->number = 0;
|
|
while ((inuse = __atm_dev_lookup(dev->number))) {
|
|
atm_dev_put(inuse);
|
|
dev->number++;
|
|
}
|
|
}
|
|
|
|
dev->ops = ops;
|
|
if (flags)
|
|
dev->flags = *flags;
|
|
else
|
|
memset(&dev->flags, 0, sizeof(dev->flags));
|
|
memset(&dev->stats, 0, sizeof(dev->stats));
|
|
refcount_set(&dev->refcnt, 1);
|
|
|
|
if (atm_proc_dev_register(dev) < 0) {
|
|
pr_err("atm_proc_dev_register failed for dev %s\n", type);
|
|
goto out_fail;
|
|
}
|
|
|
|
if (atm_register_sysfs(dev, parent) < 0) {
|
|
pr_err("atm_register_sysfs failed for dev %s\n", type);
|
|
atm_proc_dev_deregister(dev);
|
|
goto out_fail;
|
|
}
|
|
|
|
list_add_tail(&dev->dev_list, &atm_devs);
|
|
|
|
out:
|
|
mutex_unlock(&atm_dev_mutex);
|
|
return dev;
|
|
|
|
out_fail:
|
|
kfree(dev);
|
|
dev = NULL;
|
|
goto out;
|
|
}
|
|
EXPORT_SYMBOL(atm_dev_register);
|
|
|
|
void atm_dev_deregister(struct atm_dev *dev)
|
|
{
|
|
BUG_ON(test_bit(ATM_DF_REMOVED, &dev->flags));
|
|
set_bit(ATM_DF_REMOVED, &dev->flags);
|
|
|
|
/*
|
|
* if we remove current device from atm_devs list, new device
|
|
* with same number can appear, such we need deregister proc,
|
|
* release async all vccs and remove them from vccs list too
|
|
*/
|
|
mutex_lock(&atm_dev_mutex);
|
|
list_del(&dev->dev_list);
|
|
mutex_unlock(&atm_dev_mutex);
|
|
|
|
atm_dev_release_vccs(dev);
|
|
atm_unregister_sysfs(dev);
|
|
atm_proc_dev_deregister(dev);
|
|
|
|
atm_dev_put(dev);
|
|
}
|
|
EXPORT_SYMBOL(atm_dev_deregister);
|
|
|
|
static void copy_aal_stats(struct k_atm_aal_stats *from,
|
|
struct atm_aal_stats *to)
|
|
{
|
|
#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
|
|
__AAL_STAT_ITEMS
|
|
#undef __HANDLE_ITEM
|
|
}
|
|
|
|
static void subtract_aal_stats(struct k_atm_aal_stats *from,
|
|
struct atm_aal_stats *to)
|
|
{
|
|
#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
|
|
__AAL_STAT_ITEMS
|
|
#undef __HANDLE_ITEM
|
|
}
|
|
|
|
static int fetch_stats(struct atm_dev *dev, struct atm_dev_stats __user *arg,
|
|
int zero)
|
|
{
|
|
struct atm_dev_stats tmp;
|
|
int error = 0;
|
|
|
|
copy_aal_stats(&dev->stats.aal0, &tmp.aal0);
|
|
copy_aal_stats(&dev->stats.aal34, &tmp.aal34);
|
|
copy_aal_stats(&dev->stats.aal5, &tmp.aal5);
|
|
if (arg)
|
|
error = copy_to_user(arg, &tmp, sizeof(tmp));
|
|
if (zero && !error) {
|
|
subtract_aal_stats(&dev->stats.aal0, &tmp.aal0);
|
|
subtract_aal_stats(&dev->stats.aal34, &tmp.aal34);
|
|
subtract_aal_stats(&dev->stats.aal5, &tmp.aal5);
|
|
}
|
|
return error ? -EFAULT : 0;
|
|
}
|
|
|
|
int atm_dev_ioctl(unsigned int cmd, void __user *arg, int compat)
|
|
{
|
|
void __user *buf;
|
|
int error, len, number, size = 0;
|
|
struct atm_dev *dev;
|
|
struct list_head *p;
|
|
int *tmp_buf, *tmp_p;
|
|
int __user *sioc_len;
|
|
int __user *iobuf_len;
|
|
|
|
#ifndef CONFIG_COMPAT
|
|
compat = 0; /* Just so the compiler _knows_ */
|
|
#endif
|
|
|
|
switch (cmd) {
|
|
case ATM_GETNAMES:
|
|
if (compat) {
|
|
#ifdef CONFIG_COMPAT
|
|
struct compat_atm_iobuf __user *ciobuf = arg;
|
|
compat_uptr_t cbuf;
|
|
iobuf_len = &ciobuf->length;
|
|
if (get_user(cbuf, &ciobuf->buffer))
|
|
return -EFAULT;
|
|
buf = compat_ptr(cbuf);
|
|
#endif
|
|
} else {
|
|
struct atm_iobuf __user *iobuf = arg;
|
|
iobuf_len = &iobuf->length;
|
|
if (get_user(buf, &iobuf->buffer))
|
|
return -EFAULT;
|
|
}
|
|
if (get_user(len, iobuf_len))
|
|
return -EFAULT;
|
|
mutex_lock(&atm_dev_mutex);
|
|
list_for_each(p, &atm_devs)
|
|
size += sizeof(int);
|
|
if (size > len) {
|
|
mutex_unlock(&atm_dev_mutex);
|
|
return -E2BIG;
|
|
}
|
|
tmp_buf = kmalloc(size, GFP_ATOMIC);
|
|
if (!tmp_buf) {
|
|
mutex_unlock(&atm_dev_mutex);
|
|
return -ENOMEM;
|
|
}
|
|
tmp_p = tmp_buf;
|
|
list_for_each(p, &atm_devs) {
|
|
dev = list_entry(p, struct atm_dev, dev_list);
|
|
*tmp_p++ = dev->number;
|
|
}
|
|
mutex_unlock(&atm_dev_mutex);
|
|
error = ((copy_to_user(buf, tmp_buf, size)) ||
|
|
put_user(size, iobuf_len))
|
|
? -EFAULT : 0;
|
|
kfree(tmp_buf);
|
|
return error;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (compat) {
|
|
#ifdef CONFIG_COMPAT
|
|
struct compat_atmif_sioc __user *csioc = arg;
|
|
compat_uptr_t carg;
|
|
|
|
sioc_len = &csioc->length;
|
|
if (get_user(carg, &csioc->arg))
|
|
return -EFAULT;
|
|
buf = compat_ptr(carg);
|
|
|
|
if (get_user(len, &csioc->length))
|
|
return -EFAULT;
|
|
if (get_user(number, &csioc->number))
|
|
return -EFAULT;
|
|
#endif
|
|
} else {
|
|
struct atmif_sioc __user *sioc = arg;
|
|
|
|
sioc_len = &sioc->length;
|
|
if (get_user(buf, &sioc->arg))
|
|
return -EFAULT;
|
|
if (get_user(len, &sioc->length))
|
|
return -EFAULT;
|
|
if (get_user(number, &sioc->number))
|
|
return -EFAULT;
|
|
}
|
|
|
|
dev = try_then_request_module(atm_dev_lookup(number), "atm-device-%d",
|
|
number);
|
|
if (!dev)
|
|
return -ENODEV;
|
|
|
|
switch (cmd) {
|
|
case ATM_GETTYPE:
|
|
size = strlen(dev->type) + 1;
|
|
if (copy_to_user(buf, dev->type, size)) {
|
|
error = -EFAULT;
|
|
goto done;
|
|
}
|
|
break;
|
|
case ATM_GETESI:
|
|
size = ESI_LEN;
|
|
if (copy_to_user(buf, dev->esi, size)) {
|
|
error = -EFAULT;
|
|
goto done;
|
|
}
|
|
break;
|
|
case ATM_SETESI:
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < ESI_LEN; i++)
|
|
if (dev->esi[i]) {
|
|
error = -EEXIST;
|
|
goto done;
|
|
}
|
|
}
|
|
/* fall through */
|
|
case ATM_SETESIF:
|
|
{
|
|
unsigned char esi[ESI_LEN];
|
|
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
error = -EPERM;
|
|
goto done;
|
|
}
|
|
if (copy_from_user(esi, buf, ESI_LEN)) {
|
|
error = -EFAULT;
|
|
goto done;
|
|
}
|
|
memcpy(dev->esi, esi, ESI_LEN);
|
|
error = ESI_LEN;
|
|
goto done;
|
|
}
|
|
case ATM_GETSTATZ:
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
error = -EPERM;
|
|
goto done;
|
|
}
|
|
/* fall through */
|
|
case ATM_GETSTAT:
|
|
size = sizeof(struct atm_dev_stats);
|
|
error = fetch_stats(dev, buf, cmd == ATM_GETSTATZ);
|
|
if (error)
|
|
goto done;
|
|
break;
|
|
case ATM_GETCIRANGE:
|
|
size = sizeof(struct atm_cirange);
|
|
if (copy_to_user(buf, &dev->ci_range, size)) {
|
|
error = -EFAULT;
|
|
goto done;
|
|
}
|
|
break;
|
|
case ATM_GETLINKRATE:
|
|
size = sizeof(int);
|
|
if (copy_to_user(buf, &dev->link_rate, size)) {
|
|
error = -EFAULT;
|
|
goto done;
|
|
}
|
|
break;
|
|
case ATM_RSTADDR:
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
error = -EPERM;
|
|
goto done;
|
|
}
|
|
atm_reset_addr(dev, ATM_ADDR_LOCAL);
|
|
break;
|
|
case ATM_ADDADDR:
|
|
case ATM_DELADDR:
|
|
case ATM_ADDLECSADDR:
|
|
case ATM_DELLECSADDR:
|
|
{
|
|
struct sockaddr_atmsvc addr;
|
|
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
error = -EPERM;
|
|
goto done;
|
|
}
|
|
|
|
if (copy_from_user(&addr, buf, sizeof(addr))) {
|
|
error = -EFAULT;
|
|
goto done;
|
|
}
|
|
if (cmd == ATM_ADDADDR || cmd == ATM_ADDLECSADDR)
|
|
error = atm_add_addr(dev, &addr,
|
|
(cmd == ATM_ADDADDR ?
|
|
ATM_ADDR_LOCAL : ATM_ADDR_LECS));
|
|
else
|
|
error = atm_del_addr(dev, &addr,
|
|
(cmd == ATM_DELADDR ?
|
|
ATM_ADDR_LOCAL : ATM_ADDR_LECS));
|
|
goto done;
|
|
}
|
|
case ATM_GETADDR:
|
|
case ATM_GETLECSADDR:
|
|
error = atm_get_addr(dev, buf, len,
|
|
(cmd == ATM_GETADDR ?
|
|
ATM_ADDR_LOCAL : ATM_ADDR_LECS));
|
|
if (error < 0)
|
|
goto done;
|
|
size = error;
|
|
/* may return 0, but later on size == 0 means "don't
|
|
write the length" */
|
|
error = put_user(size, sioc_len) ? -EFAULT : 0;
|
|
goto done;
|
|
case ATM_SETLOOP:
|
|
if (__ATM_LM_XTRMT((int) (unsigned long) buf) &&
|
|
__ATM_LM_XTLOC((int) (unsigned long) buf) >
|
|
__ATM_LM_XTRMT((int) (unsigned long) buf)) {
|
|
error = -EINVAL;
|
|
goto done;
|
|
}
|
|
/* fall through */
|
|
case ATM_SETCIRANGE:
|
|
case SONET_GETSTATZ:
|
|
case SONET_SETDIAG:
|
|
case SONET_CLRDIAG:
|
|
case SONET_SETFRAMING:
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
error = -EPERM;
|
|
goto done;
|
|
}
|
|
/* fall through */
|
|
default:
|
|
if (compat) {
|
|
#ifdef CONFIG_COMPAT
|
|
if (!dev->ops->compat_ioctl) {
|
|
error = -EINVAL;
|
|
goto done;
|
|
}
|
|
size = dev->ops->compat_ioctl(dev, cmd, buf);
|
|
#endif
|
|
} else {
|
|
if (!dev->ops->ioctl) {
|
|
error = -EINVAL;
|
|
goto done;
|
|
}
|
|
size = dev->ops->ioctl(dev, cmd, buf);
|
|
}
|
|
if (size < 0) {
|
|
error = (size == -ENOIOCTLCMD ? -ENOTTY : size);
|
|
goto done;
|
|
}
|
|
}
|
|
|
|
if (size)
|
|
error = put_user(size, sioc_len) ? -EFAULT : 0;
|
|
else
|
|
error = 0;
|
|
done:
|
|
atm_dev_put(dev);
|
|
return error;
|
|
}
|
|
|
|
void *atm_dev_seq_start(struct seq_file *seq, loff_t *pos)
|
|
{
|
|
mutex_lock(&atm_dev_mutex);
|
|
return seq_list_start_head(&atm_devs, *pos);
|
|
}
|
|
|
|
void atm_dev_seq_stop(struct seq_file *seq, void *v)
|
|
{
|
|
mutex_unlock(&atm_dev_mutex);
|
|
}
|
|
|
|
void *atm_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
{
|
|
return seq_list_next(v, &atm_devs, pos);
|
|
}
|