Skip to content

Commit dc1acd5

Browse files
Jakob-Koschelteigland
authored andcommitted
dlm: replace usage of 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: Alexander Aring <[email protected]> Signed-off-by: David Teigland <[email protected]>
1 parent c490b3a commit dc1acd5

File tree

3 files changed

+56
-60
lines changed

3 files changed

+56
-60
lines changed

fs/dlm/lock.c

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@ static void del_timeout(struct dlm_lkb *lkb)
18851885
void dlm_scan_timeout(struct dlm_ls *ls)
18861886
{
18871887
struct dlm_rsb *r;
1888-
struct dlm_lkb *lkb;
1888+
struct dlm_lkb *lkb = NULL, *iter;
18891889
int do_cancel, do_warn;
18901890
s64 wait_us;
18911891

@@ -1896,27 +1896,28 @@ void dlm_scan_timeout(struct dlm_ls *ls)
18961896
do_cancel = 0;
18971897
do_warn = 0;
18981898
mutex_lock(&ls->ls_timeout_mutex);
1899-
list_for_each_entry(lkb, &ls->ls_timeout, lkb_time_list) {
1899+
list_for_each_entry(iter, &ls->ls_timeout, lkb_time_list) {
19001900

19011901
wait_us = ktime_to_us(ktime_sub(ktime_get(),
1902-
lkb->lkb_timestamp));
1902+
iter->lkb_timestamp));
19031903

1904-
if ((lkb->lkb_exflags & DLM_LKF_TIMEOUT) &&
1905-
wait_us >= (lkb->lkb_timeout_cs * 10000))
1904+
if ((iter->lkb_exflags & DLM_LKF_TIMEOUT) &&
1905+
wait_us >= (iter->lkb_timeout_cs * 10000))
19061906
do_cancel = 1;
19071907

1908-
if ((lkb->lkb_flags & DLM_IFL_WATCH_TIMEWARN) &&
1908+
if ((iter->lkb_flags & DLM_IFL_WATCH_TIMEWARN) &&
19091909
wait_us >= dlm_config.ci_timewarn_cs * 10000)
19101910
do_warn = 1;
19111911

19121912
if (!do_cancel && !do_warn)
19131913
continue;
1914-
hold_lkb(lkb);
1914+
hold_lkb(iter);
1915+
lkb = iter;
19151916
break;
19161917
}
19171918
mutex_unlock(&ls->ls_timeout_mutex);
19181919

1919-
if (!do_cancel && !do_warn)
1920+
if (!lkb)
19201921
break;
19211922

19221923
r = lkb->lkb_resource;
@@ -5292,21 +5293,18 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls)
52925293

