summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSachin P. Sant <sachinp@in.ibm.com>2006-12-22 12:34:55 +0530
committerSimon Horman <horms@verge.net.au>2006-12-25 11:32:12 +0900
commit7792798a79b78a5d566f70c9f00237d050b01350 (patch)
tree78e24530115805e19eeea397f184218617ece52d
parent64d74e97fddefa8241fb493fa5b497625317342c (diff)
ppc64: Dynamic mem allocation kexec tools Cleanup update
Here is a update to the previously submitted patch to dynamically allocate memory for memory range data structures. This patch adds following functionality * memset all allocated memory ranges pointers. * Simplify some of the code related to memory ranges allocation. Signed-off-by : Sachin Sant <sachinp@in.ibm.com> * Removed trailing whitespace Signed-off-by : Simon Horman <horms@verge.net.au>
-rw-r--r--kexec/arch/ppc64/crashdump-ppc64.c9
-rw-r--r--kexec/arch/ppc64/kexec-ppc64.c24
2 files changed, 20 insertions, 13 deletions
diff --git a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c
index 39879af..33d4b18 100644
--- a/kexec/arch/ppc64/crashdump-ppc64.c
+++ b/kexec/arch/ppc64/crashdump-ppc64.c
@@ -105,17 +105,18 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
DIR *dir, *dmem;
FILE *file;
struct dirent *dentry, *mentry;
- int i, n;
+ int i, n, crash_rng_len = 0;
unsigned long long start, end, cstart, cend;
crash_max_memory_ranges = max_memory_ranges + 6;
+ crash_rng_len = sizeof(struct memory_range) * crash_max_memory_ranges;
- crash_memory_range = (struct memory_range *) malloc(
- (sizeof(struct memory_range) * (crash_max_memory_ranges)));
+ crash_memory_range = (struct memory_range *) malloc(crash_rng_len);
if (!crash_memory_range) {
fprintf(stderr, "Allocation for crash memory range failed\n");
return -1;
}
+ memset(crash_memory_range, 0, crash_rng_len);
/* create a separate program header for the backup region */
crash_memory_range[0].start = BACKUP_SRC_START;
@@ -154,7 +155,7 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
closedir(dir);
goto err;
}
- if (memory_ranges >= max_memory_ranges) {
+ if (memory_ranges >= (max_memory_ranges + 1)) {
/* No space to insert another element. */
fprintf(stderr,
"Error: Number of crash memory ranges"
diff --git a/kexec/arch/ppc64/kexec-ppc64.c b/kexec/arch/ppc64/kexec-ppc64.c
index 0576f6d..5429863 100644
--- a/kexec/arch/ppc64/kexec-ppc64.c
+++ b/kexec/arch/ppc64/kexec-ppc64.c
@@ -66,26 +66,32 @@ static void cleanup_memory_ranges()
*/
static int alloc_memory_ranges()
{
- memory_range = (struct memory_range *) malloc(
- (sizeof(struct memory_range) * max_memory_ranges));
+ int memory_range_len, exclude_range_len;
+
+ memory_range_len = sizeof(struct memory_range) * max_memory_ranges;
+ exclude_range_len = sizeof(struct exclude_range) * max_memory_ranges;
+
+ memory_range = (struct memory_range *) malloc(memory_range_len);
if (!memory_range)
- goto err1;
+ return -1;
- base_memory_range = (struct memory_range *) malloc(
- (sizeof(struct memory_range) * max_memory_ranges));
+ base_memory_range = (struct memory_range *) malloc(memory_range_len);
if (!base_memory_range)
goto err1;
- exclude_range = (struct exclude_range *) malloc(
- (sizeof(struct exclude_range) * max_memory_ranges));
+ exclude_range = (struct exclude_range *) malloc(exclude_range_len);
if (!exclude_range)
goto err1;
- usablemem_rgns.ranges = (struct exclude_range *) malloc(
- (sizeof(struct exclude_range) * max_memory_ranges));
+ usablemem_rgns.ranges = (struct exclude_range *)
+ malloc(exclude_range_len);
if (!(usablemem_rgns.ranges))
goto err1;
+ memset(memory_range, 0, memory_range_len);
+ memset(base_memory_range, 0, memory_range_len);
+ memset(exclude_range, 0, exclude_range_len);
+ memset(usablemem_rgns.ranges, 0, exclude_range_len);
return 0;
err1: