Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame^] | 1 | From 03a886252f6555d6b0af76b654e76459642b89da Mon Sep 17 00:00:00 2001 |
| 2 | From: Yunguo Wei <yunguo.wei@windriver.com> |
| 3 | Date: Tue, 3 Dec 2013 18:12:50 +0800 |
| 4 | Subject: [PATCH] pmtools: switch to dynamic buffer for huge ACPI tables |
| 5 | |
| 6 | For servers like Canoe Pass or Thunder Ridge, there are much more |
| 7 | entries in ACPI table, so original 1K buffer is insufficient. |
| 8 | |
| 9 | We switch to dynamic buffer on this situation. |
| 10 | |
| 11 | Signed-off-by: Yunguo Wei <yunguo.wei@windriver.com> |
| 12 | |
| 13 | |
| 14 | Upstream-Status: Pending |
| 15 | |
| 16 | Signed-off-by: Kai Kang <kai.kang@windriver.com> |
| 17 | --- |
| 18 | madt/madt.c | 18 +++++++++++++++++- |
| 19 | 1 file changed, 17 insertions(+), 1 deletion(-) |
| 20 | |
| 21 | diff --git a/madt/madt.c b/madt/madt.c |
| 22 | index aed965c..8770cd5 100644 |
| 23 | --- a/madt/madt.c |
| 24 | +++ b/madt/madt.c |
| 25 | @@ -51,7 +51,9 @@ get_next_entry(acpi_table_entry_header * entry_header) |
| 26 | return retval; |
| 27 | } |
| 28 | |
| 29 | -u8 buffer[1024]; |
| 30 | + |
| 31 | +u8 buf[1024]; |
| 32 | +u8 *buffer = buf; |
| 33 | |
| 34 | main() |
| 35 | { |
| 36 | @@ -75,6 +77,17 @@ main() |
| 37 | |
| 38 | if (verbose) printf("header.length %d\n", madt_header->header.length); |
| 39 | |
| 40 | + /* if 1K buffer is insufficient for acpi table, switch to a larger memory buffer */ |
| 41 | + if(expected_length > sizeof(buf)) { |
| 42 | + buffer = malloc(expected_length); |
| 43 | + if (!buffer) { |
| 44 | + perror("malloc"); |
| 45 | + exit(1); |
| 46 | + } |
| 47 | + memset(buffer, 0, expected_length); |
| 48 | + memcpy(buffer, buf, sizeof(struct acpi_table_madt)); |
| 49 | + } |
| 50 | + |
| 51 | acpi_table_print((void*)&(buffer[bytes_read]), 0); |
| 52 | |
| 53 | bytes_read = sizeof(struct acpi_table_madt); |
| 54 | @@ -118,6 +131,9 @@ done: |
| 55 | printf("Checksum 0x%x != 0; 0x%x in header ERROR\n", csum, |
| 56 | madt_header->header.checksum); |
| 57 | |
| 58 | + if(buffer != buf) |
| 59 | + free(buffer); |
| 60 | + |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | -- |
| 65 | 1.8.1.2 |
| 66 | |