[XEN] Fix read_console_ring() when passed a small buffer.
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Mon, 12 Jun 2006 09:05:55 +0000 (10:05 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Mon, 12 Jun 2006 09:05:55 +0000 (10:05 +0100)
From: Akio Takebe <takebe_akio@jp.fujitsu.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
xen/drivers/char/console.c

index f3a547038e706fb71227e8badb14d084ef7e2308..9e474d94cfdadb63023cde0241c61b2d5f9dd0bb 100644 (file)
@@ -230,7 +230,7 @@ long read_console_ring(XEN_GUEST_HANDLE(char) str, u32 *pcount, int clear)
     sofar = 0;
 
     c = conringc;
-    while ( c != conringp )
+    while ( (c != conringp) && (sofar < max) )
     {
         idx = CONRING_IDX_MASK(c);
         len = conringp - c;
@@ -247,7 +247,10 @@ long read_console_ring(XEN_GUEST_HANDLE(char) str, u32 *pcount, int clear)
     if ( clear )
     {
         spin_lock_irqsave(&console_lock, flags);
-        conringc = conringp;
+        if ( (conringp - c) > CONRING_SIZE )
+            conringc = conringp - CONRING_SIZE;
+        else
+            conringc = c;
         spin_unlock_irqrestore(&console_lock, flags);
     }