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.
Please review.
Thanks
-Sachin
Signed-off-by : Sachin Sant <[EMAIL PROTECTED]>
* 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.
* Beautify some of the code related to memory ranges allocation.
*
Signed-off-by : Sachin Sant <[EMAIL PROTECTED]>
---
diff -Naurp a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c
--- a/kexec/arch/ppc64/crashdump-ppc64.c 2006-12-21 16:57:29.000000000 +0530
+++ b/kexec/arch/ppc64/crashdump-ppc64.c 2006-12-21 17:01:30.000000000 +0530
@@ -105,17 +105,18 @@ static int get_crash_memory_ranges(struc
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(struc
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 -Naurp a/kexec/arch/ppc64/kexec-ppc64.c b/kexec/arch/ppc64/kexec-ppc64.c
--- a/kexec/arch/ppc64/kexec-ppc64.c 2006-12-21 16:57:29.000000000 +0530
+++ b/kexec/arch/ppc64/kexec-ppc64.c 2006-12-21 17:05:34.000000000 +0530
@@ -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:
_______________________________________________
fastboot mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/fastboot