[U-Boot] [RFC PATCH 3/3] stdio/serial: factorize retrieve current device

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Sun Aug 23 15:26:59 CEST 2009


Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 common/serial.c |   62 +++++++++++++++++-------------------------------------
 1 files changed, 20 insertions(+), 42 deletions(-)

diff --git a/common/serial.c b/common/serial.c
index a4171be..7d764f2 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -179,77 +179,55 @@ void serial_reinit_all (void)
 	}
 }
 
-int serial_init (void)
+struct stdio_dev * serial_get_current_device(void)
 {
-	if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
-		struct stdio_dev *dev = default_serial_console ();
+	if (!(gd->flags & GD_FLG_RELOC) || !serial_current)
+		return default_serial_console ();
 
-		if (dev->start)
-			return dev->start (dev);
+	return serial_current;
+}
 
-		return 0;
-	}
+int serial_init (void)
+{
+	struct stdio_dev *dev = serial_get_current_device();
 
-	if (serial_current->start)
-		return serial_current->start (serial_current);
+	if (dev->start)
+		return dev->start (dev);
 
 	return 0;
 }
 
 void serial_setbrg (void)
 {
-	if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
-		struct stdio_dev *dev = default_serial_console ();
-
-		dev->setbrg (dev);
-		return;
-	}
+	struct stdio_dev *dev = serial_get_current_device();
 
-	serial_current->setbrg (serial_current);
+	dev->setbrg (dev);
 }
 
 int serial_getc (void)
 {
-	if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
-		struct stdio_dev *dev = default_serial_console ();
+	struct stdio_dev *dev = serial_get_current_device();
 
-		return dev->getc (dev);
-	}
-
-	return serial_current->getc (serial_current);
+	return dev->getc (dev);
 }
 
 int serial_tstc (void)
 {
-	if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
-		struct stdio_dev *dev = default_serial_console ();
-
-		return dev->tstc (dev);
-	}
+	struct stdio_dev *dev = serial_get_current_device();
 
-	return serial_current->tstc (serial_current);
+	return dev->tstc (dev);
 }
 
 void serial_putc (const char c)
 {
-	if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
-		struct stdio_dev *dev = default_serial_console ();
+	struct stdio_dev *dev = serial_get_current_device();
 
-		dev->putc (dev, c);
-		return;
-	}
-
-	serial_current->putc (serial_current, c);
+	dev->putc (dev, c);
 }
 
 void serial_puts (const char *s)
 {
-	if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
-		struct stdio_dev *dev = default_serial_console ();
-
-		dev->puts (dev, s);
-		return;
-	}
+	struct stdio_dev *dev = serial_get_current_device();
 
-	serial_current->puts (serial_current, s);
+	dev->puts (dev, s);
 }
-- 
1.6.3.1



More information about the U-Boot mailing list