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

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