cec.c (860dbce3d8dd90cb9e909c58fa79808766243651) cec.c (f3c74b38a55aefe1004200d15a83f109b510068c)
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/mm.h>
3#include <linux/gfp.h>
4#include <linux/kernel.h>
5
6#include <asm/mce.h>
7
8#include "debugfs.h"

--- 169 unchanged lines hidden (view full) ---

178
179/*
180 * @to: index of the smallest element which is >= then @pfn.
181 *
182 * Return the index of the pfn if found, otherwise negative value.
183 */
184static int __find_elem(struct ce_array *ca, u64 pfn, unsigned int *to)
185{
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/mm.h>
3#include <linux/gfp.h>
4#include <linux/kernel.h>
5
6#include <asm/mce.h>
7
8#include "debugfs.h"

--- 169 unchanged lines hidden (view full) ---

178
179/*
180 * @to: index of the smallest element which is >= then @pfn.
181 *
182 * Return the index of the pfn if found, otherwise negative value.
183 */
184static int __find_elem(struct ce_array *ca, u64 pfn, unsigned int *to)
185{
186 int min = 0, max = ca->n - 1;
186 u64 this_pfn;
187 u64 this_pfn;
187 int min = 0, max = ca->n;
188
188
189 while (min < max) {
190 int tmp = (max + min) >> 1;
189 while (min <= max) {
190 int i = (min + max) >> 1;
191
191
192 this_pfn = PFN(ca->array[tmp]);
192 this_pfn = PFN(ca->array[i]);
193
194 if (this_pfn < pfn)
193
194 if (this_pfn < pfn)
195 min = tmp + 1;
195 min = i + 1;
196 else if (this_pfn > pfn)
196 else if (this_pfn > pfn)
197 max = tmp;
198 else {
199 min = tmp;
200 break;
197 max = i - 1;
198 else if (this_pfn == pfn) {
199 if (to)
200 *to = i;
201
202 return i;
201 }
202 }
203
203 }
204 }
205
206 /*
207 * When the loop terminates without finding @pfn, min has the index of
208 * the element slot where the new @pfn should be inserted. The loop
209 * terminates when min > max, which means the min index points to the
210 * bigger element while the max index to the smaller element, in-between
211 * which the new @pfn belongs to.
212 *
213 * For more details, see exercise 1, Section 6.2.1 in TAOCP, vol. 3.
214 */
204 if (to)
205 *to = min;
206
215 if (to)
216 *to = min;
217
207 this_pfn = PFN(ca->array[min]);
208
209 if (this_pfn == pfn)
210 return min;
211
212 return -ENOKEY;
213}
214
215static int find_elem(struct ce_array *ca, u64 pfn, unsigned int *to)
216{
217 WARN_ON(!to);
218
219 if (!ca->n) {

--- 312 unchanged lines hidden ---
218 return -ENOKEY;
219}
220
221static int find_elem(struct ce_array *ca, u64 pfn, unsigned int *to)
222{
223 WARN_ON(!to);
224
225 if (!ca->n) {

--- 312 unchanged lines hidden ---