Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp875304pxb; Wed, 6 Oct 2021 17:52:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiOs0505e4zj4g723LR53GUANmkDZY73ngZ65yOuDSAFy8JcP5ZQp74+H/brFUQZ7qqTT3 X-Received: by 2002:a50:da04:: with SMTP id z4mr2071445edj.52.1633567966595; Wed, 06 Oct 2021 17:52:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633567966; cv=none; d=google.com; s=arc-20160816; b=u2sQD5kwW4FPlu8R6FQ0yjy8pvzp2mGTUSFTkX2zgYQ0znkjRKtl5NlrwI38S3pBdD xwkOEojCaPv0MRCW5/KFfRw3/u4ZcWfNTw14O5t4860VP7KVwIgZpea0DLq3+UxqWFYO D5f3WyNQ7T2ziCoaamjsukwBR/amdie4R9GQQja7xoIAfh1rl0QFiZHdoE2RfqF5uhXg vEEI7Wia/KWnYp0EVoTG1VElM3beGgX3SpPE1Len6tFZRyfGlC75pwsXjssZIWzalA2F fcYZQr3kec/K+NbcC+/Afrn5sjNjbthiIc3dTMUt6uBm9LIz9ZdS0Um7TDDtfvAPGB/s 54QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:references:in-reply-to:subject :cc:to:from:mime-version:content-transfer-encoding:dkim-signature :dkim-signature; bh=FkN4LgNhKj4PxuOMK7Hfo8inuz6SvPxGt6pScV3hnp4=; b=0svUEmsdEXHbyB4UoK9l7qneP1mJCkgyrBjHbQ9PEIDrdYJEt4m47hMLgFv91tX8C8 Ybhe794UQJ+0nGgnExdL8zcj2CpaQhzdoZuC2lyhKycI1S5wJWAfhsMmB+JjwRBKIF1m J3GrGOrlbBBK/PtKlM1zmuJd2iAtL10kTyr3ZZMORUjj+SIgRiZCnrO5aucRr3rDwG/g fQg75P6Md+lNI07vM6qiDBrK4UrtC0MfeaaKm7e7t95fIPTODj6xYlE//mqm7M4fQ0rm rZQaH7OwGhOz53nDUIhtshqRkc2bLtpwjR5UrWsj1dAiVQJik7BuZYK062dh0mrmnPhj N+nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=LXfORfH9; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=IDgCl56V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z11si3841654edc.556.2021.10.06.17.52.22; Wed, 06 Oct 2021 17:52:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=LXfORfH9; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=IDgCl56V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240078AbhJGAwV (ORCPT + 99 others); Wed, 6 Oct 2021 20:52:21 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:38584 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234538AbhJGAwU (ORCPT ); Wed, 6 Oct 2021 20:52:20 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BC4A822595; Thu, 7 Oct 2021 00:50:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1633567826; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FkN4LgNhKj4PxuOMK7Hfo8inuz6SvPxGt6pScV3hnp4=; b=LXfORfH9wk5KIW+5fKfUkcT3af9vJ8rm2QMKXIy58BXB9UoeCcbfOX1fe16DI4ePLkL5i1 4XICBaDBqqzX7LrSAJoWg1iYXmL3J+AShuZCkFtq86Dy4nJk8VvkW7Qwzz3seYey0JutzC XLJsWpXnVSxMkNy4QqiKlJfeKyfqmeo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1633567826; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FkN4LgNhKj4PxuOMK7Hfo8inuz6SvPxGt6pScV3hnp4=; b=IDgCl56VFg5B6d1bpOw01J6TMqXakyoJC4bz4c84eCcZw/qU6tuthfuBkIhbxn6CQH6zJA 4fl/2izlRwIvGTBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E368513A66; Thu, 7 Oct 2021 00:50:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id TEIkKFBEXmGnAwAAMHmgww (envelope-from ); Thu, 07 Oct 2021 00:50:24 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: "NeilBrown" To: "Wei Yang" Cc: kuba@kernel.org, gregkh@linuxfoundation.org, mojha@codeaurora.org, jkosina@suse.cz, linux-kernel@vger.kernel.org Subject: Re: [PATCH] hashtable: remove a redundant check in hash_for_each_xxx() In-reply-to: <20211007003058.uj35ekwibbrxqzku@master> References: <20211006152100.17795-1-richard.weiyang@gmail.com>, <163355497171.31063.8329134032738647570@noble.neil.brown.name>, <20211007003058.uj35ekwibbrxqzku@master> Date: Thu, 07 Oct 2021 11:50:22 +1100 Message-id: <163356782206.31063.3710696596883334978@noble.neil.brown.name> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 07 Oct 2021, Wei Yang wrote: >=20 > Here is a draft patch based on you comment: >=20 > diff --git a/include/linux/hashtable.h b/include/linux/hashtable.h > index f6c666730b8c..2ff4cb5e6a22 100644 > --- a/include/linux/hashtable.h > +++ b/include/linux/hashtable.h > @@ -116,6 +116,13 @@ static inline void hash_del_rcu(struct hlist_node *nod= e) > hlist_del_init_rcu(node); > } > =20 > +/** > + * Note: the following three hash_for_each[_xxx] helpers introduce a new l= oop > + * command that is constructed from 2 nested loops. It is safe to 'break' = out > + * of this loop even though it is a two nested loops. The 'obj =3D=3D NUL= L' test > + * ensures that when the inner loop is broken, the outer loop will break t= oo. > + */ > + > /** > * hash_for_each - iterate over a hashtable > * @name: hashtable to iterate >=20 >=20 > If you feel good, I would like to add=20 >=20 > Sugguested-by: NeilBrown That's definitely an improvement. I'd probably put it in the kernel-doc comment for hash_for_each, then in the other two just put the "it is safe" bit. Something like the following. But I don't feel strongly about it. I'm happy to say Reviewed-by: NeilBrown for your patch. Thanks, NeilBrown diff --git a/include/linux/hashtable.h b/include/linux/hashtable.h index f6c666730b8c..61db940c9501 100644 --- a/include/linux/hashtable.h +++ b/include/linux/hashtable.h @@ -122,6 +122,10 @@ static inline void hash_del_rcu(struct hlist_node *node) * @bkt: integer to use as bucket loop cursor * @obj: the type * to use as a loop cursor for each entry * @member: the name of the hlist_node within the struct + * + * Note: It is safe to 'break' out of this loop even though it is a two + * nested loops. The 'obj =3D=3D NULL' test ensures that when the inner loop + * is broken, the outer loop will break too. */ #define hash_for_each(name, bkt, obj, member) \ for ((bkt) =3D 0, obj =3D NULL; obj =3D=3D NULL && (bkt) < HASH_SIZE(name);\ @@ -134,6 +138,8 @@ static inline void hash_del_rcu(struct hlist_node *node) * @bkt: integer to use as bucket loop cursor * @obj: the type * to use as a loop cursor for each entry * @member: the name of the hlist_node within the struct + * + * It is safe to 'break' out of this loop. */ #define hash_for_each_rcu(name, bkt, obj, member) \ for ((bkt) =3D 0, obj =3D NULL; obj =3D=3D NULL && (bkt) < HASH_SIZE(name);\ @@ -148,6 +154,8 @@ static inline void hash_del_rcu(struct hlist_node *node) * @tmp: a &struct hlist_node used for temporary storage * @obj: the type * to use as a loop cursor for each entry * @member: the name of the hlist_node within the struct + * + * It is safe to 'break' out of this loop. */ #define hash_for_each_safe(name, bkt, tmp, obj, member) \ for ((bkt) =3D 0, obj =3D NULL; obj =3D=3D NULL && (bkt) < HASH_SIZE(name);\