linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/9] vt: selection, introduce vc_is_sel
@ 2020-02-19  7:39 Jiri Slaby
  2020-02-19  7:39 ` [PATCH 2/9] vt: ioctl, switch VT_IS_IN_USE and VT_BUSY to inlines Jiri Slaby
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Jiri Slaby @ 2020-02-19  7:39 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

Avoid global variables (namely sel_cons) by introducing vc_is_sel. It
checks whether the parameter is the current selection console. This will
help putting sel_cons to a struct later.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/vt/selection.c | 5 +++++
 drivers/tty/vt/vt.c        | 7 ++++---
 drivers/tty/vt/vt_ioctl.c  | 2 +-
 include/linux/selection.h  | 4 +++-
 4 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
index 0c50d7410b31..714992693974 100644
--- a/drivers/tty/vt/selection.c
+++ b/drivers/tty/vt/selection.c
@@ -88,6 +88,11 @@ void clear_selection(void)
 }
 EXPORT_SYMBOL_GPL(clear_selection);
 
+bool vc_is_sel(struct vc_data *vc)
+{
+	return vc == sel_cons;
+}
+
 /*
  * User settable table: what characters are to be considered alphabetic?
  * 128 bits. Locked by the console lock.
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 0cfbb7182b5a..8fa059ec6cc8 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -890,8 +890,9 @@ static void hide_softcursor(struct vc_data *vc)
 
 static void hide_cursor(struct vc_data *vc)
 {
-	if (vc == sel_cons)
+	if (vc_is_sel(vc))
 		clear_selection();
+
 	vc->vc_sw->con_cursor(vc, CM_ERASE);
 	hide_softcursor(vc);
 }
@@ -901,7 +902,7 @@ static void set_cursor(struct vc_data *vc)
 	if (!con_is_fg(vc) || console_blanked || vc->vc_mode == KD_GRAPHICS)
 		return;
 	if (vc->vc_deccm) {
-		if (vc == sel_cons)
+		if (vc_is_sel(vc))
 			clear_selection();
 		add_softcursor(vc);
 		if ((vc->vc_cursor_type & 0x0f) != 1)
@@ -1207,7 +1208,7 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
 		}
 	}
 
-	if (vc == sel_cons)
+	if (vc_is_sel(vc))
 		clear_selection();
 
 	old_rows = vc->vc_rows;
diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index ee6c91ef1f6c..bf4daa0c7930 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -43,7 +43,7 @@ char vt_dont_switch;
 extern struct tty_driver *console_driver;
 
 #define VT_IS_IN_USE(i)	(console_driver->ttys[i] && console_driver->ttys[i]->count)
-#define VT_BUSY(i)	(VT_IS_IN_USE(i) || i == fg_console || vc_cons[i].d == sel_cons)
+#define VT_BUSY(i)	(VT_IS_IN_USE(i) || i == fg_console || vc_is_sel(vc_cons[i].d))
 
 /*
  * Console (vt and kd) routines, as defined by USL SVR4 manual, and by
diff --git a/include/linux/selection.h b/include/linux/selection.h
index e2c1f96bf059..5b890ef5b59f 100644
--- a/include/linux/selection.h
+++ b/include/linux/selection.h
@@ -11,8 +11,8 @@
 #include <linux/tiocl.h>
 #include <linux/vt_buffer.h>
 
-extern struct vc_data *sel_cons;
 struct tty_struct;
+struct vc_data;
 
 extern void clear_selection(void);
 extern int set_selection_user(const struct tiocl_selection __user *sel,
@@ -24,6 +24,8 @@ extern int sel_loadlut(char __user *p);
 extern int mouse_reporting(void);
 extern void mouse_report(struct tty_struct * tty, int butt, int mrx, int mry);
 
+bool vc_is_sel(struct vc_data *vc);
+
 extern int console_blanked;
 
 extern const unsigned char color_table[];
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/9] vt: ioctl, switch VT_IS_IN_USE and VT_BUSY to inlines
  2020-02-19  7:39 [PATCH 1/9] vt: selection, introduce vc_is_sel Jiri Slaby
@ 2020-02-19  7:39 ` Jiri Slaby
  2020-02-19  7:39 ` [PATCH 3/9] vt: selection, remove 2 local variables from set_selection_kernel Jiri Slaby
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Jiri Slaby @ 2020-02-19  7:39 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

These two were macros. Switch them to static inlines, so that it's more
understandable what they are doing.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/vt/vt_ioctl.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index bf4daa0c7930..693d9d7ffb68 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -40,10 +40,25 @@
 #include <linux/selection.h>
 
 char vt_dont_switch;
-extern struct tty_driver *console_driver;
 
-#define VT_IS_IN_USE(i)	(console_driver->ttys[i] && console_driver->ttys[i]->count)
-#define VT_BUSY(i)	(VT_IS_IN_USE(i) || i == fg_console || vc_is_sel(vc_cons[i].d))
+static inline bool vt_in_use(unsigned int i)
+{
+	extern struct tty_driver *console_driver;
+
+	return console_driver->ttys[i] && console_driver->ttys[i]->count;
+}
+
+static inline bool vt_busy(int i)
+{
+	if (vt_in_use(i))
+		return true;
+	if (i == fg_console)
+		return true;
+	if (vc_is_sel(vc_cons[i].d))
+		return true;
+
+	return false;
+}
 
 /*
  * Console (vt and kd) routines, as defined by USL SVR4 manual, and by
@@ -289,7 +304,7 @@ static int vt_disallocate(unsigned int vc_num)
 	int ret = 0;
 
 	console_lock();
-	if (VT_BUSY(vc_num))
+	if (vt_busy(vc_num))
 		ret = -EBUSY;
 	else if (vc_num)
 		vc = vc_deallocate(vc_num);
@@ -311,7 +326,7 @@ static void vt_disallocate_all(void)
 
 	console_lock();
 	for (i = 1; i < MAX_NR_CONSOLES; i++)
-		if (!VT_BUSY(i))
+		if (!vt_busy(i))
 			vc[i] = vc_deallocate(i);
 		else
 			vc[i] = NULL;
@@ -648,7 +663,7 @@ int vt_ioctl(struct tty_struct *tty,
 			state = 1;	/* /dev/tty0 is always open */
 			for (i = 0, mask = 2; i < MAX_NR_CONSOLES && mask;
 							++i, mask <<= 1)
-				if (VT_IS_IN_USE(i))
+				if (vt_in_use(i))
 					state |= mask;
 			ret = put_user(state, &vtstat->v_state);
 		}
@@ -661,7 +676,7 @@ int vt_ioctl(struct tty_struct *tty,
 	case VT_OPENQRY:
 		/* FIXME: locking ? - but then this is a stupid API */
 		for (i = 0; i < MAX_NR_CONSOLES; ++i)
-			if (! VT_IS_IN_USE(i))
+			if (!vt_in_use(i))
 				break;
 		uival = i < MAX_NR_CONSOLES ? (i+1) : -1;
 		goto setint;		 
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/9] vt: selection, remove 2 local variables from set_selection_kernel
  2020-02-19  7:39 [PATCH 1/9] vt: selection, introduce vc_is_sel Jiri Slaby
  2020-02-19  7:39 ` [PATCH 2/9] vt: ioctl, switch VT_IS_IN_USE and VT_BUSY to inlines Jiri Slaby
