License cleanup: add SPDX GPL-2.0 license identifier to files with no license
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>
2017-11-01 17:07:57 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-03-23 02:34:40 +03:00
|
|
|
/*
|
|
|
|
* Convert integer string representation to an integer.
|
|
|
|
* If an integer doesn't fit into specified type, -E is returned.
|
|
|
|
*
|
|
|
|
* Integer starts with optional sign.
|
|
|
|
* kstrtou*() functions do not accept sign "-".
|
|
|
|
*
|
|
|
|
* Radix 0 means autodetection: leading "0x" implies radix 16,
|
|
|
|
* leading "0" implies radix 8, otherwise radix is 10.
|
|
|
|
* Autodetection hints work after optional sign, but not before.
|
|
|
|
*
|
|
|
|
* If -E is returned, result is not touched.
|
|
|
|
*/
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/math64.h>
|
2011-11-17 06:29:17 +04:00
|
|
|
#include <linux/export.h>
|
2011-03-23 02:34:40 +03:00
|
|
|
#include <linux/types.h>
|
2016-12-24 22:46:01 +03:00
|
|
|
#include <linux/uaccess.h>
|
2011-11-01 04:12:28 +04:00
|
|
|
#include "kstrtox.h"
|
2011-03-23 02:34:40 +03:00
|
|
|
|
2011-11-01 04:12:28 +04:00
|
|
|
const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
|
2011-03-23 02:34:40 +03:00
|
|
|
{
|
2011-11-01 04:12:28 +04:00
|
|
|
if (*base == 0) {
|
2011-03-23 02:34:40 +03:00
|
|
|
if (s[0] == '0') {
|
|
|
|
if (_tolower(s[1]) == 'x' && isxdigit(s[2]))
|
2011-11-01 04:12:28 +04:00
|
|
|
*base = 16;
|
2011-03-23 02:34:40 +03:00
|
|
|
else
|
2011-11-01 04:12:28 +04:00
|
|
|
*base = 8;
|
2011-03-23 02:34:40 +03:00
|
|
|
} else
|
2011-11-01 04:12:28 +04:00
|
|
|
*base = 10;
|
2011-03-23 02:34:40 +03:00
|
|
|
}
|
2011-11-01 04:12:28 +04:00
|
|
|
if (*base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
|
2011-03-23 02:34:40 +03:00
|
|
|
s += 2;
|
2011-11-01 04:12:28 +04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert non-negative integer string representation in explicitly given radix
|
|
|
|
* to an integer.
|
|
|
|
* Return number of characters consumed maybe or-ed with overflow bit.
|
|
|
|
* If overflow occurs, result integer (incorrect) is still returned.
|
|
|
|
*
|
|
|
|
* Don't you dare use this function.
|
|
|
|
*/
|
2012-02-09 19:48:20 +04:00
|
|
|
unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p)
|
2011-11-01 04:12:28 +04:00
|
|
|
{
|
2012-02-09 19:48:20 +04:00
|
|
|
unsigned long long res;
|
2011-11-01 04:12:28 +04:00
|
|
|
unsigned int rv;
|
2011-03-23 02:34:40 +03:00
|
|
|
|
2012-02-09 19:48:20 +04:00
|
|
|
res = 0;
|
2011-11-01 04:12:28 +04:00
|
|
|
rv = 0;
|
2017-07-11 01:51:38 +03:00
|
|
|
while (1) {
|
2017-07-11 01:51:41 +03:00
|
|
|
unsigned int c = *s;
|
|
|
|
unsigned int lc = c | 0x20; /* don't tolower() this line */
|
2011-03-23 02:34:40 +03:00
|
|
|
unsigned int val;
|
|
|
|
|
2017-07-11 01:51:41 +03:00
|
|
|
if ('0' <= c && c <= '9')
|
|
|
|
val = c - '0';
|
|
|
|
else if ('a' <= lc && lc <= 'f')
|
|
|
|
val = lc - 'a' + 10;
|
2011-04-15 02:22:02 +04:00
|
|
|
else
|
2011-11-01 04:12:28 +04:00
|
|
|
break;
|
2011-03-23 02:34:40 +03:00
|
|
|
|
|
|
|
if (val >= base)
|
2011-11-01 04:12:28 +04:00
|
|
|
break;
|
2012-02-09 19:48:20 +04:00
|
|
|
/*
|
|
|
|
* Check for overflow only if we are within range of
|
|
|
|
* it in the max base we support (16)
|
|
|
|
*/
|
|
|
|
if (unlikely(res & (~0ull << 60))) {
|
|
|
|
if (res > div_u64(ULLONG_MAX - val, base))
|
2016-10-11 23:51:32 +03:00
|
|
|
rv |= KSTRTOX_OVERFLOW;
|
2012-02-09 19:48:20 +04:00
|
|
|
}
|
|
|
|
res = res * base + val;
|
2011-11-01 04:12:28 +04:00
|
|
|
rv++;
|
2011-03-23 02:34:40 +03:00
|
|
|
s++;
|
|
|
|
}
|
2012-02-09 19:48:20 +04:00
|
|
|
*p = res;
|
2011-11-01 04:12:28 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
|
|
|
|
{
|
|
|
|
unsigned long long _res;
|
|
|
|
unsigned int rv;
|
|
|
|
|
|
|
|
s = _parse_integer_fixup_radix(s, &base);
|
|
|
|
rv = _parse_integer(s, base, &_res);
|
|
|
|
if (rv & KSTRTOX_OVERFLOW)
|
|
|
|
return -ERANGE;
|
|
|
|
if (rv == 0)
|
|
|
|
return -EINVAL;
|
|
|
|
s += rv;
|
|
|
|
if (*s == '\n')
|
|
|
|
s++;
|
|
|
|
if (*s)
|
2011-03-23 02:34:40 +03:00
|
|
|
return -EINVAL;
|
2011-11-01 04:12:28 +04:00
|
|
|
*res = _res;
|
2011-03-23 02:34:40 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-18 04:03:04 +04:00
|
|
|
/**
|
|
|
|
* kstrtoull - convert a string to an unsigned long long
|
|
|
|
* @s: The start of the string. The string must be null-terminated, and may also
|
|
|
|
* include a single newline before its terminating null. The first character
|
|
|
|
* may also be a plus sign, but not a minus sign.
|
|
|
|
* @base: The number base to use. The maximum supported base is 16. If base is
|
|
|
|
* given as 0, then the base of the string is automatically detected with the
|
|
|
|
* conventional semantics - If it begins with 0x the number will be parsed as a
|
|
|
|
* hexadecimal (case insensitive), if it otherwise begins with 0, it will be
|
|
|
|
* parsed as an octal number. Otherwise it will be parsed as a decimal.
|
|
|
|
* @res: Where to write the result of the conversion on success.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
|
2020-08-12 04:34:56 +03:00
|
|
|
* Preferred over simple_strtoull(). Return code must be checked.
|
2012-12-18 04:03:04 +04:00
|
|
|
*/
|
2011-03-23 02:34:40 +03:00
|
|
|
int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
|
|
|
|
{
|
|
|
|
if (s[0] == '+')
|
|
|
|
s++;
|
|
|
|
return _kstrtoull(s, base, res);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(kstrtoull);
|
|
|
|
|
2012-12-18 04:03:04 +04:00
|
|
|
/**
|
|
|
|
* kstrtoll - convert a string to a long long
|
|
|
|
* @s: The start of the string. The string must be null-terminated, and may also
|
|
|
|
* include a single newline before its terminating null. The first character
|
|
|
|
* may also be a plus sign or a minus sign.
|
|
|
|
* @base: The number base to use. The maximum supported base is 16. If base is
|
|
|
|
* given as 0, then the base of the string is automatically detected with the
|
|
|
|
* conventional semantics - If it begins with 0x the number will be parsed as a
|
|
|
|
* hexadecimal (case insensitive), if it otherwise begins with 0, it will be
|
|
|
|
* parsed as an octal number. Otherwise it will be parsed as a decimal.
|
|
|
|
* @res: Where to write the result of the conversion on success.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
|
2020-08-12 04:34:56 +03:00
|
|
|
* Preferred over simple_strtoll(). Return code must be checked.
|
2012-12-18 04:03:04 +04:00
|
|
|
*/
|
2011-03-23 02:34:40 +03:00
|
|
|
int kstrtoll(const char *s, unsigned int base, long long *res)
|
|
|
|
{
|
|
|
|
unsigned long long tmp;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (s[0] == '-') {
|
|
|
|
rv = _kstrtoull(s + 1, base, &tmp);
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
2015-09-10 01:36:17 +03:00
|
|
|
if ((long long)-tmp > 0)
|
2011-03-23 02:34:40 +03:00
|
|
|
return -ERANGE;
|
|
|
|
*res = -tmp;
|
|
|
|
} else {
|
|
|
|
rv = kstrtoull(s, base, &tmp);
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
|
|
|
if ((long long)tmp < 0)
|
|
|
|
return -ERANGE;
|
|
|
|
*res = tmp;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(kstrtoll);
|
|
|
|
|
|
|
|
/* Internal, do not use. */
|
|
|
|
int _kstrtoul(const char *s, unsigned int base, unsigned long *res)
|
|
|
|
{
|
|
|
|
unsigned long long tmp;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = kstrtoull(s, base, &tmp);
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
2018-10-31 01:05:46 +03:00
|
|
|
if (tmp != (unsigned long)tmp)
|
2011-03-23 02:34:40 +03:00
|
|
|
return -ERANGE;
|
|
|
|
*res = tmp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(_kstrtoul);
|
|
|
|
|
|
|
|
/* Internal, do not use. */
|
|
|
|
int _kstrtol(const char *s, unsigned int base, long *res)
|
|
|
|
{
|
|
|
|
long long tmp;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = kstrtoll(s, base, &tmp);
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
2018-10-31 01:05:46 +03:00
|
|
|
if (tmp != (long)tmp)
|
2011-03-23 02:34:40 +03:00
|
|
|
return -ERANGE;
|
|
|
|
*res = tmp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(_kstrtol);
|
|
|
|
|
2012-12-18 04:03:04 +04:00
|
|
|
/**
|
|
|
|
* kstrtouint - convert a string to an unsigned int
|
|
|
|
* @s: The start of the string. The string must be null-terminated, and may also
|
|
|
|
* include a single newline before its terminating null. The first character
|
|
|
|
* may also be a plus sign, but not a minus sign.
|
|
|
|
* @base: The number base to use. The maximum supported base is 16. If base is
|
|
|
|
* given as 0, then the base of the string is automatically detected with the
|
|
|
|
* conventional semantics - If it begins with 0x the number will be parsed as a
|
|
|
|
* hexadecimal (case insensitive), if it otherwise begins with 0, it will be
|
|
|
|
* parsed as an octal number. Otherwise it will be parsed as a decimal.
|
|
|
|
* @res: Where to write the result of the conversion on success.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
|
2020-08-12 04:34:56 +03:00
|
|
|
* Preferred over simple_strtoul(). Return code must be checked.
|
2012-12-18 04:03:04 +04:00
|
|
|
*/
|
2011-03-23 02:34:40 +03:00
|
|
|
int kstrtouint(const char *s, unsigned int base, unsigned int *res)
|
|
|
|
{
|
|
|
|
unsigned long long tmp;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = kstrtoull(s, base, &tmp);
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
2018-10-31 01:05:46 +03:00
|
|
|
if (tmp != (unsigned int)tmp)
|
2011-03-23 02:34:40 +03:00
|
|
|
return -ERANGE;
|
|
|
|
*res = tmp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(kstrtouint);
|
|
|
|
|
2012-12-18 04:03:04 +04:00
|
|
|
/**
|
|
|
|
* kstrtoint - convert a string to an int
|
|
|
|
* @s: The start of the string. The string must be null-terminated, and may also
|
|
|
|
* include a single newline before its terminating null. The first character
|
|
|
|
* may also be a plus sign or a minus sign.
|
|
|
|
* @base: The number base to use. The maximum supported base is 16. If base is
|
|
|
|
* given as 0, then the base of the string is automatically detected with the
|
|
|
|
* conventional semantics - If it begins with 0x the number will be parsed as a
|
|
|
|
* hexadecimal (case insensitive), if it otherwise begins with 0, it will be
|
|
|
|
* parsed as an octal number. Otherwise it will be parsed as a decimal.
|
|
|
|
* @res: Where to write the result of the conversion on success.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
|
2020-08-12 04:34:56 +03:00
|
|
|
* Preferred over simple_strtol(). Return code must be checked.
|
2012-12-18 04:03:04 +04:00
|
|
|
*/
|
2011-03-23 02:34:40 +03:00
|
|
|
int kstrtoint(const char *s, unsigned int base, int *res)
|
|
|
|
{
|
|
|
|
long long tmp;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = kstrtoll(s, base, &tmp);
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
2018-10-31 01:05:46 +03:00
|
|
|
if (tmp != (int)tmp)
|
2011-03-23 02:34:40 +03:00
|
|
|
return -ERANGE;
|
|
|
|
*res = tmp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(kstrtoint);
|
|
|
|
|
|
|
|
int kstrtou16(const char *s, unsigned int base, u16 *res)
|
|
|
|
{
|
|
|
|
unsigned long long tmp;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = kstrtoull(s, base, &tmp);
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
2018-10-31 01:05:46 +03:00
|
|
|
if (tmp != (u16)tmp)
|
2011-03-23 02:34:40 +03:00
|
|
|
return -ERANGE;
|
|
|
|
*res = tmp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(kstrtou16);
|
|
|
|
|
|
|
|
int kstrtos16(const char *s, unsigned int base, s16 *res)
|
|
|
|
{
|
|
|
|
long long tmp;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = kstrtoll(s, base, &tmp);
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
2018-10-31 01:05:46 +03:00
|
|
|
if (tmp != (s16)tmp)
|
2011-03-23 02:34:40 +03:00
|
|
|
return -ERANGE;
|
|
|
|
*res = tmp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(kstrtos16);
|
|
|
|
|
|
|
|
int kstrtou8(const char *s, unsigned int base, u8 *res)
|
|
|
|
{
|
|
|
|
unsigned long long tmp;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = kstrtoull(s, base, &tmp);
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
2018-10-31 01:05:46 +03:00
|
|
|
if (tmp != (u8)tmp)
|
2011-03-23 02:34:40 +03:00
|
|
|
return -ERANGE;
|
|
|
|
*res = tmp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(kstrtou8);
|
|
|
|
|
|
|
|
int kstrtos8(const char *s, unsigned int base, s8 *res)
|
|
|
|
{
|
|
|
|
long long tmp;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = kstrtoll(s, base, &tmp);
|
|
|
|
if (rv < 0)
|
|
|
|
return rv;
|
2018-10-31 01:05:46 +03:00
|
|
|
if (tmp != (s8)tmp)
|
2011-03-23 02:34:40 +03:00
|
|
|
return -ERANGE;
|
|
|
|
*res = tmp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(kstrtos8);
|
2011-05-25 04:13:31 +04:00
|
|
|
|
2016-03-18 00:22:50 +03:00
|
|
|
/**
|
|
|
|
* kstrtobool - convert common user inputs into boolean values
|
|
|
|
* @s: input string
|
|
|
|
* @res: result
|
|
|
|
*
|
2016-03-18 00:22:57 +03:00
|
|
|
* This routine returns 0 iff the first character is one of 'Yy1Nn0', or
|
|
|
|
* [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL. Value
|
|
|
|
* pointed to by res is updated upon finding a match.
|
2016-03-18 00:22:50 +03:00
|
|
|
*/
|
|
|
|
int kstrtobool(const char *s, bool *res)
|
|
|
|
{
|
|
|
|
if (!s)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
switch (s[0]) {
|
|
|
|
case 'y':
|
|
|
|
case 'Y':
|
|
|
|
case '1':
|
|
|
|
*res = true;
|
|
|
|
return 0;
|
|
|
|
case 'n':
|
|
|
|
case 'N':
|
|
|
|
case '0':
|
|
|
|
*res = false;
|
|
|
|
return 0;
|
2016-03-18 00:22:57 +03:00
|
|
|
case 'o':
|
|
|
|
case 'O':
|
|
|
|
switch (s[1]) {
|
|
|
|
case 'n':
|
|
|
|
case 'N':
|
|
|
|
*res = true;
|
|
|
|
return 0;
|
|
|
|
case 'f':
|
|
|
|
case 'F':
|
|
|
|
*res = false;
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-03-18 00:22:50 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(kstrtobool);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since "base" would be a nonsense argument, this open-codes the
|
|
|
|
* _from_user helper instead of using the helper macro below.
|
|
|
|
*/
|
|
|
|
int kstrtobool_from_user(const char __user *s, size_t count, bool *res)
|
|
|
|
{
|
|
|
|
/* Longest string needed to differentiate, newline, terminator */
|
|
|
|
char buf[4];
|
|
|
|
|
|
|
|
count = min(count, sizeof(buf) - 1);
|
|
|
|
if (copy_from_user(buf, s, count))
|
|
|
|
return -EFAULT;
|
|
|
|
buf[count] = '\0';
|
|
|
|
return kstrtobool(buf, res);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(kstrtobool_from_user);
|
|
|
|
|
2011-05-25 04:13:31 +04:00
|
|
|
#define kstrto_from_user(f, g, type) \
|
|
|
|
int f(const char __user *s, size_t count, unsigned int base, type *res) \
|
|
|
|
{ \
|
|
|
|
/* sign, base 2 representation, newline, terminator */ \
|
|
|
|
char buf[1 + sizeof(type) * 8 + 1 + 1]; \
|
|
|
|
\
|
|
|
|
count = min(count, sizeof(buf) - 1); \
|
|
|
|
if (copy_from_user(buf, s, count)) \
|
|
|
|
return -EFAULT; \
|
|
|
|
buf[count] = '\0'; \
|
|
|
|
return g(buf, base, res); \
|
|
|
|
} \
|
|
|
|
EXPORT_SYMBOL(f)
|
|
|
|
|
|
|
|
kstrto_from_user(kstrtoull_from_user, kstrtoull, unsigned long long);
|
|
|
|
kstrto_from_user(kstrtoll_from_user, kstrtoll, long long);
|
|
|
|
kstrto_from_user(kstrtoul_from_user, kstrtoul, unsigned long);
|
|
|
|
kstrto_from_user(kstrtol_from_user, kstrtol, long);
|
|
|
|
kstrto_from_user(kstrtouint_from_user, kstrtouint, unsigned int);
|
|
|
|
kstrto_from_user(kstrtoint_from_user, kstrtoint, int);
|
|
|
|
kstrto_from_user(kstrtou16_from_user, kstrtou16, u16);
|
|
|
|
kstrto_from_user(kstrtos16_from_user, kstrtos16, s16);
|
|
|
|
kstrto_from_user(kstrtou8_from_user, kstrtou8, u8);
|
|
|
|
kstrto_from_user(kstrtos8_from_user, kstrtos8, s8);
|