vt: use vc_allocate in con_init
PATCH v3 1/1 vt: use vc_allocate in con_init
After a5f4f52e82114e85aa1a066bd1a450acc19a464d ("vt: use kzalloc() instead of the bootmem allocator"), con_init began to use kzalloc to initialize vc_data, this patch convert con_init to use vc_allocate.
The benefit we get:
1: reduce code duplication
2: vc_allocate is more robust
3: use kmalloc instead of kzalloc for vc_screenbuf
---
Changes v2-v3:
1: fix warnings reported by checkpatch.pl
2: clarify changelog
drivers/tty/vt/vt.c | 28 ++++++++++++++-------------- drivers/tty/vt/vt_ioctl.c | 8 ++++---- include/linux/vt_kern.h | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-)
drivers/tty/vt/vt.c +14 -14
@@ -748,7 +748,8 @@ 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 */ +/* return 0 on success */ +int vc_allocate (unsigned int currcons,int early) {WARN_CONSOLE_UNLOCKED ();
@@ -789,9 +790,13 @@ 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 +2770,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 +2906,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);
drivers/tty/vt/vt_ioctl.c +4 -4
@@ -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 ();
include/linux/vt_kern.h +1 -1
@@ -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);
Signature · 1 line
1.8.3.4.8.g69490f3.dirty
Quoted 26 lines · Wang YanQing
After
a5f4f52e82114e85aa1a066bd1a450acc19a464d("vt: usekzalloc()instead of the bootmem allocator"),con_initbegan to use kzalloc to initializevc_data, this patch convertcon_initto usevc_allocate.The benefit we get:
1: reduce code duplication
2:vc_allocateis more robust
3: use kmalloc instead of kzalloc forvc_screenbufSigned-off-by Wang YanQing <[email protected]>---
Changes v2-v3:
1: fix warnings reported by checkpatch.pl
2: clarify changelogdrivers/tty/vt/vt.c | 28 ++++++++++++++-------------- drivers/tty/vt/vt_ioctl.c | 8 ++++---- include/linux/vt_kern.h | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-)drivers/tty/vt/vt.c +0
-0
drivers/tty/vt/vt.c static void visual_init(struct vc_data *vc, int num, int init) · line 752
Quoted 6 lines
drivers/tty/vt/vt.c +2
-1@@ -748,7 +748,8 @@ 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 */ +/* return 0 on success */ +int vc_allocate (unsigned int currcons,int early)
Could you use
bool/true/false
instead of
int/1/0
please?
Signature · 2 lines
js suse labs