@ 2020-02-19  7:39 ` Jiri Slaby
  2020-02-21  9:32   ` Greg KH
  2020-02-19  7:39 ` [PATCH 4/9] vt: selection, localize use_unicode Jiri Slaby
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Jiri Slaby @ 2020-02-19  7:39 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

multiplier and mode are not actually needed:
* multiplier is used only in kmalloc_array, so use "use_unicode ? 4 : 1"
  directly
* mode is used only to assign a bool in this manner:
  if (cond)
    x = true;
  else
    x = false;
  So do "x = cond" directly.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/vt/selection.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
index 714992693974..6541c09d8bba 100644
--- a/drivers/tty/vt/selection.c
+++ b/drivers/tty/vt/selection.c
@@ -191,9 +191,9 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 	struct vc_data *vc = vc_cons[fg_console].d;
 	int new_sel_start, new_sel_end, spc;
 	char *bp, *obp;
-	int i, ps, pe, multiplier;
+	int i, ps, pe;
 	u32 c;
-	int mode, ret = 0;
+	int ret = 0;
 
 	poke_blanked_console();
 
@@ -224,11 +224,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 		clear_selection();
 		sel_cons = vc_cons[fg_console].d;
 	}
-	mode = vt_do_kdgkbmode(fg_console);
-	if (mode == K_UNICODE)
-		use_unicode = 1;
-	else
-		use_unicode = 0;
+	use_unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
 
 	switch (v->sel_mode)
 	{
@@ -312,8 +308,8 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 	sel_end = new_sel_end;
 
 	/* Allocate a new buffer before freeing the old one ... */
-	multiplier = use_unicode ? 4 : 1;  /* chars can take up to 4 bytes */
-	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, multiplier,
+	/* chars can take up to 4 bytes with unicode */
+	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, use_unicode ? 4 : 1,
 			   GFP_KERNEL);
 	if (!bp) {
 		printk(KERN_WARNING "selection: kmalloc() failed\n");
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/9] vt: selection, localize use_unicode
  2020-02-19  7:39 [PATCH 1/9] vt: selection, introduce vc_is_sel Jiri Slaby
  2020-02-19  7:39 ` [PATCH 2/9] vt: ioctl, switch VT_IS_IN_USE and VT_BUSY to inlines Jiri Slaby
  2020-02-19  7:39 ` [PATCH 3/9] vt: selection, remove 2 local variables from set_selection_kernel Jiri Slaby
@ 2020-02-19  7:39 ` Jiri Slaby
  2020-02-19  7:39 ` [PATCH 5/9] vt: selection, create struct from console selection globals Jiri Slaby
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Jiri Slaby @ 2020-02-19  7:39 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

use_unicode needs not be global. It is used only in set_selection_kernel
and sel_pos (a callee). It is also always set there prior calling
sel_pos. So make use_unicode local and rename it to plain shorter
"unicode". Finally, propagate it to sel_pos via parameter.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/vt/selection.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
index 6541c09d8bba..33f94293f45e 100644
--- a/drivers/tty/vt/selection.c
+++ b/drivers/tty/vt/selection.c
@@ -41,7 +41,6 @@ extern void poke_blanked_console(void);
 /* Variables for selection control. */
 /* Use a dynamic buffer, instead of static (Dec 1994) */
 struct vc_data *sel_cons;		/* must not be deallocated */
-static int use_unicode;
 static volatile int sel_start = -1; 	/* cleared by clear_selection */
 static int sel_end;
 static int sel_buffer_lth;
@@ -64,9 +63,9 @@ static inline void highlight_pointer(const int where)
 }
 
 static u32
-sel_pos(int n)
+sel_pos(int n, bool unicode)
 {
-	if (use_unicode)
+	if (unicode)
 		return screen_glyph_unicode(sel_cons, n / 2);
 	return inverse_translate(sel_cons, screen_glyph(sel_cons, n),
 				0);
@@ -194,6 +193,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 	int i, ps, pe;
 	u32 c;
 	int ret = 0;
+	bool unicode;
 
 	poke_blanked_console();
 
@@ -224,7 +224,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 		clear_selection();
 		sel_cons = vc_cons[fg_console].d;
 	}
-	use_unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
+	unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
 
 	switch (v->sel_mode)
 	{
@@ -233,21 +233,21 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 			new_sel_end = pe;
 			break;
 		case TIOCL_SELWORD:	/* word-by-word selection */
-			spc = isspace(sel_pos(ps));
+			spc = isspace(sel_pos(ps, unicode));
 			for (new_sel_start = ps; ; ps -= 2)
 			{
-				if ((spc && !isspace(sel_pos(ps))) ||
-				    (!spc && !inword(sel_pos(ps))))
+				if ((spc && !isspace(sel_pos(ps, unicode))) ||
+				    (!spc && !inword(sel_pos(ps, unicode))))
 					break;
 				new_sel_start = ps;
 				if (!(ps % vc->vc_size_row))
 					break;
 			}
-			spc = isspace(sel_pos(pe));
+			spc = isspace(sel_pos(pe, unicode));
 			for (new_sel_end = pe; ; pe += 2)
 			{
-				if ((spc && !isspace(sel_pos(pe))) ||
-				    (!spc && !inword(sel_pos(pe))))
+				if ((spc && !isspace(sel_pos(pe, unicode))) ||
+				    (!spc && !inword(sel_pos(pe, unicode))))
 					break;
 				new_sel_end = pe;
 				if (!((pe + 2) % vc->vc_size_row))
@@ -273,12 +273,12 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 	/* 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))) {
+		isspace(sel_pos(new_sel_end, unicode))) {
 		for (pe = new_sel_end + 2; ; pe += 2)
-			if (!isspace(sel_pos(pe)) ||
+			if (!isspace(sel_pos(pe, unicode)) ||
 			    atedge(pe, vc->vc_size_row))
 				break;
-		if (isspace(sel_pos(pe)))
+		if (isspace(sel_pos(pe, unicode)))
 			new_sel_end = pe;
 	}
 	if (sel_start == -1)	/* no current selection */
@@ -309,7 +309,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 
 	/* Allocate a new buffer before freeing the old one ... */
 	/* chars can take up to 4 bytes with unicode */
-	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, use_unicode ? 4 : 1,
+	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, unicode ? 4 : 1,
 			   GFP_KERNEL);
 	if (!bp) {
 		printk(KERN_WARNING "selection: kmalloc() failed\n");
@@ -322,8 +322,8 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 
 	obp = bp;
 	for (i = sel_start; i <= sel_end; i += 2) {
-		c = sel_pos(i);
-		if (use_unicode)
+		c = sel_pos(i, unicode);
+		if (unicode)
 			bp += store_utf8(c, bp);
 		else
 			*bp++ = c;
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/9] vt: selection, create struct from console selection globals
  2020-02-19  7:39 [PATCH 1/9] vt: selection, introduce vc_is_sel Jiri Slaby
                   ` (2 preceding siblings ...)
  2020-02-19  7:39 ` [PATCH 4/9] vt: selection, localize use_unicode Jiri Slaby
@ 2020-02-19  7:39 ` Jiri Slaby
  2020-02-19  7:39 ` [PATCH 6/9] vt: switch vt_dont_switch to bool Jiri Slaby
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Jiri Slaby @ 2020-02-19  7:39 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

Move all the selection global variables to a structure vc_selection,
instantiated as vc_sel. This helps to group all the variables together
and see what should be protected by the embedded lock too.

It might be used later also for per-console selection support.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/vt/selection.c | 94 +++++++++++++++++++-------------------
 1 file changed, 48 insertions(+), 46 deletions(-)

diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
index 33f94293f45e..0cd7072b6a56 100644
--- a/drivers/tty/vt/selection.c
+++ b/drivers/tty/vt/selection.c
@@ -38,14 +38,17 @@
 extern void poke_blanked_console(void);
 
 /* FIXME: all this needs locking */
-/* Variables for selection control. */
-/* Use a dynamic buffer, instead of static (Dec 1994) */
-struct vc_data *sel_cons;		/* must not be deallocated */
-static volatile int sel_start = -1; 	/* cleared by clear_selection */
-static int sel_end;
-static int sel_buffer_lth;
-static char *sel_buffer;
-static DEFINE_MUTEX(sel_lock);
+static struct vc_selection {
+	struct mutex lock;
+	struct vc_data *cons;			/* must not be deallocated */
+	char *buffer;
+	unsigned int buf_len;
+	volatile int start;			/* cleared by clear_selection */
+	int end;
+} vc_sel = {
+	.lock = __MUTEX_INITIALIZER(vc_sel.lock),
+	.start = -1,
+};
 
 /* clear_selection, highlight and highlight_pointer can be called
    from interrupt (via scrollback/front) */
@@ -53,22 +56,21 @@ static DEFINE_MUTEX(sel_lock);
 /* 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);
+	invert_screen(vc_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);
+	complement_pos(vc_sel.cons, where);
 }
 
 static u32
 sel_pos(int n, bool unicode)
 {
 	if (unicode)
-		return screen_glyph_unicode(sel_cons, n / 2);
-	return inverse_translate(sel_cons, screen_glyph(sel_cons, n),
-				0);
+		return screen_glyph_unicode(vc_sel.cons, n / 2);
+	return inverse_translate(vc_sel.cons, screen_glyph(vc_sel.cons, n), 0);
 }
 
 /**
@@ -80,16 +82,16 @@ sel_pos(int n, bool unicode)
 void clear_selection(void)
 {
 	highlight_pointer(-1); /* hide the pointer */
-	if (sel_start != -1) {
-		highlight(sel_start, sel_end);
-		sel_start = -1;
+	if (vc_sel.start != -1) {
+		highlight(vc_sel.start, vc_sel.end);
+		vc_sel.start = -1;
 	}
 }
 EXPORT_SYMBOL_GPL(clear_selection);
 
 bool vc_is_sel(struct vc_data *vc)
 {
-	return vc == sel_cons;
+	return vc == vc_sel.cons;
 }
 
 /*
@@ -216,13 +218,13 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 		return 0;
 	}
 
-	if (ps > pe)	/* make sel_start <= sel_end */
+	if (ps > pe)	/* make vc_sel.start <= vc_sel.end */
 		swap(ps, pe);
 
-	mutex_lock(&sel_lock);
-	if (sel_cons != vc_cons[fg_console].d) {
+	mutex_lock(&vc_sel.lock);
+	if (vc_sel.cons != vc_cons[fg_console].d) {
 		clear_selection();
-		sel_cons = vc_cons[fg_console].d;
+		vc_sel.cons = vc_cons[fg_console].d;
 	}
 	unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
 
@@ -281,35 +283,35 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 		if (isspace(sel_pos(pe, unicode)))
 			new_sel_end = pe;
 	}
-	if (sel_start == -1)	/* no current selection */
+	if (vc_sel.start == -1)	/* no current selection */
 		highlight(new_sel_start, new_sel_end);
-	else if (new_sel_start == sel_start)
+	else if (new_sel_start == vc_sel.start)
 	{
-		if (new_sel_end == sel_end)	/* no action required */
+		if (new_sel_end == vc_sel.end)	/* no action required */
 			goto unlock;
-		else if (new_sel_end > sel_end)	/* extend to right */
-			highlight(sel_end + 2, new_sel_end);
+		else if (new_sel_end > vc_sel.end)	/* extend to right */
+			highlight(vc_sel.end + 2, new_sel_end);
 		else				/* contract from right */
-			highlight(new_sel_end + 2, sel_end);
+			highlight(new_sel_end + 2, vc_sel.end);
 	}
-	else if (new_sel_end == sel_end)
+	else if (new_sel_end == vc_sel.end)
 	{
-		if (new_sel_start < sel_start)	/* extend to left */
-			highlight(new_sel_start, sel_start - 2);
+		if (new_sel_start < vc_sel.start) /* extend to left */
+			highlight(new_sel_start, vc_sel.start - 2);
 		else				/* contract from left */
-			highlight(sel_start, new_sel_start - 2);
+			highlight(vc_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;
+	vc_sel.start = new_sel_start;
+	vc_sel.end = new_sel_end;
 
 	/* Allocate a new buffer before freeing the old one ... */
 	/* chars can take up to 4 bytes with unicode */
-	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, unicode ? 4 : 1,
+	bp = kmalloc_array((vc_sel.end - vc_sel.start) / 2 + 1, unicode ? 4 : 1,
 			   GFP_KERNEL);
 	if (!bp) {
 		printk(KERN_WARNING "selection: kmalloc() failed\n");
@@ -317,11 +319,11 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 		ret = -ENOMEM;
 		goto unlock;
 	}
-	kfree(sel_buffer);
-	sel_buffer = bp;
+	kfree(vc_sel.buffer);
+	vc_sel.buffer = bp;
 
 	obp = bp;
-	for (i = sel_start; i <= sel_end; i += 2) {
+	for (i = vc_sel.start; i <= vc_sel.end; i += 2) {
 		c = sel_pos(i, unicode);
 		if (unicode)
 			bp += store_utf8(c, bp);
@@ -339,9 +341,9 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 			obp = bp;
 		}
 	}
-	sel_buffer_lth = bp - sel_buffer;
+	vc_sel.buf_len = bp - vc_sel.buffer;
 unlock:
-	mutex_unlock(&sel_lock);
+	mutex_unlock(&vc_sel.lock);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(set_selection_kernel);
@@ -372,26 +374,26 @@ int paste_selection(struct tty_struct *tty)
 	tty_buffer_lock_exclusive(&vc->port);
 
 	add_wait_queue(&vc->paste_wait, &wait);
-	mutex_lock(&sel_lock);
-	while (sel_buffer && sel_buffer_lth > pasted) {
+	mutex_lock(&vc_sel.lock);
+	while (vc_sel.buffer && vc_sel.buf_len > pasted) {
 		set_current_state(TASK_INTERRUPTIBLE);
 		if (signal_pending(current)) {
 			ret = -EINTR;
 			break;
 		}
 		if (tty_throttled(tty)) {
-			mutex_unlock(&sel_lock);
+			mutex_unlock(&vc_sel.lock);
 			schedule();
-			mutex_lock(&sel_lock);
+			mutex_lock(&vc_sel.lock);
 			continue;
 		}
 		__set_current_state(TASK_RUNNING);
-		count = sel_buffer_lth - pasted;
-		count = tty_ldisc_receive_buf(ld, sel_buffer + pasted, NULL,
+		count = vc_sel.buf_len - pasted;
+		count = tty_ldisc_receive_buf(ld, vc_sel.buffer + pasted, NULL,
 					      count);
 		pasted += count;
 	}
-	mutex_unlock(&sel_lock);
+	mutex_unlock(&vc_sel.lock);
 	remove_wait_queue(&vc->paste_wait, &wait);
 	__set_current_state(TASK_RUNNING);
 
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/9] vt: switch vt_dont_switch to bool
  2020-02-19  7:39 [PATCH 1/9] vt: selection, introduce vc_is_sel Jiri Slaby
                   ` (3 preceding siblings ...)
  2020-02-19  7:39 ` [PATCH 5/9] vt: selection, create struct from console selection globals Jiri Slaby
@ 2020-02-19  7:39 ` Jiri Slaby
  2020-02-19  7:39 ` [PATCH 7/9] vt: vt_kern.h, remove extern from functions Jiri Slaby
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Jiri Slaby @ 2020-02-19  7:39 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

vt_dont_switch is pure boolean, no need for whole char.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/vt/vt_ioctl.c | 6 +++---
 include/linux/vt_kern.h   | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 693d9d7ffb68..38948ac5fc49 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -39,7 +39,7 @@
 #include <linux/kbd_diacr.h>
 #include <linux/selection.h>
 
-char vt_dont_switch;
+bool vt_dont_switch;
 
 static inline bool vt_in_use(unsigned int i)
 {
@@ -1026,12 +1026,12 @@ int vt_ioctl(struct tty_struct *tty,
 	case VT_LOCKSWITCH:
 		if (!capable(CAP_SYS_TTY_CONFIG))
 			return -EPERM;
-		vt_dont_switch = 1;
+		vt_dont_switch = true;
 		break;
 	case VT_UNLOCKSWITCH:
 		if (!capable(CAP_SYS_TTY_CONFIG))
 			return -EPERM;
-		vt_dont_switch = 0;
+		vt_dont_switch = false;
 		break;
 	case VT_GETHIFONTMASK:
 		ret = put_user(vc->vc_hi_font_mask,
diff --git a/include/linux/vt_kern.h b/include/linux/vt_kern.h
index 8dc77e40bc03..ded5c48598f3 100644
--- a/include/linux/vt_kern.h
+++ b/include/linux/vt_kern.h
@@ -135,7 +135,7 @@ extern int do_unbind_con_driver(const struct consw *csw, int first, int last,
 			     int deflt);
 int vty_init(const struct file_operations *console_fops);
 
-extern char vt_dont_switch;
+extern bool vt_dont_switch;
 extern int default_utf8;
 extern int global_cursor_default;
 
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 7/9] vt: vt_kern.h, remove extern from functions
  2020-02-19  7:39 [PATCH 1/9] vt: selection, introduce vc_is_sel Jiri Slaby
                   ` (4 preceding siblings ...)
  2020-02-19  7:39 ` [PATCH 6/9] vt: switch vt_dont_switch to bool Jiri Slaby
@ 2020-02-19  7:39 ` Jiri Slaby
  2020-02-19  7:39 ` [PATCH 8/9] vt: selection, remove redeclaration of poke_blanked_console Jiri Slaby
  2020-02-19  7:39 ` [PATCH 9/9] vt: selection, indent switch-case properly Jiri Slaby
  7 siblings, 0 replies; 12+ messages in thread
From: Jiri Slaby @ 2020-02-19  7:39 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

Unify the declarations of functions in vt_kern.h: some are with extern,
some are not. Remove extern from the former as it is not needed for
functions.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 include/linux/vt_kern.h | 62 ++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/include/linux/vt_kern.h b/include/linux/vt_kern.h
index ded5c48598f3..abf5bccf906a 100644
--- a/include/linux/vt_kern.h
+++ b/include/linux/vt_kern.h
@@ -28,8 +28,9 @@
 #define BROKEN_GRAPHICS_PROGRAMS 1
 #endif
 
-extern void kd_mksound(unsigned int hz, unsigned int ticks);
-extern int kbd_rate(struct kbd_repeat *rep);
+void kd_mksound(unsigned int hz, unsigned int ticks);
+int kbd_rate(struct kbd_repeat *rep);
+
 extern int fg_console, last_console, want_console;
 
 /* console.c */
@@ -131,8 +132,8 @@ void vt_event_post(unsigned int event, unsigned int old, unsigned int new);
 int vt_waitactive(int n);
 void change_console(struct vc_data *new_vc);
 void reset_vc(struct vc_data *vc);
-extern int do_unbind_con_driver(const struct consw *csw, int first, int last,
-			     int deflt);
+int do_unbind_con_driver(const struct consw *csw, int first, int last,
+			 int deflt);
 int vty_init(const struct file_operations *console_fops);
 
 extern bool vt_dont_switch;
@@ -146,7 +147,7 @@ struct vt_spawn_console {
 };
 extern struct vt_spawn_console vt_spawn_con;
 
-extern int vt_move_to_console(unsigned int vt, int alloc);
+int vt_move_to_console(unsigned int vt, int alloc);
 
 /* Interfaces for VC notification of character events (for accessibility etc) */
 
@@ -155,35 +156,34 @@ struct vt_notifier_param {
 	unsigned int c;		/* Printed char */
 };
 
-extern int register_vt_notifier(struct notifier_block *nb);
-extern int unregister_vt_notifier(struct notifier_block *nb);
+int register_vt_notifier(struct notifier_block *nb);
+int unregister_vt_notifier(struct notifier_block *nb);
 
-extern void hide_boot_cursor(bool hide);
+void hide_boot_cursor(bool hide);
 
 /* keyboard  provided interfaces */
-extern int vt_do_diacrit(unsigned int cmd, void __user *up, int eperm);
-extern int vt_do_kdskbmode(int console, unsigned int arg);
-extern int vt_do_kdskbmeta(int console, unsigned int arg);
-extern int vt_do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc,
-								int perm);
-extern int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe,
-					int perm, int console);
-extern int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb,
-                                        int perm);
-extern int vt_do_kdskled(int console, int cmd, unsigned long arg, int perm);
-extern int vt_do_kdgkbmode(int console);
-extern int vt_do_kdgkbmeta(int console);
-extern void vt_reset_unicode(int console);
-extern int vt_get_shift_state(void);
-extern void vt_reset_keyboard(int console);
-extern int vt_get_leds(int console, int flag);
-extern int vt_get_kbd_mode_bit(int console, int bit);
-extern void vt_set_kbd_mode_bit(int console, int bit);
-extern void vt_clr_kbd_mode_bit(int console, int bit);
-extern void vt_set_led_state(int console, int leds);
-extern void vt_set_led_state(int console, int leds);
-extern void vt_kbd_con_start(int console);
-extern void vt_kbd_con_stop(int console);
+int vt_do_diacrit(unsigned int cmd, void __user *up, int eperm);
+int vt_do_kdskbmode(int console, unsigned int arg);
+int vt_do_kdskbmeta(int console, unsigned int arg);
+int vt_do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc,
+			  int perm);
+int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
+		     int console);
+int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm);
+int vt_do_kdskled(int console, int cmd, unsigned long arg, int perm);
+int vt_do_kdgkbmode(int console);
+int vt_do_kdgkbmeta(int console);
+void vt_reset_unicode(int console);
+int vt_get_shift_state(void);
+void vt_reset_keyboard(int console);
+int vt_get_leds(int console, int flag);
+int vt_get_kbd_mode_bit(int console, int bit);
+void vt_set_kbd_mode_bit(int console, int bit);
+void vt_clr_kbd_mode_bit(int console, int bit);
+void vt_set_led_state(int console, int leds);
+void vt_set_led_state(int console, int leds);
+void vt_kbd_con_start(int console);
+void vt_kbd_con_stop(int console);
 
 void vc_scrolldelta_helper(struct vc_data *c, int lines,
 		unsigned int rolled_over, void *_base, unsigned int size);
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 8/9] vt: selection, remove redeclaration of poke_blanked_console
  2020-02-19  7:39 [PATCH 1/9] vt: selection, introduce vc_is_sel Jiri Slaby
                   ` (5 preceding siblings ...)
  2020-02-19  7:39 ` [PATCH 7/9] vt: vt_kern.h, remove extern from functions Jiri Slaby
