From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752847AbbJFR0O (ORCPT ); Tue, 6 Oct 2015 13:26:14 -0400 Received: from mail-ig0-f171.google.com ([209.85.213.171]:33800 "EHLO mail-ig0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752347AbbJFR0N (ORCPT ); Tue, 6 Oct 2015 13:26:13 -0400 Date: Tue, 6 Oct 2015 13:25:55 -0400 From: Tejun Heo To: Cody P Schafer Cc: Andrew Morton , John de la Garza , Michel Lespinasse , Peter Zijlstra , Rusty Russell , linux-kernel@vger.kernel.org Subject: Re: [PATCH] rbtree: clarify documentation of rbtree_postorder_for_each_entry_safe() Message-ID: <20151006172555.GA3931@mtj.duckdns.org> References: <1443997973-1700-1-git-send-email-dev@codyps.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1443997973-1700-1-git-send-email-dev@codyps.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Sun, Oct 04, 2015 at 06:32:50PM -0400, Cody P Schafer wrote: > Doing this will cause random nodes to be missed by the iteration because > rb_erase() may rebalance the tree, changing the ordering that we're > trying to iterate over. > > The previous documentation for rbtree_postorder_for_each_entry_safe() > wasn't clear that this wasn't allowed, it was taken from the docs for > list_for_each_entry_safe(), where erasing isn't a problem due to > list_del() not reordering. Ugh... that's a misleading name for an iterator if it doesn't allow removal of elements during iteration. > Explicitly warn developers about this potential pit-fall. > > Note that I haven't fixed the actual issue that (it appears) the commit > referenced above introduced (not familiar enough with that code). > > In general (and in this case), the patterns to follow are: > - switch to rb_first() + rb_erase(), don't use > rbtree_postorder_for_each_entry_safe(). I'll update it to a while loop on rb_first(). Thanks. -- tejun