Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S943301AbcJ0PO2 (ORCPT ); Thu, 27 Oct 2016 11:14:28 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:58864 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935350AbcJ0PO0 (ORCPT ); Thu, 27 Oct 2016 11:14:26 -0400 Date: Thu, 27 Oct 2016 17:14:20 +0200 From: Peter Zijlstra To: David Herrmann Cc: linux-kernel@vger.kernel.org, Andy Lutomirski , Jiri Kosina , Greg KH , Hannes Reinecke , Steven Rostedt , Arnd Bergmann , Tom Gundersen , Josh Triplett , Linus Torvalds , Andrew Morton Subject: Re: [RFC v1 05/14] bus1: util - pool utility library Message-ID: <20161027151420.GG3175@twins.programming.kicks-ass.net> References: <20161026191810.12275-1-dh.herrmann@gmail.com> <20161026191810.12275-6-dh.herrmann@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161026191810.12275-6-dh.herrmann@gmail.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2065 Lines: 82 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); > +}