Re: [PATCH v4 05/66] Maple Tree: Add new data structure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/1/21 15:29, Liam Howlett wrote:
> +/*
> + * mt_find() - Search from the start up until an entry is found.
> + * @mt: The maple tree
> + * @*index: Pointer which contains the start location of the search
> + * @max: The maximum value to check
> + *
> + * Handles locking.
> + *
> + * Return: The entry at or after the @*index or %NULL

Noticed later that the comment doesn't say how *index is updated.

> + */
> +void *mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max)
> +{
> +	MA_STATE(mas, mt, *index, *index);
> +	void *entry;
> +#ifdef CONFIG_DEBUG_MAPLE_TREE
> +	unsigned long copy = *index;
> +#endif
> +
> +	trace_ma_read(__func__, &mas);
> +
> +	if ((*index) > max)
> +		return NULL;
> +
> +	rcu_read_lock();
> +retry:
> +	entry = mas_state_walk(&mas);
> +	if (mas_is_start(&mas))
> +		goto retry;
> +
> +	if (unlikely(xa_is_zero(entry)))
> +		entry = NULL;
> +
> +	if (entry)
> +		goto unlock;
> +
> +	while (mas_searchable(&mas) && (mas.index < max)) {
> +		entry = mas_next_entry(&mas, max);
> +		if (likely(entry && !xa_is_zero(entry)))
> +			break;
> +	}
> +
> +	if (unlikely(xa_is_zero(entry)))
> +		entry = NULL;
> +unlock:
> +	rcu_read_unlock();
> +	if (likely(entry)) {
> +		*index = mas.last + 1;
> +#ifdef CONFIG_DEBUG_MAPLE_TREE
> +		if ((*index) && (*index) <= copy)
> +			printk("index not increased! %lx <= %lx\n",
> +			       *index, copy);
> +		MT_BUG_ON(mt, (*index) && ((*index) <= copy));
> +#endif
> +	}
> +
> +	return entry;
> +}
> +EXPORT_SYMBOL(mt_find);





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux