/* Caller should check returned pointer with dm_target_is_valid() to trap I/O beyond end of device.  */
struct dm_target* dm_table_find_target(struct dm_table *t, sector_t sector)
/* Caller should check returned pointer with dm_target_is_valid() to trap I/O beyond end of device.  */
struct dm_target* dm_table_find_target(struct dm_table *t, sector_t sector)
{
	unsigned int l, n = 0, k = 0;
	sector_t *node;
	for (l = 0; l < t->depth; l++) {
		n = get_child(n, k);
		node = get_node(t, l, n);
		for (k = 0; k < KEYS_PER_NODE; k++)
			if (node[k] >= sector)
				break;
	}
	return &t->targets[(KEYS_PER_NODE * n) + k];
}