
From: "Antonino A. Daplas" <adaplas@hotpop.com>

The function set_con2fb_map() is getting very big.  Split it into its
component functions.

Signed-off-by: Antonino Daplas <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/drivers/video/console/fbcon.c |  225 +++++++++++++++++++---------------
 1 files changed, 127 insertions(+), 98 deletions(-)

diff -puN drivers/video/console/fbcon.c~fbcon-split-set_con2fb_map drivers/video/console/fbcon.c
--- 25/drivers/video/console/fbcon.c~fbcon-split-set_con2fb_map	2004-11-07 16:32:35.526438896 -0800
+++ 25-akpm/drivers/video/console/fbcon.c	2004-11-07 16:32:35.532437984 -0800
@@ -503,96 +503,58 @@ static void set_blitting_type(struct vc_
 }
 #endif /* CONFIG_MISC_TILEBLITTING */
 
-/**
- *	set_con2fb_map - map console to frame buffer device
- *	@unit: virtual console number to map
- *	@newidx: frame buffer index to map virtual console to
- *      @user: user request
- *
- *	Maps a virtual console @unit to a frame buffer device
- *	@newidx.
- */
-static int set_con2fb_map(int unit, int newidx, int user)
+
+static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
+				  int unit, int oldidx)
 {
-	struct vc_data *vc = vc_cons[unit].d;
-	int oldidx = con2fb_map[unit];
-	struct fb_info *info = registered_fb[newidx];
-	struct fb_info *oldinfo = NULL;
-	struct fbcon_ops *ops;
-	int found;
+	struct fbcon_ops *ops = NULL;
+	int err = 0;
 
-	if (oldidx == newidx)
-		return 0;
+	if (!try_module_get(info->fbops->owner))
+		err = -ENODEV;
 
-	if (!info)
-		return -EINVAL;
+	if (!err && info->fbops->fb_open &&
+	    info->fbops->fb_open(info, 0))
+		err = -ENODEV;
 
-	if (!search_for_mapped_con()) {
-		info_idx = newidx;
-		return fbcon_takeover(0);
+	if (!err) {
+		ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
+		if (!ops)
+			err = -ENOMEM;
 	}
 
-	if (oldidx != -1)
-		oldinfo = registered_fb[oldidx];
-
-	found = search_fb_in_map(newidx);
-
-	acquire_console_sem();
-	con2fb_map[unit] = newidx;
-
-	if (!found) {
-		int err = 0;
-
-		ops = NULL;
-
-		if (!try_module_get(info->fbops->owner)) {
-			err = -ENODEV;
-		}
-
-		if (!err && info->fbops->fb_open &&
-		    info->fbops->fb_open(info, 0)) {
-			err = -ENODEV;
-		}
-
-		if (!err) {
-			ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
-			if (!ops)
-				err = -ENOMEM;
-		}
-
-		if (!err) {
-			memset(ops, 0, sizeof(struct fbcon_ops));
-			info->fbcon_par = ops;
-			set_blitting_type(vc, info, NULL);
-		}
+	if (!err) {
+		memset(ops, 0, sizeof(struct fbcon_ops));
+		info->fbcon_par = ops;
+		set_blitting_type(vc, info, NULL);
+	}
 
-		if (err) {
-			con2fb_map[unit] = oldidx;
-			module_put(info->fbops->owner);
-			release_console_sem();
-			return err;
-		}
+	if (err) {
+		con2fb_map[unit] = oldidx;
+		module_put(info->fbops->owner);
 	}
 
-	/*
-	 * If old fb is not mapped to any of the consoles,
-	 * fbcon should release it.
-	 */
-	if (oldinfo && !search_fb_in_map(oldidx)) {
+	return err;
+}
 
-		ops = oldinfo->fbcon_par;
+static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
+				  struct fb_info *newinfo, int unit,
+				  int oldidx, int found)
+{
+	struct fbcon_ops *ops = oldinfo->fbcon_par;
+	int err = 0;
 
-		if (oldinfo->fbops->fb_release &&
-		    oldinfo->fbops->fb_release(oldinfo, 0)) {
-			con2fb_map[unit] = oldidx;
-			if (!found && info->fbops->fb_release)
-				info->fbops->fb_release(info, 0);
-			if (!found)
-				module_put(info->fbops->owner);
-			release_console_sem();
-			return -ENODEV;
-		}
+	if (oldinfo->fbops->fb_release &&
+	    oldinfo->fbops->fb_release(oldinfo, 0)) {
+		con2fb_map[unit] = oldidx;
+		if (!found && newinfo->fbops->fb_release)
+			newinfo->fbops->fb_release(newinfo, 0);
+		if (!found)
+			module_put(newinfo->fbops->owner);
+		err = -ENODEV;
+	}
 
+	if (!err) {
 		if (oldinfo->queue.func == fb_flashcursor)
 			del_timer_sync(&ops->cursor_timer);
 
@@ -603,25 +565,31 @@ static int set_con2fb_map(int unit, int 
 		module_put(oldinfo->fbops->owner);
 	}
 
-	if (!found) {
-		if (!info->queue.func || info->queue.func == fb_flashcursor) {
+	return err;
+}
 
-			ops = info->fbcon_par;
+static void con2fb_init_newinfo(struct fb_info *info)
+{
+	if (!info->queue.func || info->queue.func == fb_flashcursor) {
+		struct fbcon_ops *ops = info->fbcon_par;
 
-			if (!info->queue.func)
-				INIT_WORK(&info->queue, fb_flashcursor, info);
+		if (!info->queue.func)
+			INIT_WORK(&info->queue, fb_flashcursor, info);
 
-			init_timer(&ops->cursor_timer);
-			ops->cursor_timer.function = cursor_timer_handler;
-			ops->cursor_timer.expires = jiffies + HZ / 5;
-			ops->cursor_timer.data = (unsigned long ) info;
-			add_timer(&ops->cursor_timer);
-		}
+		init_timer(&ops->cursor_timer);
+		ops->cursor_timer.function = cursor_timer_handler;
+		ops->cursor_timer.expires = jiffies + HZ / 5;
+		ops->cursor_timer.data = (unsigned long ) info;
+		add_timer(&ops->cursor_timer);
 	}
+}
+
+static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
+				int unit, int show_logo)
+{
+	struct fbcon_ops *ops = info->fbcon_par;
 
-	ops = info->fbcon_par;
 	ops->currcon = fg_console;
-	con2fb_map_boot[unit] = newidx;
 
 	if (info->fbops->fb_set_par)
 		info->fbops->fb_set_par(info);
@@ -631,17 +599,78 @@ static int set_con2fb_map(int unit, int 
 	else
 		fbcon_preset_disp(info, unit);
 
-	if (fg_console == 0 && !user && logo_shown != FBCON_LOGO_DONTSHOW) {
-		struct vc_data *vc = vc_cons[fg_console].d;
-		struct fb_info *fg_info = registered_fb[con2fb_map[fg_console]];
-
-		fbcon_prepare_logo(vc, fg_info, vc->vc_cols, vc->vc_rows,
-				   vc->vc_cols, vc->vc_rows);
+	if (show_logo) {
+		struct vc_data *fg_vc = vc_cons[fg_console].d;
+		struct fb_info *fg_info =
+			registered_fb[con2fb_map[fg_console]];
+
+		fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
+				   fg_vc->vc_rows, fg_vc->vc_cols,
+				   fg_vc->vc_rows);
 	}
 
 	switch_screen(fg_console);
+}
+
+/**
+ *	set_con2fb_map - map console to frame buffer device
+ *	@unit: virtual console number to map
+ *	@newidx: frame buffer index to map virtual console to
+ *      @user: user request
+ *
+ *	Maps a virtual console @unit to a frame buffer device
+ *	@newidx.
+ */
+static int set_con2fb_map(int unit, int newidx, int user)
+{
+	struct vc_data *vc = vc_cons[unit].d;
+	int oldidx = con2fb_map[unit];
+	struct fb_info *info = registered_fb[newidx];
+	struct fb_info *oldinfo = NULL;
+ 	int found, err = 0;
+
+	if (oldidx == newidx)
+		return 0;
+
+	if (!info)
+ 		err =  -EINVAL;
+
+ 	if (!err && !search_for_mapped_con()) {
+		info_idx = newidx;
+		return fbcon_takeover(0);
+	}
+
+	if (oldidx != -1)
+		oldinfo = registered_fb[oldidx];
+
+	found = search_fb_in_map(newidx);
+
+	acquire_console_sem();
+	con2fb_map[unit] = newidx;
+	if (!err && !found)
+ 		err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
+
+
+	/*
+	 * If old fb is not mapped to any of the consoles,
+	 * fbcon should release it.
+	 */
+ 	if (!err && oldinfo && !search_fb_in_map(oldidx))
+ 		err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
+ 					     found);
+
+ 	if (!err) {
+ 		int show_logo = (fg_console == 0 && !user &&
+ 				 logo_shown != FBCON_LOGO_DONTSHOW);
+
+ 		if (!found)
+ 			con2fb_init_newinfo(info);
+ 		con2fb_map_boot[unit] = newidx;
+ 		con2fb_init_display(vc, info, unit, show_logo);
+	}
+
 	release_console_sem();
-	return 0;
+ 	return err;
 }
 
 /*
_
