From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751878AbdBMGA2 (ORCPT ); Mon, 13 Feb 2017 01:00:28 -0500 Received: from LGEAMRELO11.lge.com ([156.147.23.51]:52110 "EHLO lgeamrelo11.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751638AbdBMGA1 (ORCPT ); Mon, 13 Feb 2017 01:00:27 -0500 X-Original-SENDERIP: 156.147.1.151 X-Original-MAILFROM: byungchul.park@lge.com X-Original-SENDERIP: 10.177.222.33 X-Original-MAILFROM: byungchul.park@lge.com Date: Mon, 13 Feb 2017 15:00:04 +0900 From: Byungchul Park To: Al Viro Cc: peterz@infradead.org, mingo@kernel.org, koverstreet@google.com, neilb@suse.de, nab@linux-iscsi.org, ying.huang@intel.com, oleg@redhat.com, asias@redhat.com, shli@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] llist: Don't reinvent the wheel but use existing llist API Message-ID: <20170213060004.GJ16086@X58A-UD3R> References: <1486959013-26105-1-git-send-email-byungchul.park@lge.com> <20170213054326.GR13195@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170213054326.GR13195@ZenIV.linux.org.uk> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 13, 2017 at 05:43:26AM +0000, Al Viro wrote: > On Mon, Feb 13, 2017 at 01:10:13PM +0900, Byungchul Park wrote: > > Although llist provides proper APIs, they are not used. Make them used. > > > @@ -231,12 +231,10 @@ static void __fput(struct file *file) > > static void delayed_fput(struct work_struct *unused) > > { > > struct llist_node *node = llist_del_all(&delayed_fput_list); > > - struct llist_node *next; > > + struct file *f; > > > > - for (; node; node = next) { > > - next = llist_next(node); > > - __fput(llist_entry(node, struct file, f_u.fu_llist)); > > - } > > + llist_for_each_entry(f, node, f_u.fu_llist) > > + __fput(f); > > } > > #define llist_for_each_entry(pos, node, member) \ > for ((pos) = llist_entry((node), typeof(*(pos)), member); \ > &(pos)->member != NULL; \ > (pos) = llist_entry((pos)->member.next, typeof(*(pos)), member)) > > Now, think what happens after __fput() frees the damn thing. In the > step of that loop, that is. > > That kind of pattern (find next, do something with the current, proceed to > the next we'd found before) is a strong hint that this "do something" > might remove the thing from the list, or outright destroy it. Both > file_table.c and namespace.c chunks are breaking exactly that kind of > places. > > Please, don't do this kind of conversions blindly. There _is_ another > iterating primitive for such places, but figuring out which one is right > is not something you can do without understanding what the code is doing. I'm really sorry. I made a mistake. I should have used the safe version in the case. > And no, blind replacement of all such loops with llist_for_each_entry_safe, > just in case, is not a good idea either.