@ 2020-02-19  7:39 ` Jiri Slaby
  2020-02-19  7:39 ` [PATCH 9/9] vt: selection, indent switch-case properly Jiri Slaby
  7 siblings, 0 replies; 12+ messages in thread
From: Jiri Slaby @ 2020-02-19  7:39 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

It is declared in vt_kern.h, so no need to declare it in selection.c
which includes the header.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/vt/selection.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
index 0cd7072b6a56..eaf11729ef9e 100644
--- a/drivers/tty/vt/selection.c
+++ b/drivers/tty/vt/selection.c
@@ -35,8 +35,6 @@
 /* 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);
-
 /* FIXME: all this needs locking */
 static struct vc_selection {
 	struct mutex lock;
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 9/9] vt: selection, indent switch-case properly
  2020-02-19  7:39 [PATCH 1/9] vt: selection, introduce vc_is_sel Jiri Slaby
                   ` (6 preceding siblings ...)
  2020-02-19  7:39 ` [PATCH 8/9] vt: selection, remove redeclaration of poke_blanked_console Jiri Slaby
@ 2020-02-19  7:39 ` Jiri Slaby
  7 siblings, 0 replies; 12+ messages in thread
From: Jiri Slaby @ 2020-02-19  7:39 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

Shift the cases one level left as this is how we are supposed to write
the switch-case code according to the CodingStyle.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/vt/selection.c | 72 ++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
index eaf11729ef9e..b9c517463efa 100644
--- a/drivers/tty/vt/selection.c
+++ b/drivers/tty/vt/selection.c
@@ -226,45 +226,43 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 	}
 	unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
 
-	switch (v->sel_mode)
-	{
-		case TIOCL_SELCHAR:	/* character-by-character selection */
+	switch (v->sel_mode) {
+	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, unicode));
+		for (new_sel_start = ps; ; ps -= 2) {
+			if ((spc && !isspace(sel_pos(ps, unicode))) ||
+			    (!spc && !inword(sel_pos(ps, unicode))))
+				break;
 			new_sel_start = ps;
+			if (!(ps % vc->vc_size_row))
+				break;
+		}
+
+		spc = isspace(sel_pos(pe, unicode));
+		for (new_sel_end = pe; ; pe += 2) {
+			if ((spc && !isspace(sel_pos(pe, unicode))) ||
+			    (!spc && !inword(sel_pos(pe, unicode))))
+				break;
 			new_sel_end = pe;
-			break;
-		case TIOCL_SELWORD:	/* word-by-word selection */
-			spc = isspace(sel_pos(ps, unicode));
-			for (new_sel_start = ps; ; ps -= 2)
-			{
-				if ((spc && !isspace(sel_pos(ps, unicode))) ||
-				    (!spc && !inword(sel_pos(ps, unicode))))
-					break;
-				new_sel_start = ps;
-				if (!(ps % vc->vc_size_row))
-					break;
-			}
-			spc = isspace(sel_pos(pe, unicode));
-			for (new_sel_end = pe; ; pe += 2)
-			{
-				if ((spc && !isspace(sel_pos(pe, unicode))) ||
-				    (!spc && !inword(sel_pos(pe, unicode))))
-					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);
-			goto unlock;
-		default:
-			ret = -EINVAL;
-			goto unlock;
+			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);
+		goto unlock;
+	default:
+		ret = -EINVAL;
+		goto unlock;
 	}
 
 	/* remove the pointer */
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/9] vt: selection, remove 2 local variables from set_selection_kernel
  2020-02-19  7:39 ` [PATCH 3/9] vt: selection, remove 2 local variables from set_selection_kernel Jiri Slaby
