Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934126AbcLTQrQ (ORCPT ); Tue, 20 Dec 2016 11:47:16 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:48303 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752203AbcLTQrO (ORCPT ); Tue, 20 Dec 2016 11:47:14 -0500 Date: Tue, 20 Dec 2016 11:47:03 -0500 From: Konrad Rzeszutek Wilk To: Geliang Tang , roger.pau@citrix.com Cc: Roger Pau =?iso-8859-1?Q?Monn=E9?= , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] xen/blkback: use rb_entry() Message-ID: <20161220164703.GL10069@char.us.oracle.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.1 (2016-10-04) X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1955 Lines: 52 On Tue, Dec 20, 2016 at 10:02:19PM +0800, Geliang Tang wrote: > To make the code clearer, use rb_entry() instead of container_of() to > deal with rbtree. That is OK but I think 'container_of' is more clear. Roger, thoughts? > > Signed-off-by: Geliang Tang > --- > drivers/block/xen-blkback/blkback.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c > index 726c32e..7e59fae 100644 > --- a/drivers/block/xen-blkback/blkback.c > +++ b/drivers/block/xen-blkback/blkback.c > @@ -191,10 +191,10 @@ static void make_response(struct xen_blkif_ring *ring, u64 id, > unsigned short op, int st); > > #define foreach_grant_safe(pos, n, rbtree, node) \ > - for ((pos) = container_of(rb_first((rbtree)), typeof(*(pos)), node), \ > + for ((pos) = rb_entry(rb_first((rbtree)), typeof(*(pos)), node), \ > (n) = (&(pos)->node != NULL) ? rb_next(&(pos)->node) : NULL; \ > &(pos)->node != NULL; \ > - (pos) = container_of(n, typeof(*(pos)), node), \ > + (pos) = rb_entry(n, typeof(*(pos)), node), \ > (n) = (&(pos)->node != NULL) ? rb_next(&(pos)->node) : NULL) > > > @@ -223,7 +223,7 @@ static int add_persistent_gnt(struct xen_blkif_ring *ring, > /* Figure out where to put new node */ > new = &ring->persistent_gnts.rb_node; > while (*new) { > - this = container_of(*new, struct persistent_gnt, node); > + this = rb_entry(*new, struct persistent_gnt, node); > > parent = *new; > if (persistent_gnt->gnt < this->gnt) > @@ -254,7 +254,7 @@ static struct persistent_gnt *get_persistent_gnt(struct xen_blkif_ring *ring, > > node = ring->persistent_gnts.rb_node; > while (node) { > - data = container_of(node, struct persistent_gnt, node); > + data = rb_entry(node, struct persistent_gnt, node); > > if (gref < data->gnt) > node = node->rb_left; > -- > 2.9.3 >