lkml.org 
[lkml]   [2021]   [Dec]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v4 05/66] Maple Tree: Add new data structure
Date
* Vlastimil Babka <vbabka@suse.cz> [211215 07:54]:
> 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.

Good point. I will add to the comment what happens to *index.

>
> > + */
> > +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);
>
\
 
 \ /
  Last update: 2021-12-15 18:53    [W:0.202 / U:0.380 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site