From 614d99eba149d0fafc64dfdddc7ef04970e0d86c Mon Sep 17 00:00:00 2001
From: Michael Brown <mcb30@ipxe.org>
Date: Tue, 20 Apr 2021 13:28:57 +0100
Subject: [PATCH] [xen] Avoid infinite loop on allocation failure in
 xenstore_response()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Conflict:NA
Reference:https://github.com/ipxe/ipxe/commit/614d99eba149d0fafc64dfdddc7ef04970e0d86c
---
 src/interface/xen/xenstore.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/interface/xen/xenstore.c b/src/interface/xen/xenstore.c
index a14881f..c2da532 100644
--- a/src/interface/xen/xenstore.c
+++ b/src/interface/xen/xenstore.c
@@ -68,14 +68,14 @@ static void xenstore_send ( struct xen_hypervisor *xen, const void *data,
 	XENSTORE_RING_IDX cons;
 	XENSTORE_RING_IDX idx;
 	const char *bytes = data;
-	size_t offset = 0;
+	size_t offset;
 	size_t fill;
 
 	DBGCP ( intf, "XENSTORE raw request:\n" );
 	DBGCP_HDA ( intf, MASK_XENSTORE_IDX ( prod ), data, len );
 
 	/* Write one byte at a time */
-	while ( offset < len ) {
+	for ( offset =0 ; offset < len ; offset++ ) {
 
 		/* Wait for space to become available */
 		while ( 1 ) {
@@ -90,7 +90,7 @@ static void xenstore_send ( struct xen_hypervisor *xen, const void *data,
 
 		/* Write byte */
 		idx = MASK_XENSTORE_IDX ( prod++ );
-		writeb ( bytes[offset++], &intf->req[idx] );
+		writeb ( bytes[offset], &intf->req[idx] );
 	}
 
 	/* Update producer counter */
@@ -125,13 +125,13 @@ static void xenstore_recv ( struct xen_hypervisor *xen, void *data,
 	XENSTORE_RING_IDX prod;
 	XENSTORE_RING_IDX idx;
 	char *bytes = data;
-	size_t offset = 0;
+	size_t offset;
 	size_t fill;
 
 	DBGCP ( intf, "XENSTORE raw response:\n" );
 
 	/* Read one byte at a time */
-	while ( offset < len ) {
+	for ( offset = 0 ; offset < len ; offset++ ) {
 
 		/* Wait for data to be ready */
 		while ( 1 ) {
@@ -147,7 +147,7 @@ static void xenstore_recv ( struct xen_hypervisor *xen, void *data,
 		/* Read byte */
 		idx = MASK_XENSTORE_IDX ( cons++ );
 		if ( data )
-			bytes[offset++] = readb ( &intf->rsp[idx] );
+			bytes[offset] = readb ( &intf->rsp[idx] );
 	}
 	if ( data )
 		DBGCP_HDA ( intf, MASK_XENSTORE_IDX ( cons - len ), data, len );
-- 
2.23.0