52935294
static struct dlm_lkb *find_resend_waiter(struct dlm_ls *ls)
52945295
{
5295-
struct dlm_lkb *lkb;
5296-
int found = 0;
5296+
struct dlm_lkb *lkb = NULL, *iter;
52975297

52985298
mutex_lock(&ls->ls_waiters_mutex);
5299-
list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) {
5300-
if (lkb->lkb_flags & DLM_IFL_RESEND) {
5301-
hold_lkb(lkb);
5302-
found = 1;
5299+
list_for_each_entry(iter, &ls->ls_waiters, lkb_wait_reply) {
5300+
if (iter->lkb_flags & DLM_IFL_RESEND) {
5301+
hold_lkb(iter);
5302+
lkb = iter;
53035303
break;
53045304
}
53055305
}
53065306
mutex_unlock(&ls->ls_waiters_mutex);
53075307

5308-
if (!found)
5309-
lkb = NULL;
53105308
return lkb;
53115309
}
53125310

@@ -5964,37 +5962,36 @@ int dlm_user_adopt_orphan(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
59645962
int mode, uint32_t flags, void *name, unsigned int namelen,
59655963
unsigned long timeout_cs, uint32_t *lkid)
59665964
{
5967-
struct dlm_lkb *lkb;
5965+
struct dlm_lkb *lkb = NULL, *iter;
59685966
struct dlm_user_args *ua;
59695967
int found_other_mode = 0;
5970-
int found = 0;
59715968
int rv = 0;
59725969

59735970
mutex_lock(&ls->ls_orphans_mutex);
5974-
list_for_each_entry(lkb, &ls->ls_orphans, lkb_ownqueue) {
5975-
if (lkb->lkb_resource->res_length != namelen)
5971+
list_for_each_entry(iter, &ls->ls_orphans, lkb_ownqueue) {
5972+
if (iter->lkb_resource->res_length != namelen)
59765973
continue;
5977-
if (memcmp(lkb->lkb_resource->res_name, name, namelen))
5974+
if (memcmp(iter->lkb_resource->res_name, name, namelen))
59785975
continue;
5979-
if (lkb->lkb_grmode != mode) {
5976+
if (iter->lkb_grmode != mode) {
59805977
found_other_mode = 1;
59815978
continue;
59825979
}
59835980

5984-
found = 1;
5985-
list_del_init(&lkb->lkb_ownqueue);
5986-
lkb->lkb_flags &= ~DLM_IFL_ORPHAN;
5987-
*lkid = lkb->lkb_id;
5981+
lkb = iter;
5982+
list_del_init(&iter->lkb_ownqueue);
5983+
iter->lkb_flags &= ~DLM_IFL_ORPHAN;
5984+
*lkid = iter->lkb_id;
59885985
break;
59895986
}
59905987
mutex_unlock(&ls->ls_orphans_mutex);
59915988

5992-
if (!found && found_other_mode) {
5989+
if (!lkb && found_other_mode) {
59935990
rv = -EAGAIN;
59945991
goto out;
59955992
}
59965993

5997-
if (!found) {
5994+
if (!lkb) {
59985995
rv = -ENOENT;
59995996
goto out;
60005997
}

fs/dlm/plock.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ static ssize_t dev_read(struct file *file, char __user *u, size_t count,
407407
static ssize_t dev_write(struct file *file, const char __user *u, size_t count,
408408
loff_t *ppos)
409409
{
410+
struct plock_op *op = NULL, *iter;
410411
struct dlm_plock_info info;
411-
struct plock_op *op;
412-
int found = 0, do_callback = 0;
412+
int do_callback = 0;
413413

414414
if (count != sizeof(info))
415415
return -EINVAL;
@@ -421,23 +421,23 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count,
421421
return -EINVAL;
422422

423423
spin_lock(&ops_lock);
424-
list_for_each_entry(op, &recv_list, list) {
425-
if (op->info.fsid == info.fsid &&
426-
op->info.number == info.number &&
427-
op->info.owner == info.owner) {
428-
list_del_init(&op->list);
429-
memcpy(&op->info, &info, sizeof(info));
430-
if (op->data)
424+
list_for_each_entry(iter, &recv_list, list) {
425+
if (iter->info.fsid == info.fsid &&
426+
iter->info.number == info.number &&
427+
iter->info.owner == info.owner) {
428+
list_del_init(&iter->list);
429+
memcpy(&iter->info, &info, sizeof(info));
430+
if (iter->data)
431431
do_callback = 1;
432432
else
433-
op->done = 1;
434-
found = 1;
433+
iter->done = 1;
434+
op = iter;
435435
break;
436436
}
437437
}
438438
spin_unlock(&ops_lock);
439439

440-
if (found) {
440+
if (op) {
441441
if (do_callback)
442442
dlm_plock_callback(op);
443443
else

fs/dlm/recover.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,9 @@ void dlm_recovered_lock(struct dlm_rsb *r)
732732

733733
static void recover_lvb(struct dlm_rsb *r)
734734
{
735-
struct dlm_lkb *lkb, *high_lkb = NULL;
735+
struct dlm_lkb *big_lkb = NULL, *iter, *high_lkb = NULL;
736736
uint32_t high_seq = 0;
737737
int lock_lvb_exists = 0;
738-
int big_lock_exists = 0;
739738
int lvblen = r->res_ls->ls_lvblen;
740739

741740
if (!rsb_flag(r, RSB_NEW_MASTER2) &&
@@ -751,37 +750,37 @@ static void recover_lvb(struct dlm_rsb *r)
751750
/* we are the new master, so figure out if VALNOTVALID should
752751
be set, and set the rsb lvb from the best lkb available. */
753752

754-
list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
755-
if (!(lkb->lkb_exflags & DLM_LKF_VALBLK))
753+
list_for_each_entry(iter, &r->res_grantqueue, lkb_statequeue) {
754+
if (!(iter->lkb_exflags & DLM_LKF_VALBLK))
756755
continue;
757756

758757
lock_lvb_exists = 1;
759758

760-
if (lkb->lkb_grmode > DLM_LOCK_CR) {
761-
big_lock_exists = 1;
759+
if (iter->lkb_grmode > DLM_LOCK_CR) {
760+
big_lkb = iter;
762761
goto setflag;
763762
}
764763

765-
if (((int)lkb->lkb_lvbseq - (int)high_seq) >= 0) {
766-
high_lkb = lkb;
767-
high_seq = lkb->lkb_lvbseq;
764+
if (((int)iter->lkb_lvbseq - (int)high_seq) >= 0) {
765+
high_lkb = iter;
766+
high_seq = iter->lkb_lvbseq;
768767
}
769768
}
770769

771-
list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
772-
if (!(lkb->lkb_exflags & DLM_LKF_VALBLK))
770+
list_for_each_entry(iter, &r->res_convertqueue, lkb_statequeue) {
771+
if (!(iter->lkb_exflags & DLM_LKF_VALBLK))
773772
continue;
774773

775774
lock_lvb_exists = 1;
776775

777-
if (lkb->lkb_grmode > DLM_LOCK_CR) {
778-
big_lock_exists = 1;
776+
if (iter->lkb_grmode > DLM_LOCK_CR) {
777+
big_lkb = iter;
779778
goto setflag;
780779
}
781780

782-
if (((int)lkb->lkb_lvbseq - (int)high_seq) >= 0) {
783-
high_lkb = lkb;
784-
high_seq = lkb->lkb_lvbseq;
781+
if (((int)iter->lkb_lvbseq - (int)high_seq) >= 0) {
782+
high_lkb = iter;
783+
high_seq = iter->lkb_lvbseq;
785784
}
786785
}
787786

@@ -790,7 +789,7 @@ static void recover_lvb(struct dlm_rsb *r)
790789
goto out;
791790

792791
/* lvb is invalidated if only NL/CR locks remain */
793-
if (!big_lock_exists)
792+
if (!big_lkb)
794793
rsb_set_flag(r, RSB_VALNOTVALID);
795794

796795
if (!r->res_lvbptr) {
@@ -799,9 +798,9 @@ static void recover_lvb(struct dlm_rsb *r)
799798
goto out;
800799
}
801800

802-
if (big_lock_exists) {
803-
r->res_lvbseq = lkb->lkb_lvbseq;
804-
memcpy(r->res_lvbptr, lkb->lkb_lvbptr, lvblen);
801+
if (big_lkb) {
802+
r->res_lvbseq = big_lkb->lkb_lvbseq;
803+
memcpy(r->res_lvbptr, big_lkb->lkb_lvbptr, lvblen);
805804
} else if (high_lkb) {
806805
r->res_lvbseq = high_lkb->lkb_lvbseq;
807806
memcpy(r->res_lvbptr, high_lkb->lkb_lvbptr, lvblen);

0 commit comments

Comments
 (0)