Index: kernel/genarch/src/drivers/ns16550/ns16550.c
===================================================================
--- kernel/genarch/src/drivers/ns16550/ns16550.c	(revision ed88c8e9e48e792fdd0df46568e33e36eb624db3)
+++ kernel/genarch/src/drivers/ns16550/ns16550.c	(revision 10d65d70906a865fb116576edc88e47ab61a5fb4)
@@ -47,4 +47,19 @@
 #define LSR_TH_READY    0x20
 
+#define RETRY_CNT	100000
+
+#define NOTHING \
+	do { \
+	} while(0)
+
+#define WHILE_CNT_AND_COND_DO(cnt, expr, statement) \
+	do { \
+		for (volatile unsigned i = 0; i < (cnt); i++) \
+			if ((expr)) \
+				statement; \
+			else \
+				break; \
+	} while (0)
+
 static uint8_t ns16550_reg_read(ns16550_instance_t *inst, ns16550_reg_t reg)
 {
@@ -78,15 +93,18 @@
 }
 
-/**< Clear input buffer. */
+/** Clear input buffer. */
 static void ns16550_clear_buffer(ns16550_instance_t *instance)
 {
-	while (ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY)
-		(void) ns16550_reg_read(instance, NS16550_REG_RBR);
+	WHILE_CNT_AND_COND_DO(RETRY_CNT,
+	    ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY,
+	    (void) ns16550_reg_read(instance, NS16550_REG_RBR));
 }
 
 static void ns16550_sendb(ns16550_instance_t *instance, uint8_t byte)
 {
-	while (!(ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_TH_READY))
-		;
+	WHILE_CNT_AND_COND_DO(RETRY_CNT,
+	    !(ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_TH_READY),
+	    NOTHING);
+
 	ns16550_reg_write(instance, NS16550_REG_THR, byte);
 }
