dev: fbcon: Add null pointer check

It maybe access a null pointer 'config'.

Change-Id: I0502e8fd0057390f5146715d71bf1c4d48f5b2cc
diff --git a/dev/fbcon/fbcon.c b/dev/fbcon/fbcon.c
index adc5e29..c9d0df6 100644
--- a/dev/fbcon/fbcon.c
+++ b/dev/fbcon/fbcon.c
@@ -21,7 +21,7 @@
  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
@@ -183,8 +183,13 @@
 	unsigned i, j;
 	uint32_t bg_color, check_color, tmp_color, tmp1_color;
 	char *pixels;
-	unsigned count = config->width * (FONT_HEIGHT * (y_end - y_start) - 1);
+	unsigned count;
 
+	/* ignore anything that happens before fbcon is initialized */
+	if (!config)
+		return;
+
+	count = config->width * (FONT_HEIGHT * (y_end - y_start) - 1);
 	pixels = config->base;
 	pixels += y_start * ((config->bpp / 8) * FONT_HEIGHT * config->width);
 
@@ -221,6 +226,10 @@
 	unsigned total_x, total_y;
 	unsigned bytes_per_bpp;
 
+	/* ignore anything that happens before fbcon is initialized */
+	if (!config)
+		return;
+
 	if (config->update_start)
 		config->update_start();
 	if (config->update_done)
@@ -235,9 +244,17 @@
 /* TODO: Take stride into account */
 static void fbcon_scroll_up(void)
 {
-	unsigned short *dst = config->base;
-	unsigned short *src = dst + (config->width * FONT_HEIGHT);
-	unsigned count = config->width * (config->height - FONT_HEIGHT);
+	unsigned short *dst = NULL;
+	unsigned short *src = NULL;
+	unsigned count = 0;
+
+	/* ignore anything that happens before fbcon is initialized */
+	if (!config)
+		return;
+
+	dst = config->base;
+	src = dst + (config->width * FONT_HEIGHT);
+	count = config->width * (config->height - FONT_HEIGHT);
 
 	while(count--) {
 		*dst++ = *src++;
@@ -257,6 +274,10 @@
 	uint32_t line_color, tmp_color;
 	int i, j;
 
+	/* ignore anything that happens before fbcon is initialized */
+	if (!config)
+		return;
+
 	/* set line's color via diffrent type */
 	line_color = fb_color_formats[type].fg;
 
@@ -291,10 +312,17 @@
 void fbcon_clear(void)
 {
 	unsigned long i = 0, j = 0;
-	unsigned char *pixels = config->base;
-	unsigned count = config->width * config->height;
+	unsigned char *pixels = NULL;
+	unsigned count;
 	uint32_t bg_color;
 
+	/* ignore anything that happens before fbcon is initialized */
+	if (!config)
+		return;
+
+	pixels = config->base;
+	count =  config->width * config->height;
+
 	fbcon_set_colors(FBCON_COMMON_MSG);
 	for (i = 0; i < count; i++) {
 		bg_color = BGCOLOR;