refactor: extract VM's log buffer into separate struct

Extract the `log_buffer` and `log_buffer_length` fields from the `vm`
struct into a separate `log_buffer` struct.

Change-Id: I5d63418b6d9ee9dcf7792d89a229beea28d02c48
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
diff --git a/inc/hf/api.h b/inc/hf/api.h
index 4c30552..5bbbe7f 100644
--- a/inc/hf/api.h
+++ b/inc/hf/api.h
@@ -154,6 +154,7 @@
 struct ffa_value api_ffa_mem_perm_set(vaddr_t base_addr, uint32_t page_count,
 				      uint32_t mem_perm, struct vcpu *current);
 
+void api_flush_log_buffer(ffa_id_t id, struct log_buffer *buffer);
 struct ffa_value api_ffa_console_log(const struct ffa_value args,
 				     struct vcpu *current);
 
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index bdd029a..3559634 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -199,6 +199,11 @@
 	bool permissive;
 };
 
+struct log_buffer {
+	char chars[LOG_BUFFER_SIZE];
+	uint16_t len;
+};
+
 struct vm {
 	ffa_id_t id;
 	struct ffa_uuid uuids[PARTITION_MAX_UUIDS];
@@ -242,8 +247,7 @@
 		bool npi_injected;
 	} notifications;
 
-	char log_buffer[LOG_BUFFER_SIZE];
-	uint16_t log_buffer_length;
+	struct log_buffer log_buffer;
 
 	/**
 	 * Wait entries to be used when waiting on other VM mailboxes. See
diff --git a/src/api.c b/src/api.c
index 327ebfa..1ef18c1 100644
--- a/src/api.c
+++ b/src/api.c
@@ -4687,10 +4687,11 @@
  * Send the contents of the given VM's log buffer to the log, preceded
  * by the VM ID and followed by a newline.
  */
-void api_flush_vm_buffer(ffa_id_t id, char *buffer, size_t length)
+void api_flush_log_buffer(ffa_id_t id, struct log_buffer *buffer)
 {
-	buffer[length] = '\0';
-	dlog("%s %x: %s\n", ffa_is_vm_id(id) ? "VM" : "SP", id, buffer);
+	buffer->chars[buffer->len] = '\0';
+	dlog("%s %x: %s\n", ffa_is_vm_id(id) ? "VM" : "SP", id, buffer->chars);
+	buffer->len = 0;
 }
 
 /**
@@ -4755,6 +4756,8 @@
 	}
 
 	vm_locked = vm_lock(current->vm);
+	struct log_buffer *log_buffer = &current->vm->log_buffer;
+
 	for (size_t i = 0; i < chars_count; i++) {
 		bool flush = false;
 		const char c = chars[i];
@@ -4762,17 +4765,12 @@
 		if (c == '\n' || c == '\0') {
 			flush = true;
 		} else {
-			vm_locked.vm->log_buffer
-				[vm_locked.vm->log_buffer_length++] = c;
-			flush = (vm_locked.vm->log_buffer_length ==
-				 LOG_BUFFER_SIZE);
+			log_buffer->chars[log_buffer->len++] = c;
+			flush = log_buffer->len == LOG_BUFFER_SIZE;
 		}
 
 		if (flush) {
-			api_flush_vm_buffer(vm_locked.vm->id,
-					    vm_locked.vm->log_buffer,
-					    vm_locked.vm->log_buffer_length);
-			vm_locked.vm->log_buffer_length = 0;
+			api_flush_log_buffer(vm_locked.vm->id, log_buffer);
 		}
 	}