#include <linux/kernel.h>
#include <linux/string.h>
int add_range(struct range *range, int az, int nr_range, u64 start, u64 end)
range[nr_range].start = start;
range[nr_range].end = end;
int add_range_with_merge(struct range *range, int az, int nr_range,
for (i = 0; i < nr_range; i++) {
u64 common_start, common_end;
common_start = max(range[i].start, start);
common_end = min(range[i].end, end);
if (common_start > common_end)
start = min(range[i].start, start);
end = max(range[i].end, end);
memmove(&range[i], &range[i + 1],
(nr_range - (i + 1)) * sizeof(range[i]));
range[nr_range - 1].start = 0;
range[nr_range - 1].end = 0;
return add_range(range, az, nr_range, start, end);