@ 2020-02-21  9:32   ` Greg KH
  2020-02-24  9:26     ` Jiri Slaby
  0 siblings, 1 reply; 12+ messages in thread
From: Greg KH @ 2020-02-21  9:32 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: linux-serial, linux-kernel

On Wed, Feb 19, 2020 at 08:39:45AM +0100, Jiri Slaby wrote:
> multiplier and mode are not actually needed:
> * multiplier is used only in kmalloc_array, so use "use_unicode ? 4 : 1"
>   directly
> * mode is used only to assign a bool in this manner:
>   if (cond)
>     x = true;
>   else
>     x = false;
>   So do "x = cond" directly.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> ---
>  drivers/tty/vt/selection.c | 14 +++++---------
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
> index 714992693974..6541c09d8bba 100644
> --- a/drivers/tty/vt/selection.c
> +++ b/drivers/tty/vt/selection.c
> @@ -191,9 +191,9 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
>  	struct vc_data *vc = vc_cons[fg_console].d;
>  	int new_sel_start, new_sel_end, spc;
>  	char *bp, *obp;
> -	int i, ps, pe, multiplier;
> +	int i, ps, pe;
>  	u32 c;
> -	int mode, ret = 0;
> +	int ret = 0;
>  
>  	poke_blanked_console();
>  
> @@ -224,11 +224,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
>  		clear_selection();
>  		sel_cons = vc_cons[fg_console].d;
>  	}
> -	mode = vt_do_kdgkbmode(fg_console);
> -	if (mode == K_UNICODE)
> -		use_unicode = 1;
> -	else
> -		use_unicode = 0;
> +	use_unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
>  
>  	switch (v->sel_mode)
>  	{
> @@ -312,8 +308,8 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
>  	sel_end = new_sel_end;
>  
>  	/* Allocate a new buffer before freeing the old one ... */
> -	multiplier = use_unicode ? 4 : 1;  /* chars can take up to 4 bytes */
> -	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, multiplier,
> +	/* chars can take up to 4 bytes with unicode */
> +	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, use_unicode ? 4 : 1,
>  			   GFP_KERNEL);
>  	if (!bp) {
>  		printk(KERN_WARNING "selection: kmalloc() failed\n");
> -- 
> 2.25.0
> 

This patch fails to apply to my tree, so I stopped here.  Can you rebase
and resend the rest of these?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/9] vt: selection, remove 2 local variables from set_selection_kernel
  2020-02-21  9:32   ` Greg KH
@ 2020-02-24  9:26     ` Jiri Slaby
  2020-03-06  7:37       ` Greg KH
  0 siblings, 1 reply; 12+ messages in thread
From: Jiri Slaby @ 2020-02-24  9:26 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-serial, linux-kernel

On 21. 02. 20, 10:32, Greg KH wrote:
> On Wed, Feb 19, 2020 at 08:39:45AM +0100, Jiri Slaby wrote:
>> multiplier and mode are not actually needed:
>> * multiplier is used only in kmalloc_array, so use "use_unicode ? 4 : 1"
>>   directly
>> * mode is used only to assign a bool in this manner:
>>   if (cond)
>>     x = true;
>>   else
>>     x = false;
>>   So do "x = cond" directly.
>>
>> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
>> ---
>>  drivers/tty/vt/selection.c | 14 +++++---------
>>  1 file changed, 5 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
>> index 714992693974..6541c09d8bba 100644
>> --- a/drivers/tty/vt/selection.c
>> +++ b/drivers/tty/vt/selection.c
>> @@ -191,9 +191,9 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
>>  	struct vc_data *vc = vc_cons[fg_console].d;
>>  	int new_sel_start, new_sel_end, spc;
>>  	char *bp, *obp;
>> -	int i, ps, pe, multiplier;
>> +	int i, ps, pe;
>>  	u32 c;
>> -	int mode, ret = 0;
>> +	int ret = 0;
>>  
>>  	poke_blanked_console();
>>  
>> @@ -224,11 +224,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
>>  		clear_selection();
>>  		sel_cons = vc_cons[fg_console].d;
>>  	}
>> -	mode = vt_do_kdgkbmode(fg_console);
>> -	if (mode == K_UNICODE)
>> -		use_unicode = 1;
>> -	else
>> -		use_unicode = 0;
>> +	use_unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
>>  
>>  	switch (v->sel_mode)
>>  	{
>> @@ -312,8 +308,8 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
>>  	sel_end = new_sel_end;
>>  
>>  	/* Allocate a new buffer before freeing the old one ... */
>> -	multiplier = use_unicode ? 4 : 1;  /* chars can take up to 4 bytes */
>> -	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, multiplier,
>> +	/* chars can take up to 4 bytes with unicode */
>> +	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, use_unicode ? 4 : 1,
>>  			   GFP_KERNEL);
>>  	if (!bp) {
>>  		printk(KERN_WARNING "selection: kmalloc() failed\n");
>> -- 
>> 2.25.0
>>
> 
> This patch fails to apply to my tree, so I stopped here.  Can you rebase
> and resend the rest of these?

Could you be a little bit more specific? After the rebase, it still
applies cleanly for me. Perhaps the tree you are applying this to was
missing this 5.6-rc3 commit:
commit 07e6124a1a46b4b5a9b3cacc0c306b50da87abf5
Author: Jiri Slaby <jslaby@suse.cz>
Date:   Mon Feb 10 09:11:31 2020 +0100

    vt: selection, close sel_buffer race
?


thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/9] vt: selection, remove 2 local variables from set_selection_kernel
  2020-02-24  9:26     ` Jiri Slaby
@ 2020-03-06  7:37       ` Greg KH
  0 siblings, 0 replies; 12+ messages in thread
From: Greg KH @ 2020-03-06  7:37 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: linux-serial, linux-kernel

On Mon, Feb 24, 2020 at 10:26:50AM +0100, Jiri Slaby wrote:
> On 21. 02. 20, 10:32, Greg KH wrote:
> > On Wed, Feb 19, 2020 at 08:39:45AM +0100, Jiri Slaby wrote:
> >> multiplier and mode are not actually needed:
> >> * multiplier is used only in kmalloc_array, so use "use_unicode ? 4 : 1"
> >>   directly
> >> * mode is used only to assign a bool in this manner:
> >>   if (cond)
> >>     x = true;
> >>   else
> >>     x = false;
> >>   So do "x = cond" directly.
> >>
> >> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> >> ---
> >>  drivers/tty/vt/selection.c | 14 +++++---------
> >>  1 file changed, 5 insertions(+), 9 deletions(-)
> >>
> >> diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
> >> index 714992693974..6541c09d8bba 100644
> >> --- a/drivers/tty/vt/selection.c
> >> +++ b/drivers/tty/vt/selection.c
> >> @@ -191,9 +191,9 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
> >>  	struct vc_data *vc = vc_cons[fg_console].d;
> >>  	int new_sel_start, new_sel_end, spc;
> >>  	char *bp, *obp;
> >> -	int i, ps, pe, multiplier;
> >> +	int i, ps, pe;
> >>  	u32 c;
> >> -	int mode, ret = 0;
> >> +	int ret = 0;
> >>  
> >>  	poke_blanked_console();
> >>  
> >> @@ -224,11 +224,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
> >>  		clear_selection();
> >>  		sel_cons = vc_cons[fg_console].d;
> >>  	}
> >> -	mode = vt_do_kdgkbmode(fg_console);
> >> -	if (mode == K_UNICODE)
> >> -		use_unicode = 1;
> >> -	else
> >> -		use_unicode = 0;
> >> +	use_unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
> >>  
> >>  	switch (v->sel_mode)
> >>  	{
> >> @@ -312,8 +308,8 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
> >>  	sel_end = new_sel_end;
> >>  
> >>  	/* Allocate a new buffer before freeing the old one ... */
> >> -	multiplier = use_unicode ? 4 : 1;  /* chars can take up to 4 bytes */
> >> -	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, multiplier,
> >> +	/* chars can take up to 4 bytes with unicode */
> >> +	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, use_unicode ? 4 : 1,
> >>  			   GFP_KERNEL);
> >>  	if (!bp) {
> >>  		printk(KERN_WARNING "selection: kmalloc() failed\n");
> >> -- 
> >> 2.25.0
> >>
> > 
> > This patch fails to apply to my tree, so I stopped here.  Can you rebase
> > and resend the rest of these?
> 
> Could you be a little bit more specific? After the rebase, it still
> applies cleanly for me. Perhaps the tree you are applying this to was
> missing this 5.6-rc3 commit:
> commit 07e6124a1a46b4b5a9b3cacc0c306b50da87abf5
> Author: Jiri Slaby <jslaby@suse.cz>
> Date:   Mon Feb 10 09:11:31 2020 +0100
> 
>     vt: selection, close sel_buffer race
> ?

Yes, I did not have your other patches in the branch I was using, as
those were to go to Linus for this current release.

I've fixed this up now and applied the rest, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-03-06  7:38 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-19  7:39 [PATCH 1/9] vt: selection, introduce vc_is_sel Jiri Slaby
2020-02-19  7:39 ` [PATCH 2/9] vt: ioctl, switch VT_IS_IN_USE and VT_BUSY to inlines Jiri Slaby
2020-02-19  7:39 ` [PATCH 3/9] vt: selection, remove 2 local variables from set_selection_kernel Jiri Slaby
2020-02-21  9:32   ` Greg KH
2020-02-24  9:26     ` Jiri Slaby
2020-03-06  7:37       ` Greg KH
2020-02-19  7:39 ` [PATCH 4/9] vt: selection, localize use_unicode Jiri Slaby
2020-02-19  7:39 ` [PATCH 5/9] vt: selection, create struct from console selection globals Jiri Slaby
2020-02-19  7:39 ` [PATCH 6/9] vt: switch vt_dont_switch to bool Jiri Slaby
2020-02-19  7:39 ` [PATCH 7/9] vt: vt_kern.h, remove extern from functions Jiri Slaby
2020-02-19  7:39 ` [PATCH 8/9] vt: selection, remove redeclaration of poke_blanked_console Jiri Slaby
2020-02-19  7:39 ` [PATCH 9/9] vt: selection, indent switch-case properly Jiri Slaby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).