/* Add memory segment to the segment list if it doesn't overlap with an already present segment.  */
static int insert_memory_segment(struct memory_segment *seg)
/* Add memory segment to the segment list if it doesn't overlap with an already present segment.  */
static int insert_memory_segment(struct memory_segment *seg)
{
	struct memory_segment *tmp;
	if (seg->start + seg->size > VMEM_MAX_PHYS ||
	    seg->start + seg->size < seg->start)
		return -ERANGE;
	list_for_each_entry(tmp, &mem_segs, list) {
		if (seg->start >= tmp->start + tmp->size)
			continue;
		if (seg->start + seg->size <= tmp->start)
			continue;
		return -ENOSPC;
	}
	list_add(&seg->list, &mem_segs);
	return 0;
}