cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <agruenba@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 2/2] gfs2: replace usage of found with dedicated list iterator variable
Date: Mon, 4 Apr 2022 16:42:03 +0200	[thread overview]
Message-ID: <CAHc6FU41FSZHGx+H1zBsBEnLo2s2fViDKJV4P-LJXg3s5xP4WA@mail.gmail.com> (raw)
In-Reply-To: <20220331223857.902911-2-jakobkoschel@gmail.com>

Jakob,

On Fri, Apr 1, 2022 at 12:40 AM Jakob Koschel <jakobkoschel@gmail.com> wrote:
> To move the list iterator variable into the list_for_each_entry_*()
> macro in the future it should be avoided to use the list iterator
> variable after the loop body.
>
> To *never* use the list iterator variable after the loop it was
> concluded to use a separate iterator variable instead of a
> found boolean [1].
>
> This removes the need to use a found variable and simply checking if
> the variable was set, can determine if the break/goto was hit.
>
> Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w at mail.gmail.com/ [1]
> Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
> ---
>  fs/gfs2/quota.c    | 13 ++++++-------
>  fs/gfs2/recovery.c | 22 ++++++++++------------
>  2 files changed, 16 insertions(+), 19 deletions(-)
>
> diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
> index be0997e24d60..dafd04fb9164 100644
> --- a/fs/gfs2/quota.c
> +++ b/fs/gfs2/quota.c
> @@ -443,7 +443,7 @@ static int qd_check_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
>
>  static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
>  {
> -       struct gfs2_quota_data *qd = NULL;
> +       struct gfs2_quota_data *qd = NULL, *iter;
>         int error;
>         int found = 0;
>
> @@ -454,15 +454,14 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
>
>         spin_lock(&qd_lock);
>
> -       list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
> -               found = qd_check_sync(sdp, qd, &sdp->sd_quota_sync_gen);
> -               if (found)
> +       list_for_each_entry(iter, &sdp->sd_quota_list, qd_list) {
> +               found = qd_check_sync(sdp, iter, &sdp->sd_quota_sync_gen);
> +               if (found) {
> +                       qd = iter;

we might as well get rid of 'found' here like in the below two
changes. Let me fix that up.

>                         break;
> +               }
>         }
>
> -       if (!found)
> -               qd = NULL;
> -
>         spin_unlock(&qd_lock);
>
>         if (qd) {
> diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c
> index 016ed1b2ca1d..2bb085a72e8e 100644
> --- a/fs/gfs2/recovery.c
> +++ b/fs/gfs2/recovery.c
> @@ -55,17 +55,16 @@ int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk,
>  int gfs2_revoke_add(struct gfs2_jdesc *jd, u64 blkno, unsigned int where)
>  {
>         struct list_head *head = &jd->jd_revoke_list;
> -       struct gfs2_revoke_replay *rr;
> -       int found = 0;
> +       struct gfs2_revoke_replay *rr = NULL, *iter;
>
> -       list_for_each_entry(rr, head, rr_list) {
> -               if (rr->rr_blkno == blkno) {
> -                       found = 1;
> +       list_for_each_entry(iter, head, rr_list) {
> +               if (iter->rr_blkno == blkno) {
> +                       rr = iter;
>                         break;
>                 }
>         }
>
> -       if (found) {
> +       if (rr) {
>                 rr->rr_where = where;
>                 return 0;
>         }
> @@ -83,18 +82,17 @@ int gfs2_revoke_add(struct gfs2_jdesc *jd, u64 blkno, unsigned int where)
>
>  int gfs2_revoke_check(struct gfs2_jdesc *jd, u64 blkno, unsigned int where)
>  {
> -       struct gfs2_revoke_replay *rr;
> +       struct gfs2_revoke_replay *rr = NULL, *iter;
>         int wrap, a, b, revoke;
> -       int found = 0;
>
> -       list_for_each_entry(rr, &jd->jd_revoke_list, rr_list) {
> -               if (rr->rr_blkno == blkno) {
> -                       found = 1;
> +       list_for_each_entry(iter, &jd->jd_revoke_list, rr_list) {
> +               if (iter->rr_blkno == blkno) {
> +                       rr = iter;
>                         break;
>                 }
>         }
>
> -       if (!found)
> +       if (!rr)
>                 return 0;
>
>         wrap = (rr->rr_where < jd->jd_replay_tail);
> --
> 2.25.1
>

Thanks,
Andreas


  reply	other threads:[~2022-04-04 14:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31 22:38 [Cluster-devel] [PATCH 1/2] gfs2: remove usage of list iterator variable for list_for_each_entry_continue() Jakob Koschel
2022-03-31 22:38 ` [Cluster-devel] [PATCH 2/2] gfs2: replace usage of found with dedicated list iterator variable Jakob Koschel
2022-04-04 14:42   ` Andreas Gruenbacher [this message]
2022-04-04 14:58 ` [Cluster-devel] [PATCH 1/2] gfs2: remove usage of list iterator variable for list_for_each_entry_continue() Andreas Gruenbacher
2022-04-08  0:09   ` Jakob Koschel

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=CAHc6FU41FSZHGx+H1zBsBEnLo2s2fViDKJV4P-LJXg3s5xP4WA@mail.gmail.com \
    --to=agruenba@redhat.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).