diff mbox

acpica: fwts_acpica_init(): handle out of memory failures

Message ID 1330683236-19002-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King March 2, 2012, 10:13 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpica/fwts_acpica.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

Comments

Keng-Yu Lin March 5, 2012, 9:43 a.m. UTC | #1
On Fri, Mar 2, 2012 at 6:13 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpica/fwts_acpica.c |   18 +++++++++++++++++-
>  1 files changed, 17 insertions(+), 1 deletions(-)
>
> diff --git a/src/acpica/fwts_acpica.c b/src/acpica/fwts_acpica.c
> index 0c2a3ff..096683a 100644
> --- a/src/acpica/fwts_acpica.c
> +++ b/src/acpica/fwts_acpica.c
> @@ -475,7 +475,11 @@ int fwts_acpica_init(fwts_framework *fw)
>                fwts_acpi_table_info *tbl;
>
>                fwts_acpica_FADT = fwts_low_calloc(1, table->length);
> -               memcpy(fwts_acpica_FADT, table->data, table->length);
> +               if (fwts_acpica_FADT == NULL) {
> +                       fwts_log_error(fw, "Out of memory allocating FADT.");
> +                       return FWTS_ERROR;
> +               }
> +               memcpy(fwts_acpica_FADT, table->data, table->length);
>
>                if (fwts_acpi_find_table(fw, "DSDT", 0, &tbl) != FWTS_OK)
>                        return FWTS_ERROR;
> @@ -515,6 +519,10 @@ int fwts_acpica_init(fwts_framework *fw)
>                uint64_t *entries;
>
>                fwts_acpica_XSDT = fwts_low_calloc(1, table->length);
> +               if (fwts_acpica_XSDT == NULL) {
> +                       fwts_log_error(fw, "Out of memory allocating XSDT.");
> +                       return FWTS_ERROR;
> +               }
>                memcpy(fwts_acpica_XSDT, table->data, sizeof(ACPI_TABLE_HEADER));
>
>                n = (table->length - sizeof(ACPI_TABLE_HEADER)) / sizeof(uint64_t);
> @@ -546,6 +554,10 @@ int fwts_acpica_init(fwts_framework *fw)
>                uint32_t *entries;
>
>                fwts_acpica_RSDT = fwts_low_calloc(1, table->length);
> +               if (fwts_acpica_RSDT == NULL) {
> +                       fwts_log_error(fw, "Out of memory allocating RSDT.");
> +                       return FWTS_ERROR;
> +               }
>                memcpy(fwts_acpica_RSDT, table->data, sizeof(ACPI_TABLE_HEADER));
>
>                n = (table->length - sizeof(ACPI_TABLE_HEADER)) / sizeof(uint32_t);
> @@ -576,6 +588,10 @@ int fwts_acpica_init(fwts_framework *fw)
>                return FWTS_ERROR;
>        if (table) {
>                fwts_acpica_RSDP = fwts_low_calloc(1, table->length);
> +               if (fwts_acpica_RSDP == NULL) {
> +                       fwts_log_error(fw, "Out of memory allocating RSDP.");
> +                       return FWTS_ERROR;
> +               }
>                memcpy(fwts_acpica_RSDP, table->data, table->length);
>
>                if (table->length > 20)
> --
> 1.7.9
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Alex Hung March 6, 2012, 9:30 a.m. UTC | #2
On 03/02/2012 06:13 PM, Colin King wrote:
> From: Colin Ian King<colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King<colin.king@canonical.com>
> ---
>   src/acpica/fwts_acpica.c |   18 +++++++++++++++++-
>   1 files changed, 17 insertions(+), 1 deletions(-)
>
> diff --git a/src/acpica/fwts_acpica.c b/src/acpica/fwts_acpica.c
> index 0c2a3ff..096683a 100644
> --- a/src/acpica/fwts_acpica.c
> +++ b/src/acpica/fwts_acpica.c
> @@ -475,7 +475,11 @@ int fwts_acpica_init(fwts_framework *fw)
>   		fwts_acpi_table_info *tbl;
>
>   		fwts_acpica_FADT = fwts_low_calloc(1, table->length);
> -		memcpy(fwts_acpica_FADT, table->data, table->length);		
> +		if (fwts_acpica_FADT == NULL) {
> +			fwts_log_error(fw, "Out of memory allocating FADT.");
> +			return FWTS_ERROR;
> +		}
> +		memcpy(fwts_acpica_FADT, table->data, table->length);
>
>   		if (fwts_acpi_find_table(fw, "DSDT", 0,&tbl) != FWTS_OK)
>   			return FWTS_ERROR;
> @@ -515,6 +519,10 @@ int fwts_acpica_init(fwts_framework *fw)
>   		uint64_t *entries;
>
>   		fwts_acpica_XSDT = fwts_low_calloc(1, table->length);
> +		if (fwts_acpica_XSDT == NULL) {
> +			fwts_log_error(fw, "Out of memory allocating XSDT.");
> +			return FWTS_ERROR;
> +		}
>   		memcpy(fwts_acpica_XSDT, table->data, sizeof(ACPI_TABLE_HEADER));
>
>   		n = (table->length - sizeof(ACPI_TABLE_HEADER)) / sizeof(uint64_t);
> @@ -546,6 +554,10 @@ int fwts_acpica_init(fwts_framework *fw)
>   		uint32_t *entries;
>   	
>   		fwts_acpica_RSDT = fwts_low_calloc(1, table->length);
> +		if (fwts_acpica_RSDT == NULL) {
> +			fwts_log_error(fw, "Out of memory allocating RSDT.");
> +			return FWTS_ERROR;
> +		}
>   		memcpy(fwts_acpica_RSDT, table->data, sizeof(ACPI_TABLE_HEADER));
>   	
>   		n = (table->length - sizeof(ACPI_TABLE_HEADER)) / sizeof(uint32_t);
> @@ -576,6 +588,10 @@ int fwts_acpica_init(fwts_framework *fw)
>   		return FWTS_ERROR;
>   	if (table) {
>   		fwts_acpica_RSDP = fwts_low_calloc(1, table->length);
> +		if (fwts_acpica_RSDP == NULL) {
> +			fwts_log_error(fw, "Out of memory allocating RSDP.");
> +			return FWTS_ERROR;
> +		}
>   		memcpy(fwts_acpica_RSDP, table->data, table->length);
>
>   		if (table->length>  20)
Acked-by: Alex Hung<alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/acpica/fwts_acpica.c b/src/acpica/fwts_acpica.c
index 0c2a3ff..096683a 100644
--- a/src/acpica/fwts_acpica.c
+++ b/src/acpica/fwts_acpica.c
@@ -475,7 +475,11 @@  int fwts_acpica_init(fwts_framework *fw)
 		fwts_acpi_table_info *tbl;
 
 		fwts_acpica_FADT = fwts_low_calloc(1, table->length);
-		memcpy(fwts_acpica_FADT, table->data, table->length);		
+		if (fwts_acpica_FADT == NULL) {
+			fwts_log_error(fw, "Out of memory allocating FADT.");
+			return FWTS_ERROR;
+		}
+		memcpy(fwts_acpica_FADT, table->data, table->length);
 
 		if (fwts_acpi_find_table(fw, "DSDT", 0, &tbl) != FWTS_OK)
 			return FWTS_ERROR;
@@ -515,6 +519,10 @@  int fwts_acpica_init(fwts_framework *fw)
 		uint64_t *entries;
 
 		fwts_acpica_XSDT = fwts_low_calloc(1, table->length);
+		if (fwts_acpica_XSDT == NULL) {
+			fwts_log_error(fw, "Out of memory allocating XSDT.");
+			return FWTS_ERROR;
+		}
 		memcpy(fwts_acpica_XSDT, table->data, sizeof(ACPI_TABLE_HEADER));
 
 		n = (table->length - sizeof(ACPI_TABLE_HEADER)) / sizeof(uint64_t);
@@ -546,6 +554,10 @@  int fwts_acpica_init(fwts_framework *fw)
 		uint32_t *entries;
 	
 		fwts_acpica_RSDT = fwts_low_calloc(1, table->length);
+		if (fwts_acpica_RSDT == NULL) {
+			fwts_log_error(fw, "Out of memory allocating RSDT.");
+			return FWTS_ERROR;
+		}
 		memcpy(fwts_acpica_RSDT, table->data, sizeof(ACPI_TABLE_HEADER));
 	
 		n = (table->length - sizeof(ACPI_TABLE_HEADER)) / sizeof(uint32_t);
@@ -576,6 +588,10 @@  int fwts_acpica_init(fwts_framework *fw)
 		return FWTS_ERROR;
 	if (table) {
 		fwts_acpica_RSDP = fwts_low_calloc(1, table->length);
+		if (fwts_acpica_RSDP == NULL) {
+			fwts_log_error(fw, "Out of memory allocating RSDP.");
+			return FWTS_ERROR;
+		}
 		memcpy(fwts_acpica_RSDP, table->data, table->length);
 
 		if (table->length > 20)