Skip to content

Commit b846f2d

Browse files
Jakob-KoschelAndreas Gruenbacher
authored andcommitted
gfs2: replace 'found' with dedicated list iterator variable
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@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel <[email protected]> Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent d928e8f commit b846f2d

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

fs/gfs2/quota.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,8 @@ static int qd_check_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
443443

444444
static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
445445
{
446-
struct gfs2_quota_data *qd = NULL;
446+
struct gfs2_quota_data *qd = NULL, *iter;
447447
int error;
448-
int found = 0;
449448

450449
*qdp = NULL;
451450

@@ -454,15 +453,13 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
454453

455454
spin_lock(&qd_lock);
456455

457-
list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
458-
found = qd_check_sync(sdp, qd, &sdp->sd_quota_sync_gen);
459-
if (found)
456+
list_for_each_entry(iter, &sdp->sd_quota_list, qd_list) {
457+
if (qd_check_sync(sdp, iter, &sdp->sd_quota_sync_gen)) {
458+
qd = iter;
460459
break;
460+
}
461461
}
462462

463-
if (!found)
464-
qd = NULL;
465-
466463
spin_unlock(&qd_lock);
467464

468465
if (qd) {

fs/gfs2/recovery.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,16 @@ int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk,
5555
int gfs2_revoke_add(struct gfs2_jdesc *jd, u64 blkno, unsigned int where)
5656
{
5757
struct list_head *head = &jd->jd_revoke_list;
58-
struct gfs2_revoke_replay *rr;
59-
int found = 0;
58+
struct gfs2_revoke_replay *rr = NULL, *iter;
6059

61-
list_for_each_entry(rr, head, rr_list) {
62-
if (rr->rr_blkno == blkno) {
63-
found = 1;
60+
list_for_each_entry(iter, head, rr_list) {
61+
if (iter->rr_blkno == blkno) {
62+
rr = iter;
6463
break;
6564
}
6665
}
6766

68-
if (found) {
67+
if (rr) {
6968
rr->rr_where = where;
7069
return 0;
7170
}
@@ -83,18 +82,17 @@ int gfs2_revoke_add(struct gfs2_jdesc *jd, u64 blkno, unsigned int where)
8382

8483
int gfs2_revoke_check(struct gfs2_jdesc *jd, u64 blkno, unsigned int where)
8584
{
86-
struct gfs2_revoke_replay *rr;
85+
struct gfs2_revoke_replay *rr = NULL, *iter;
8786
int wrap, a, b, revoke;
88-
int found = 0;
8987

90-
list_for_each_entry(rr, &jd->jd_revoke_list, rr_list) {
91-
if (rr->rr_blkno == blkno) {
92-
found = 1;
88+
list_for_each_entry(iter, &jd->jd_revoke_list, rr_list) {
89+
if (iter->rr_blkno == blkno) {
90+
rr = iter;
9391
break;
9492
}
9593
}
9694

97-
if (!found)
95+
if (!rr)
9896
return 0;
9997

10098
wrap = (rr->rr_where < jd->jd_replay_tail);

0 commit comments

Comments
 (0)