lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20131231090932.GA3223@udknight>
Date:	Tue, 31 Dec 2013 17:09:32 +0800
From:	Wang YanQing <udknight@...il.com>
To:	gregkh@...uxfoundation.org
Cc:	jslaby@...e.cz, airlied@...hat.com, akpm@...ux-foundation.org,
	kilobyte@...band.pl, linux-kernel@...r.kernel.org
Subject: [PATCH ]vt: use vc_allocate in con_init

After commit a5f4f52e82114e85aa1a066bd1a450acc19a464d
("vt: use kzalloc() instead of the bootmem allocator"),
then we could use vc_allocate in con_init.

The benefit we get:
1: reduce code duplication
2: vc_allocate is more robust

Signed-off-by: Wang YanQing <udknight@...il.com>
---
 drivers/tty/vt/vt.c       | 25 +++++++++++--------------
 drivers/tty/vt/vt_ioctl.c |  8 ++++----
 include/linux/vt_kern.h   |  2 +-
 3 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 15aaa01..8723cb4 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -748,7 +748,7 @@ static void visual_init(struct vc_data *vc, int num, int init)
 	vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row;
 }
 
-int vc_allocate(unsigned int currcons)	/* return 0 on success */
+int vc_allocate(unsigned int currcons, int early)	/* return 0 on success */
 {
 	WARN_CONSOLE_UNLOCKED();
 
@@ -789,9 +789,11 @@ int vc_allocate(unsigned int currcons)	/* return 0 on success */
 	    if (global_cursor_default == -1)
 		    global_cursor_default = 1;
 
-	    vc_init(vc, vc->vc_rows, vc->vc_cols, 1);
-	    vcs_make_sysfs(currcons);
-	    atomic_notifier_call_chain(&vt_notifier_list, VT_ALLOCATE, &param);
+	    vc_init(vc, vc->vc_rows, vc->vc_cols, currcons == 0 ? !vc->vc_sw->con_save_screen : 1);
+	    if (!early) {
+		    vcs_make_sysfs(currcons);
+		    atomic_notifier_call_chain(&vt_notifier_list, VT_ALLOCATE, &param);
+	    }
 	}
 	return 0;
 }
@@ -2765,7 +2767,7 @@ static int con_install(struct tty_driver *driver, struct tty_struct *tty)
 	int ret;
 
 	console_lock();
-	ret = vc_allocate(currcons);
+	ret = vc_allocate(currcons, 0);
 	if (ret)
 		goto unlock;
 
@@ -2901,15 +2903,10 @@ static int __init con_init(void)
 		mod_timer(&console_timer, jiffies + (blankinterval * HZ));
 	}
 
-	for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) {
-		vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT);
-		INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK);
-		tty_port_init(&vc->port);
-		visual_init(vc, currcons, 1);
-		vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT);
-		vc_init(vc, vc->vc_rows, vc->vc_cols,
-			currcons || !vc->vc_sw->con_save_screen);
-	}
+	for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++)
+		if (vc_allocate(currcons, 1))
+			panic("Can't initialize console %d!", currcons + 1);
+
 	currcons = fg_console = 0;
 	master_display_fg = vc = vc_cons[currcons].d;
 	set_origin(vc);
diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 2bd78e2..59667c1 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -680,7 +680,7 @@ int vt_ioctl(struct tty_struct *tty,
 		else {
 			arg--;
 			console_lock();
-			ret = vc_allocate(arg);
+			ret = vc_allocate(arg, 0);
 			console_unlock();
 			if (ret)
 				break;
@@ -705,7 +705,7 @@ int vt_ioctl(struct tty_struct *tty,
 		else {
 			vsa.console--;
 			console_lock();
-			ret = vc_allocate(vsa.console);
+			ret = vc_allocate(vsa.console, 0);
 			if (ret == 0) {
 				struct vc_data *nvc;
 				/* This is safe providing we don't drop the
@@ -778,7 +778,7 @@ int vt_ioctl(struct tty_struct *tty,
 				int newvt;
 				newvt = vc->vt_newvt;
 				vc->vt_newvt = -1;
-				ret = vc_allocate(newvt);
+				ret = vc_allocate(newvt, 0);
 				if (ret) {
 					console_unlock();
 					break;
@@ -1441,7 +1441,7 @@ int vt_move_to_console(unsigned int vt, int alloc)
 	}
 	prev = fg_console;
 
-	if (alloc && vc_allocate(vt)) {
+	if (alloc && vc_allocate(vt, 0)) {
 		/* we can't have a free VC for now. Too bad,
 		 * we don't want to mess the screen for now. */
 		console_unlock();
diff --git a/include/linux/vt_kern.h b/include/linux/vt_kern.h
index 8d76342..96d8795 100644
--- a/include/linux/vt_kern.h
+++ b/include/linux/vt_kern.h
@@ -33,7 +33,7 @@ extern int fg_console, last_console, want_console;
 
 /* console.c */
 
-int vc_allocate(unsigned int console);
+int vc_allocate(unsigned int console, int early);
 int vc_cons_allocated(unsigned int console);
 int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines);
 struct vc_data *vc_deallocate(unsigned int console);
-- 
1.8.3.4.8.g69490f3.dirty
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