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
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* This module exports the functions:
|
|
|
|
*
|
2019-04-17 15:21:13 +03:00
|
|
|
* 'int set_selection_user(struct tiocl_selection __user *,
|
|
|
|
* struct tty_struct *)'
|
|
|
|
* 'int set_selection_kernel(struct tiocl_selection *, struct tty_struct *)'
|
2005-04-17 02:20:36 +04:00
|
|
|
* 'void clear_selection(void)'
|
|
|
|
* 'int paste_selection(struct tty_struct *)'
|
|
|
|
* 'int sel_loadlut(char __user *)'
|
|
|
|
*
|
|
|
|
* Now that /dev/vcs exists, most of this can disappear again.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
2016-12-24 22:46:01 +03:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-07-16 10:40:40 +04:00
|
|
|
#include <linux/kbd_kern.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/vt_kern.h>
|
|
|
|
#include <linux/consolemap.h>
|
|
|
|
#include <linux/selection.h>
|
|
|
|
#include <linux/tiocl.h>
|
|
|
|
#include <linux/console.h>
|
2013-06-15 17:36:15 +04:00
|
|
|
#include <linux/tty_flip.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Don't take this from <ctype.h>: 011-015 on the screen aren't spaces */
|
|
|
|
#define isspace(c) ((c) == ' ')
|
|
|
|
|
|
|
|
extern void poke_blanked_console(void);
|
|
|
|
|
2012-02-28 18:49:23 +04:00
|
|
|
/* FIXME: all this needs locking */
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Variables for selection control. */
|
|
|
|
/* Use a dynamic buffer, instead of static (Dec 1994) */
|
2006-09-29 13:00:03 +04:00
|
|
|
struct vc_data *sel_cons; /* must not be deallocated */
|
2007-07-16 10:40:40 +04:00
|
|
|
static int use_unicode;
|
2005-04-17 02:20:36 +04:00
|
|
|
static volatile int sel_start = -1; /* cleared by clear_selection */
|
|
|
|
static int sel_end;
|
|
|
|
static int sel_buffer_lth;
|
|
|
|
static char *sel_buffer;
|
|
|
|
|
|
|
|
/* clear_selection, highlight and highlight_pointer can be called
|
|
|
|
from interrupt (via scrollback/front) */
|
|
|
|
|
|
|
|
/* set reverse video on characters s-e of console with selection. */
|
|
|
|
static inline void highlight(const int s, const int e)
|
|
|
|
{
|
|
|
|
invert_screen(sel_cons, s, e-s+2, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* use complementary color to show the pointer */
|
|
|
|
static inline void highlight_pointer(const int where)
|
|
|
|
{
|
|
|
|
complement_pos(sel_cons, where);
|
|
|
|
}
|
|
|
|
|
2018-07-18 05:10:44 +03:00
|
|
|
static u32
|
2005-04-17 02:20:36 +04:00
|
|
|
sel_pos(int n)
|
|
|
|
{
|
2018-07-18 05:10:44 +03:00
|
|
|
if (use_unicode)
|
|
|
|
return screen_glyph_unicode(sel_cons, n / 2);
|
2007-07-16 10:40:40 +04:00
|
|
|
return inverse_translate(sel_cons, screen_glyph(sel_cons, n),
|
2018-07-18 05:10:44 +03:00
|
|
|
0);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2012-03-02 19:00:02 +04:00
|
|
|
/**
|
|
|
|
* clear_selection - remove current selection
|
|
|
|
*
|
|
|
|
* Remove the current selection highlight, if any from the console
|
|
|
|
* holding the selection. The caller must hold the console lock.
|
|
|
|
*/
|
|
|
|
void clear_selection(void)
|
|
|
|
{
|
2005-04-17 02:20:36 +04:00
|
|
|
highlight_pointer(-1); /* hide the pointer */
|
|
|
|
if (sel_start != -1) {
|
|
|
|
highlight(sel_start, sel_end);
|
|
|
|
sel_start = -1;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 15:21:13 +03:00
|
|
|
EXPORT_SYMBOL_GPL(clear_selection);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* User settable table: what characters are to be considered alphabetic?
|
2017-03-27 15:21:14 +03:00
|
|
|
* 128 bits. Locked by the console lock.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2017-03-27 15:21:14 +03:00
|
|
|
static u32 inwordLut[]={
|
2005-04-17 02:20:36 +04:00
|
|
|
0x00000000, /* control chars */
|
2017-03-27 15:21:13 +03:00
|
|
|
0x03FFE000, /* digits and "-./" */
|
2005-04-17 02:20:36 +04:00
|
|
|
0x87FFFFFE, /* uppercase and '_' */
|
|
|
|
0x07FFFFFE, /* lowercase */
|
|
|
|
};
|
|
|
|
|
2018-07-18 05:10:44 +03:00
|
|
|
static inline int inword(const u32 c)
|
|
|
|
{
|
2017-03-27 15:21:14 +03:00
|
|
|
return c > 0x7f || (( inwordLut[c>>5] >> (c & 0x1F) ) & 1);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2012-03-02 19:00:02 +04:00
|
|
|
/**
|
|
|
|
* set loadlut - load the LUT table
|
|
|
|
* @p: user table
|
|
|
|
*
|
|
|
|
* Load the LUT table from user space. The caller must hold the console
|
|
|
|
* lock. Make a temporary copy so a partial update doesn't make a mess.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
int sel_loadlut(char __user *p)
|
|
|
|
{
|
2017-03-27 15:21:14 +03:00
|
|
|
u32 tmplut[ARRAY_SIZE(inwordLut)];
|
|
|
|
if (copy_from_user(tmplut, (u32 __user *)(p+4), sizeof(inwordLut)))
|
2012-03-02 19:00:02 +04:00
|
|
|
return -EFAULT;
|
2017-03-27 15:21:14 +03:00
|
|
|
memcpy(inwordLut, tmplut, sizeof(inwordLut));
|
2012-03-02 19:00:02 +04:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* does screen address p correspond to character at LH/RH edge of screen? */
|
|
|
|
static inline int atedge(const int p, int size_row)
|
|
|
|
{
|
|
|
|
return (!(p % size_row) || !((p + 2) % size_row));
|
|
|
|
}
|
|
|
|
|
2018-07-18 05:10:43 +03:00
|
|
|
/* stores the char in UTF8 and returns the number of bytes used (1-4) */
|
|
|
|
static int store_utf8(u32 c, char *p)
|
2007-07-16 10:40:40 +04:00
|
|
|
{
|
|
|
|
if (c < 0x80) {
|
|
|
|
/* 0******* */
|
|
|
|
p[0] = c;
|
|
|
|
return 1;
|
|
|
|
} else if (c < 0x800) {
|
|
|
|
/* 110***** 10****** */
|
|
|
|
p[0] = 0xc0 | (c >> 6);
|
|
|
|
p[1] = 0x80 | (c & 0x3f);
|
|
|
|
return 2;
|
2018-07-18 05:10:43 +03:00
|
|
|
} else if (c < 0x10000) {
|
2007-07-16 10:40:40 +04:00
|
|
|
/* 1110**** 10****** 10****** */
|
|
|
|
p[0] = 0xe0 | (c >> 12);
|
|
|
|
p[1] = 0x80 | ((c >> 6) & 0x3f);
|
|
|
|
p[2] = 0x80 | (c & 0x3f);
|
|
|
|
return 3;
|
2018-07-18 05:10:43 +03:00
|
|
|
} else if (c < 0x110000) {
|
|
|
|
/* 11110*** 10****** 10****** 10****** */
|
|
|
|
p[0] = 0xf0 | (c >> 18);
|
|
|
|
p[1] = 0x80 | ((c >> 12) & 0x3f);
|
|
|
|
p[2] = 0x80 | ((c >> 6) & 0x3f);
|
|
|
|
p[3] = 0x80 | (c & 0x3f);
|
|
|
|
return 4;
|
|
|
|
} else {
|
|
|
|
/* outside Unicode, replace with U+FFFD */
|
|
|
|
p[0] = 0xef;
|
|
|
|
p[1] = 0xbf;
|
|
|
|
p[2] = 0xbd;
|
|
|
|
return 3;
|
|
|
|
}
|
2007-07-16 10:40:40 +04:00
|
|
|
}
|
|
|
|
|
2012-03-02 19:00:02 +04:00
|
|
|
/**
|
2019-04-17 15:21:13 +03:00
|
|
|
* set_selection_user - set the current selection.
|
2012-03-02 19:00:02 +04:00
|
|
|
* @sel: user selection info
|
|
|
|
* @tty: the console tty
|
|
|
|
*
|
|
|
|
* Invoked by the ioctl handle for the vt layer.
|
|
|
|
*
|
|
|
|
* The entire selection process is managed under the console_lock. It's
|
|
|
|
* a lot under the lock but its hardly a performance path
|
|
|
|
*/
|
2019-04-17 15:21:13 +03:00
|
|
|
int set_selection_user(const struct tiocl_selection __user *sel,
|
|
|
|
struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct tiocl_selection v;
|
|
|
|
|
|
|
|
if (copy_from_user(&v, sel, sizeof(*sel)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return set_selection_kernel(&v, tty);
|
|
|
|
}
|
|
|
|
|
|
|
|
int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct vc_data *vc = vc_cons[fg_console].d;
|
2017-09-29 19:40:54 +03:00
|
|
|
int new_sel_start, new_sel_end, spc;
|
2005-04-17 02:20:36 +04:00
|
|
|
char *bp, *obp;
|
2007-07-16 10:40:40 +04:00
|
|
|
int i, ps, pe, multiplier;
|
2018-07-18 05:10:44 +03:00
|
|
|
u32 c;
|
2012-02-28 18:49:23 +04:00
|
|
|
int mode;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
poke_blanked_console();
|
|
|
|
|
2019-04-17 15:21:13 +03:00
|
|
|
v->xs = min_t(u16, v->xs - 1, vc->vc_cols - 1);
|
|
|
|
v->ys = min_t(u16, v->ys - 1, vc->vc_rows - 1);
|
|
|
|
v->xe = min_t(u16, v->xe - 1, vc->vc_cols - 1);
|
|
|
|
v->ye = min_t(u16, v->ye - 1, vc->vc_rows - 1);
|
|
|
|
ps = v->ys * vc->vc_size_row + (v->xs << 1);
|
|
|
|
pe = v->ye * vc->vc_size_row + (v->xe << 1);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-04-17 15:21:13 +03:00
|
|
|
if (v->sel_mode == TIOCL_SELCLEAR) {
|
2017-09-29 19:40:54 +03:00
|
|
|
/* useful for screendump without selection highlights */
|
|
|
|
clear_selection();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:21:13 +03:00
|
|
|
if (mouse_reporting() && (v->sel_mode & TIOCL_SELMOUSEREPORT)) {
|
|
|
|
mouse_report(tty, v->sel_mode & TIOCL_SELBUTTONMASK, v->xs,
|
|
|
|
v->ys);
|
2017-09-29 19:40:54 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (ps > pe) /* make sel_start <= sel_end */
|
2017-11-11 01:05:45 +03:00
|
|
|
swap(ps, pe);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (sel_cons != vc_cons[fg_console].d) {
|
|
|
|
clear_selection();
|
|
|
|
sel_cons = vc_cons[fg_console].d;
|
|
|
|
}
|
2012-02-28 18:49:23 +04:00
|
|
|
mode = vt_do_kdgkbmode(fg_console);
|
|
|
|
if (mode == K_UNICODE)
|
|
|
|
use_unicode = 1;
|
|
|
|
else
|
|
|
|
use_unicode = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-04-17 15:21:13 +03:00
|
|
|
switch (v->sel_mode)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
case TIOCL_SELCHAR: /* character-by-character selection */
|
|
|
|
new_sel_start = ps;
|
|
|
|
new_sel_end = pe;
|
|
|
|
break;
|
|
|
|
case TIOCL_SELWORD: /* word-by-word selection */
|
|
|
|
spc = isspace(sel_pos(ps));
|
|
|
|
for (new_sel_start = ps; ; ps -= 2)
|
|
|
|
{
|
|
|
|
if ((spc && !isspace(sel_pos(ps))) ||
|
|
|
|
(!spc && !inword(sel_pos(ps))))
|
|
|
|
break;
|
|
|
|
new_sel_start = ps;
|
|
|
|
if (!(ps % vc->vc_size_row))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spc = isspace(sel_pos(pe));
|
|
|
|
for (new_sel_end = pe; ; pe += 2)
|
|
|
|
{
|
|
|
|
if ((spc && !isspace(sel_pos(pe))) ||
|
|
|
|
(!spc && !inword(sel_pos(pe))))
|
|
|
|
break;
|
|
|
|
new_sel_end = pe;
|
|
|
|
if (!((pe + 2) % vc->vc_size_row))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TIOCL_SELLINE: /* line-by-line selection */
|
|
|
|
new_sel_start = ps - ps % vc->vc_size_row;
|
|
|
|
new_sel_end = pe + vc->vc_size_row
|
|
|
|
- pe % vc->vc_size_row - 2;
|
|
|
|
break;
|
|
|
|
case TIOCL_SELPOINTER:
|
|
|
|
highlight_pointer(pe);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove the pointer */
|
|
|
|
highlight_pointer(-1);
|
|
|
|
|
|
|
|
/* select to end of line if on trailing space */
|
|
|
|
if (new_sel_end > new_sel_start &&
|
|
|
|
!atedge(new_sel_end, vc->vc_size_row) &&
|
|
|
|
isspace(sel_pos(new_sel_end))) {
|
|
|
|
for (pe = new_sel_end + 2; ; pe += 2)
|
|
|
|
if (!isspace(sel_pos(pe)) ||
|
|
|
|
atedge(pe, vc->vc_size_row))
|
|
|
|
break;
|
|
|
|
if (isspace(sel_pos(pe)))
|
|
|
|
new_sel_end = pe;
|
|
|
|
}
|
|
|
|
if (sel_start == -1) /* no current selection */
|
|
|
|
highlight(new_sel_start, new_sel_end);
|
|
|
|
else if (new_sel_start == sel_start)
|
|
|
|
{
|
|
|
|
if (new_sel_end == sel_end) /* no action required */
|
|
|
|
return 0;
|
|
|
|
else if (new_sel_end > sel_end) /* extend to right */
|
|
|
|
highlight(sel_end + 2, new_sel_end);
|
|
|
|
else /* contract from right */
|
|
|
|
highlight(new_sel_end + 2, sel_end);
|
|
|
|
}
|
|
|
|
else if (new_sel_end == sel_end)
|
|
|
|
{
|
|
|
|
if (new_sel_start < sel_start) /* extend to left */
|
|
|
|
highlight(new_sel_start, sel_start - 2);
|
|
|
|
else /* contract from left */
|
|
|
|
highlight(sel_start, new_sel_start - 2);
|
|
|
|
}
|
|
|
|
else /* some other case; start selection from scratch */
|
|
|
|
{
|
|
|
|
clear_selection();
|
|
|
|
highlight(new_sel_start, new_sel_end);
|
|
|
|
}
|
|
|
|
sel_start = new_sel_start;
|
|
|
|
sel_end = new_sel_end;
|
|
|
|
|
|
|
|
/* Allocate a new buffer before freeing the old one ... */
|
2018-07-18 05:10:43 +03:00
|
|
|
multiplier = use_unicode ? 4 : 1; /* chars can take up to 4 bytes */
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 23:55:00 +03:00
|
|
|
bp = kmalloc_array((sel_end - sel_start) / 2 + 1, multiplier,
|
|
|
|
GFP_KERNEL);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!bp) {
|
|
|
|
printk(KERN_WARNING "selection: kmalloc() failed\n");
|
|
|
|
clear_selection();
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2005-11-07 12:01:29 +03:00
|
|
|
kfree(sel_buffer);
|
2005-04-17 02:20:36 +04:00
|
|
|
sel_buffer = bp;
|
|
|
|
|
|
|
|
obp = bp;
|
|
|
|
for (i = sel_start; i <= sel_end; i += 2) {
|
2007-07-16 10:40:40 +04:00
|
|
|
c = sel_pos(i);
|
|
|
|
if (use_unicode)
|
|
|
|
bp += store_utf8(c, bp);
|
|
|
|
else
|
|
|
|
*bp++ = c;
|
|
|
|
if (!isspace(c))
|
2005-04-17 02:20:36 +04:00
|
|
|
obp = bp;
|
|
|
|
if (! ((i + 2) % vc->vc_size_row)) {
|
|
|
|
/* strip trailing blanks from line and add newline,
|
|
|
|
unless non-space at end of line. */
|
|
|
|
if (obp != bp) {
|
|
|
|
bp = obp;
|
|
|
|
*bp++ = '\r';
|
|
|
|
}
|
|
|
|
obp = bp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sel_buffer_lth = bp - sel_buffer;
|
|
|
|
return 0;
|
|
|
|
}
|
2019-04-17 15:21:13 +03:00
|
|
|
EXPORT_SYMBOL_GPL(set_selection_kernel);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Insert the contents of the selection buffer into the
|
|
|
|
* queue of the tty associated with the current console.
|
|
|
|
* Invoked by ioctl().
|
2011-07-14 16:35:14 +04:00
|
|
|
*
|
2012-03-02 18:59:37 +04:00
|
|
|
* Locking: called without locks. Calls the ldisc wrongly with
|
|
|
|
* unsafe methods,
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
int paste_selection(struct tty_struct *tty)
|
|
|
|
{
|
2009-01-02 16:47:26 +03:00
|
|
|
struct vc_data *vc = tty->driver_data;
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 07:54:13 +03:00
|
|
|
int pasted = 0;
|
|
|
|
unsigned int count;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct tty_ldisc *ld;
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
2011-01-26 02:07:35 +03:00
|
|
|
console_lock();
|
2005-04-17 02:20:36 +04:00
|
|
|
poke_blanked_console();
|
2011-01-26 02:07:35 +03:00
|
|
|
console_unlock();
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-10-19 00:26:32 +04:00
|
|
|
ld = tty_ldisc_ref_wait(tty);
|
2016-01-11 09:41:01 +03:00
|
|
|
if (!ld)
|
|
|
|
return -EIO; /* ldisc was hung up */
|
2013-06-15 17:36:15 +04:00
|
|
|
tty_buffer_lock_exclusive(&vc->port);
|
2010-06-02 00:53:06 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
add_wait_queue(&vc->paste_wait, &wait);
|
|
|
|
while (sel_buffer && sel_buffer_lth > pasted) {
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2016-04-10 03:11:36 +03:00
|
|
|
if (tty_throttled(tty)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
schedule();
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-13 03:47:35 +03:00
|
|
|
__set_current_state(TASK_RUNNING);
|
2005-04-17 02:20:36 +04:00
|
|
|
count = sel_buffer_lth - pasted;
|
2013-06-15 17:14:15 +04:00
|
|
|
count = tty_ldisc_receive_buf(ld, sel_buffer + pasted, NULL,
|
|
|
|
count);
|
2005-04-17 02:20:36 +04:00
|
|
|
pasted += count;
|
|
|
|
}
|
|
|
|
remove_wait_queue(&vc->paste_wait, &wait);
|
2007-05-08 11:30:52 +04:00
|
|
|
__set_current_state(TASK_RUNNING);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-06-15 17:36:15 +04:00
|
|
|
tty_buffer_unlock_exclusive(&vc->port);
|
2005-04-17 02:20:36 +04:00
|
|
|
tty_ldisc_deref(ld);
|
|
|
|
return 0;
|
|
|
|
}
|
2019-04-17 15:21:13 +03:00
|
|
|
EXPORT_SYMBOL_GPL(paste_selection);
|