/* Insert a resource into the resource tree, possibly expanding it in order to make it encompass any conflicting resources.  */
void insert_resource_expand_to_fit(struct resource *root, struct resource *new)
/* Insert a resource into the resource tree, possibly expanding it in order to make it encompass any conflicting resources.  */
void insert_resource_expand_to_fit(struct resource *root, struct resource *new)
{
	if (new->parent)
		return;
	write_lock(&resource_lock);
	for (;;) {
		struct resource *conflict;
		conflict = __insert_resource(root, new);
		if (!conflict)
			break;
		if (conflict == root)
			break;
		if (conflict->start < new->start)
			new->start = conflict->start;
		if (conflict->end > new->end)
			new->end = conflict->end;
		printk("Expanded resource %s due to conflict with %s\n", new->name, conflict->name);
	}
	write_unlock(&resource_lock);
}