diff mbox series

[v3,5/5] discover/platform-powerpc: don't copy IANA from mbox to buffer

Message ID 20191017100610.GA6709@gmail.com
State Accepted
Headers show
Series [v3,1/5] discover/platform-powerpc: add missing mbox block selector | expand

Commit Message

Maxim Polyakov Oct. 17, 2019, 10:06 a.m. UTC
This patch adds code that takes into account the size of the IANA
identifier number in the mailbox and doesn't copy it into the data
buffer.

Signed-off-by: Maxim Polyakov <m.polyakov@yadro.com>
---
 discover/platform-powerpc.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c
index 533e21a..8932dee 100644
--- a/discover/platform-powerpc.c
+++ b/discover/platform-powerpc.c
@@ -560,6 +560,7 @@  static int get_ipmi_boot_mailbox(struct platform_powerpc *platform,
 	 * on higher numbers.
 	 */
 	for (i = 0; i < UCHAR_MAX; i++) {
+		uint8_t *boot_opt_data;
 		int block_size = get_ipmi_boot_mailbox_block(platform, &mailbox, i);
 		if (block_size < CHASSIS_BOOT_MBOX_IANA_SZ && i == 0) {
 			/*
@@ -576,9 +577,12 @@  static int get_ipmi_boot_mailbox(struct platform_powerpc *platform,
 		if (i == 0) {
 			/*
 			 * The first three bytes of block zero are an IANA
-			 * Enterprise ID number. Check it matches the IBM
-			 * number, '2'.
+			 * Enterprise ID number
 			 */
+			block_size -= CHASSIS_BOOT_MBOX_IANA_SZ;
+			boot_opt_data = &mailbox.b0.data;
+
+			/* Check IANA matches the IBM number, '2' */
 			if (mailbox.b0.iana[0] != 0x02 ||
 				mailbox.b0.iana[1] != 0x00 ||
 				mailbox.b0.iana[2] != 0x00) {
@@ -588,6 +592,8 @@  static int get_ipmi_boot_mailbox(struct platform_powerpc *platform,
 						mailbox.b0.iana[2]);
 				return -1;
 			}
+		} else {
+			boot_opt_data = &mailbox.data;
 		}
 
 		mailbox_buffer = talloc_realloc(platform, mailbox_buffer,
@@ -596,7 +602,7 @@  static int get_ipmi_boot_mailbox(struct platform_powerpc *platform,
 			pb_log_fn("Failed to allocate mailbox buffer\n");
 			return -1;
 		}
-		memcpy(mailbox_buffer + mailbox_size, &mailbox.data, block_size);
+		memcpy(mailbox_buffer + mailbox_size, boot_opt_data, block_size);
 		mailbox_size += block_size;
 	}
 
@@ -607,10 +613,10 @@  static int get_ipmi_boot_mailbox(struct platform_powerpc *platform,
 	else
 		pb_debug_fn("%hu blocks read (%zu bytes)\n", i, mailbox_size);
 
-	if (mailbox_size < 3 + strlen("petitboot,bootdevs="))
+	if (mailbox_size < strlen("petitboot,bootdevs="))
 		return -1;
 
-	prefix = talloc_strndup(mailbox_buffer, mailbox_buffer + 3,
+	prefix = talloc_strndup(mailbox_buffer, mailbox_buffer,
 			strlen("petitboot,bootdevs="));
 	if (!prefix) {
 		pb_log_fn("Couldn't check prefix\n");
@@ -628,9 +634,9 @@  static int get_ipmi_boot_mailbox(struct platform_powerpc *platform,
 	}
 
 	/* Don't include IANA number in buffer */
-	content_size = mailbox_size - 3 - strlen("petitboot,bootdevs=");
+	content_size = mailbox_size - strlen("petitboot,bootdevs=");
 	*buf = talloc_memdup(platform,
-			mailbox_buffer + 3 + strlen("petitboot,bootdevs="),
+			mailbox_buffer + strlen("petitboot,bootdevs="),
 			content_size + 1);
 	(*buf)[content_size] = '\0';