Messages in this thread | | | Date | Thu, 27 Oct 2016 17:14:20 +0200 | From | Peter Zijlstra <> | Subject | Re: [RFC v1 05/14] bus1: util - pool utility library |
| |
On Wed, Oct 26, 2016 at 09:18:01PM +0200, David Herrmann wrote:
All small nits..
> +void bus1_pool_deinit(struct bus1_pool *pool) > +{ > + struct bus1_pool_slice *slice; > + > + if (!pool || !pool->f) > + return; > + > + while ((slice = list_first_entry_or_null(&pool->slices, > + struct bus1_pool_slice, > + entry))) { > + WARN_ON(slice->ref_kernel); > + list_del(&slice->entry); > + bus1_pool_slice_free(slice); > + }
I prefer to write that loop like:
while (!list_empty(&pool->slices)) { slice = list_first_entry(&pool->slices, struct bus1_pool_slice, entry); list_del(&slice->entry);
// ... }
> +static void bus1_pool_free(struct bus1_pool *pool, > + struct bus1_pool_slice *slice) > +{ > + struct bus1_pool_slice *ps; > + > + /* don't free the slice if either has a reference */ > + if (slice->ref_kernel || slice->ref_user || WARN_ON(slice->free)) > + return; > + > + /* > + * To release a pool-slice, we first drop it from the busy-tree, then > + * merge it with possible previous/following free slices and re-add it > + * to the free-tree. > + */ > + > + rb_erase(&slice->rb, &pool->slices_busy); > + > + if (!WARN_ON(slice->size > pool->allocated_size)) > + pool->allocated_size -= slice->size; > + > + if (pool->slices.next != &slice->entry) { > + ps = container_of(slice->entry.prev, struct bus1_pool_slice, > + entry);
ps = list_prev_entry(slice, entry);
> + if (ps->free) { > + rb_erase(&ps->rb, &pool->slices_free); > + list_del(&slice->entry); > + ps->size += slice->size; > + bus1_pool_slice_free(slice); > + slice = ps; /* switch to previous slice */ > + } > + } > + > + if (pool->slices.prev != &slice->entry) { > + ps = container_of(slice->entry.next, struct bus1_pool_slice, > + entry);
ps = list_next_entry(slice, entry);
> + if (ps->free) { > + rb_erase(&ps->rb, &pool->slices_free); > + list_del(&ps->entry); > + slice->size += ps->size; > + bus1_pool_slice_free(ps); > + } > + } > + > + slice->free = true; > + bus1_pool_slice_link_free(slice, pool); > +}
| |