From: Wang YanQing <udknight@gmail.com>
To: gregkh@linuxfoundation.org
Cc: jslaby@suse.cz, airlied@redhat.com, akpm@linux-foundation.org,
kilobyte@angband.pl, linux-kernel@vger.kernel.org
Subject: [PATCH ]vt: use vc_allocate in con_init
Date: Tue, 31 Dec 2013 17:09:32 +0800 [thread overview]
Message-ID: <20131231090932.GA3223@udknight> (raw)
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@gmail.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, ¶m);
+ 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, ¶m);
+ }
}
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
reply other threads:[~2013-12-31 9:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131231090932.GA3223@udknight \
--to=udknight@gmail.com \
--cc=airlied@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.cz \
--cc=kilobyte@angband.pl \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.