linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "NeilBrown" <neilb@suse.de>
To: "Wei Yang" <richard.weiyang@gmail.com>
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()
Date: Thu, 07 Oct 2021 11:50:22 +1100	[thread overview]
Message-ID: <163356782206.31063.3710696596883334978@noble.neil.brown.name> (raw)
In-Reply-To: <20211007003058.uj35ekwibbrxqzku@master>

On Thu, 07 Oct 2021, Wei Yang wrote:
> 
> Here is a draft patch based on you comment:
> 
> 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 *node)
>  	hlist_del_init_rcu(node);
>  }
>  
> +/**
> + * Note: the following three hash_for_each[_xxx] helpers introduce a new loop
> + * 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 == NULL' test
> + * ensures that when the inner loop is broken, the outer loop will break too.
> + */
> +
>  /**
>   * hash_for_each - iterate over a hashtable
>   * @name: hashtable to iterate
> 
> 
> If you feel good, I would like to add 
> 
> Sugguested-by: NeilBrown <neilb@suse.de>

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 <neilb@suse.de>

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 == 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) = 0, obj = NULL; obj == 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) = 0, obj = NULL; obj == 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) = 0, obj = NULL; obj == NULL && (bkt) < HASH_SIZE(name);\


  reply	other threads:[~2021-10-07  0:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 15:21 [PATCH] hashtable: remove a redundant check in hash_for_each_xxx() Wei Yang
2021-10-06 15:29 ` Greg KH
2021-10-06 21:16 ` NeilBrown
2021-10-07  0:30   ` Wei Yang
2021-10-07  0:50     ` NeilBrown [this message]
2021-10-07 23:40       ` Wei Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=163356782206.31063.3710696596883334978@noble.neil.brown.name \
    --to=neilb@suse.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=jkosina@suse.cz \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mojha@codeaurora.org \
    --cc=richard.weiyang@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).