Blame SOURCES/kexec-tools-2.0.20-kexec-add-variant-helper-functions-for-handling-memo.patch

f4cf83
From cf977b1af9ec67fabcc6a625589c49c52d07b11d Mon Sep 17 00:00:00 2001
f4cf83
From: AKASHI Takahiro <takahiro.akashi@linaro.org>
f4cf83
Date: Wed, 18 Dec 2019 11:42:30 -0500
f4cf83
Subject: [PATCH 1/3] kexec: add variant helper functions for handling memory
f4cf83
 regions
f4cf83
f4cf83
mem_regions_alloc_and_add() and mem_regions_alloc_and_exclude() are
f4cf83
functionally equivalent to, respectively, mem_regions_add() and
f4cf83
mem_regions_exclude() except the formers will re-allocate memory
f4cf83
dynamically when no more entries are available in 'ranges' array.
f4cf83
f4cf83
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
f4cf83
Tested-by: Bhupesh Sharma <bhsharma@redhat.com>
f4cf83
Tested-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
f4cf83
Signed-off-by: Simon Horman <horms@verge.net.au>
f4cf83
---
f4cf83
 kexec/mem_regions.c | 42 ++++++++++++++++++++++++++++++++++++++++++
f4cf83
 kexec/mem_regions.h |  7 +++++++
f4cf83
 2 files changed, 49 insertions(+)
f4cf83
f4cf83
diff --git a/kexec/mem_regions.c b/kexec/mem_regions.c
f4cf83
index 50c8abccb93a..ad7d3f13fd84 100644
f4cf83
--- a/kexec/mem_regions.c
f4cf83
+++ b/kexec/mem_regions.c
f4cf83
@@ -125,3 +125,45 @@ int mem_regions_exclude(struct memory_ranges *ranges,
f4cf83
 	}
f4cf83
 	return 0;
f4cf83
 }
f4cf83
+
f4cf83
+#define KEXEC_MEMORY_RANGES 16
f4cf83
+
f4cf83
+int mem_regions_alloc_and_add(struct memory_ranges *ranges,
f4cf83
+			      unsigned long long base,
f4cf83
+			      unsigned long long length, int type)
f4cf83
+{
f4cf83
+	void *new_ranges;
f4cf83
+
f4cf83
+	if (ranges->size >= ranges->max_size) {
f4cf83
+		new_ranges = realloc(ranges->ranges,
f4cf83
+				sizeof(struct memory_range) *
f4cf83
+				(ranges->max_size + KEXEC_MEMORY_RANGES));
f4cf83
+		if (!new_ranges)
f4cf83
+			return -1;
f4cf83
+
f4cf83
+		ranges->ranges = new_ranges;
f4cf83
+		ranges->max_size += KEXEC_MEMORY_RANGES;
f4cf83
+	}
f4cf83
+
f4cf83
+	return mem_regions_add(ranges, base, length, type);
f4cf83
+}
f4cf83
+
f4cf83
+int mem_regions_alloc_and_exclude(struct memory_ranges *ranges,
f4cf83
+				  const struct memory_range *range)
f4cf83
+{
f4cf83
+	void *new_ranges;
f4cf83
+
f4cf83
+	/* for safety, we should have at least one free entry in ranges */
f4cf83
+	if (ranges->size >= ranges->max_size) {
f4cf83
+		new_ranges = realloc(ranges->ranges,
f4cf83
+				sizeof(struct memory_range) *
f4cf83
+				(ranges->max_size + KEXEC_MEMORY_RANGES));
f4cf83
+		if (!new_ranges)
f4cf83
+			return -1;
f4cf83
+
f4cf83
+		ranges->ranges = new_ranges;
f4cf83
+		ranges->max_size += KEXEC_MEMORY_RANGES;
f4cf83
+	}
f4cf83
+
f4cf83
+	return mem_regions_exclude(ranges, range);
f4cf83
+}
f4cf83
diff --git a/kexec/mem_regions.h b/kexec/mem_regions.h
f4cf83
index ae9e972b0206..e306d67e3261 100644
f4cf83
--- a/kexec/mem_regions.h
f4cf83
+++ b/kexec/mem_regions.h
f4cf83
@@ -12,4 +12,11 @@ int mem_regions_exclude(struct memory_ranges *ranges,
f4cf83
 int mem_regions_add(struct memory_ranges *ranges, unsigned long long base,
f4cf83
                     unsigned long long length, int type);
f4cf83
 
f4cf83
+int mem_regions_alloc_and_exclude(struct memory_ranges *ranges,
f4cf83
+				  const struct memory_range *range);
f4cf83
+
f4cf83
+int mem_regions_alloc_and_add(struct memory_ranges *ranges,
f4cf83
+			      unsigned long long base,
f4cf83
+			      unsigned long long length, int type);
f4cf83
+
f4cf83
 #endif
f4cf83
-- 
f4cf83
2.7.4
f4cf83