Blame SOURCES/kexec-tools-2.0.14-kexec-exntend-the-semantics-of-kexec_iomem_for_each_.patch

23ef29
From e7bb07ee7b499f71990e9e83596bdb2ddabdd4cd Mon Sep 17 00:00:00 2001
23ef29
Message-Id: <e7bb07ee7b499f71990e9e83596bdb2ddabdd4cd.1489676829.git.panand@redhat.com>
23ef29
In-Reply-To: <f85183096d31d865c97565614535d84943b12908.1489676829.git.panand@redhat.com>
23ef29
References: <f85183096d31d865c97565614535d84943b12908.1489676829.git.panand@redhat.com>
23ef29
From: AKASHI Takahiro <takahiro.akashi@linaro.org>
23ef29
Date: Wed, 15 Mar 2017 18:38:16 +0900
23ef29
Subject: [PATCH 02/10] kexec: exntend the semantics of
23ef29
 kexec_iomem_for_each_line
23ef29
23ef29
The current kexec_iomem_for_each_line() counts up all the lines for which
23ef29
a callback function returns zero(0) or positive, and otherwise it stops
23ef29
further scanning.
23ef29
This behavior is incovenient in some cases. For instance, on arm64, we want
23ef29
to count up "System RAM" entries, but need to skip "reserved" entries.
23ef29
23ef29
So this patch extends the semantics so that we will continue to scan
23ef29
succeeding entries but not count lines for which a callback function
23ef29
returns positive.
23ef29
23ef29
The current users of kexec_iomem_for_each_line(), arm, sh and x86, will not
23ef29
be affected by this change because
23ef29
* arm
23ef29
  The callback function only returns -1 or 0, and the return value of
23ef29
  kexec_iomem_for_each_line() will never be used.
23ef29
* sh, x86
23ef29
  The callback function may return (-1 for sh,) 0 or 1, but always returns
23ef29
  1 once we have reached the maximum number of entries allowed.
23ef29
  Even so the current kexec_iomem_for_each_line() counts them up.
23ef29
  This change actually fixes this bug.
23ef29
23ef29
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
23ef29
---
23ef29
 kexec/kexec-iomem.c | 15 ++++++++++-----
23ef29
 1 file changed, 10 insertions(+), 5 deletions(-)
23ef29
23ef29
diff --git a/kexec/kexec-iomem.c b/kexec/kexec-iomem.c
23ef29
index 485a2e810080..0a0277a422d8 100644
23ef29
--- a/kexec/kexec-iomem.c
23ef29
+++ b/kexec/kexec-iomem.c
23ef29
@@ -18,6 +18,9 @@
23ef29
  * Iterate over each line in the file returned by proc_iomem(). If match is
23ef29
  * NULL or if the line matches with our match-pattern then call the
23ef29
  * callback if non-NULL.
23ef29
+ * If match is NULL, callback should return a negative if error.
23ef29
+ * Otherwise the interation goes on, incrementing nr but only if callback
23ef29
+ * returns 0 (matched).
23ef29
  *
23ef29
  * Return the number of lines matched.
23ef29
  */
23ef29
@@ -37,7 +40,7 @@ int kexec_iomem_for_each_line(char *match,
23ef29
 	char *str;
23ef29
 	int consumed;
23ef29
 	int count;
23ef29
-	int nr = 0;
23ef29
+	int nr = 0, ret;
23ef29
 
23ef29
 	fp = fopen(iomem, "r");
23ef29
 	if (!fp)
23ef29
@@ -50,11 +53,13 @@ int kexec_iomem_for_each_line(char *match,
23ef29
 		str = line + consumed;
23ef29
 		size = end - start + 1;
23ef29
 		if (!match || memcmp(str, match, strlen(match)) == 0) {
23ef29
-			if (callback
23ef29
-			    && callback(data, nr, str, start, size) < 0) {
23ef29
-				break;
23ef29
+			if (callback) {
23ef29
+				ret = callback(data, nr, str, start, size);
23ef29
+				if (ret < 0)
23ef29
+					break;
23ef29
+				else if (ret == 0)
23ef29
+					nr++;
23ef29
 			}
23ef29
-			nr++;
23ef29
 		}
23ef29
 	}
23ef29
 
23ef29
-- 
23ef29
2.9.3
23ef29