Skip to content

Commit 9543c8a

Browse files
ematsumiyaSteve French
authored andcommitted
cifs: list_for_each() -> list_for_each_entry()
Replace list_for_each() by list_for_each_entr() where appropriate. Remove no longer used list_head stack variables. Signed-off-by: Enzo Matsumiya <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent ec88cc5 commit 9543c8a

File tree

5 files changed

+22
-67
lines changed

5 files changed

+22
-67
lines changed

fs/cifs/cifs_debug.c

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
168168

169169
static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
170170
{
171-
struct list_head *tmp, *tmp1, *tmp2;
172171
struct TCP_Server_Info *server;
173172
struct cifs_ses *ses;
174173
struct cifs_tcon *tcon;
@@ -184,14 +183,10 @@ static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
184183
#endif /* CIFS_DEBUG2 */
185184
spin_lock(&cifs_tcp_ses_lock);
186185
list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
187-
list_for_each(tmp, &server->smb_ses_list) {
188-
ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
189-
list_for_each(tmp1, &ses->tcon_list) {
190-
tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
186+
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
187+
list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
191188
spin_lock(&tcon->open_file_lock);
192-
list_for_each(tmp2, &tcon->openFileList) {
193-
cfile = list_entry(tmp2, struct cifsFileInfo,
194-
tlist);
189+
list_for_each_entry(cfile, &tcon->openFileList, tlist) {
195190
seq_printf(m,
196191
"0x%x 0x%llx 0x%x %d %d %d %pd",
197192
tcon->tid,
@@ -218,7 +213,6 @@ static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
218213

219214
static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
220215
{
221-
struct list_head *tmp2, *tmp3;
222216
struct mid_q_entry *mid_entry;
223217
struct TCP_Server_Info *server;
224218
struct cifs_ses *ses;
@@ -381,9 +375,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
381375

382376
seq_printf(m, "\n\n\tSessions: ");
383377
i = 0;
384-
list_for_each(tmp2, &server->smb_ses_list) {
385-
ses = list_entry(tmp2, struct cifs_ses,
386-
smb_ses_list);
378+
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
387379
i++;
388380
if ((ses->serverDomain == NULL) ||
389381
(ses->serverOS == NULL) ||
@@ -447,9 +439,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
447439
else
448440
seq_puts(m, "none\n");
449441

450-
list_for_each(tmp3, &ses->tcon_list) {
451-
tcon = list_entry(tmp3, struct cifs_tcon,
452-
tcon_list);
442+
list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
453443
++j;
454444
seq_printf(m, "\n\t%d) ", j);
455445
cifs_debug_tcon(m, tcon);
@@ -474,9 +464,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
474464

475465
seq_puts(m, "\n\n\tMIDs: ");
476466
spin_lock(&GlobalMid_Lock);
477-
list_for_each(tmp3, &server->pending_mid_q) {
478-
mid_entry = list_entry(tmp3, struct mid_q_entry,
479-
qhead);
467+
list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
480468
seq_printf(m, "\n\tState: %d com: %d pid:"
481469
" %d cbdata: %p mid %llu\n",
482470
mid_entry->mid_state,
@@ -504,7 +492,6 @@ static ssize_t cifs_stats_proc_write(struct file *file,
504492
{
505493
bool bv;
506494
int rc;
507-
struct list_head *tmp1, *tmp2, *tmp3;
508495
struct TCP_Server_Info *server;
509496
struct cifs_ses *ses;
510497
struct cifs_tcon *tcon;
@@ -525,9 +512,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
525512
GlobalCurrentXid = 0;
526513
spin_unlock(&GlobalMid_Lock);
527514
spin_lock(&cifs_tcp_ses_lock);
528-
list_for_each(tmp1, &cifs_tcp_ses_list) {
529-
server = list_entry(tmp1, struct TCP_Server_Info,
530-
tcp_ses_list);
515+
list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
531516
server->max_in_flight = 0;
532517
#ifdef CONFIG_CIFS_STATS2
533518
for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
@@ -538,13 +523,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
538523
server->fastest_cmd[0] = 0;
539524
}
540525
#endif /* CONFIG_CIFS_STATS2 */
541-
list_for_each(tmp2, &server->smb_ses_list) {
542-
ses = list_entry(tmp2, struct cifs_ses,
543-
smb_ses_list);
544-
list_for_each(tmp3, &ses->tcon_list) {
545-
tcon = list_entry(tmp3,
546-
struct cifs_tcon,
547-
tcon_list);
526+
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
527+
list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
548528
atomic_set(&tcon->num_smbs_sent, 0);
549529
spin_lock(&tcon->stat_lock);
550530
tcon->bytes_read = 0;
@@ -569,7 +549,6 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
569549
#ifdef CONFIG_CIFS_STATS2
570550
int j;
571551
#endif /* STATS2 */
572-
struct list_head *tmp2, *tmp3;
573552
struct TCP_Server_Info *server;
574553
struct cifs_ses *ses;
575554
struct cifs_tcon *tcon;
@@ -619,13 +598,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
619598
atomic_read(&server->smb2slowcmd[j]),
620599
server->hostname, j);
621600
#endif /* STATS2 */
622-
list_for_each(tmp2, &server->smb_ses_list) {
623-
ses = list_entry(tmp2, struct cifs_ses,
624-
smb_ses_list);
625-
list_for_each(tmp3, &ses->tcon_list) {
626-
tcon = list_entry(tmp3,
627-
struct cifs_tcon,
628-
tcon_list);
601+
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
602+
list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
629603
i++;
630604
seq_printf(m, "\n%d) %s", i, tcon->treeName);
631605
if (tcon->need_reconnect)

fs/cifs/connect.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,10 @@ static int match_tcon(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
22572257
static struct cifs_tcon *
22582258
cifs_find_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
22592259
{
2260-
struct list_head *tmp;
22612260
struct cifs_tcon *tcon;
22622261

22632262
spin_lock(&cifs_tcp_ses_lock);
2264-
list_for_each(tmp, &ses->tcon_list) {
2265-
tcon = list_entry(tmp, struct cifs_tcon, tcon_list);
2266-
2263+
list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
22672264
if (!match_tcon(tcon, ctx))
22682265
continue;
22692266
++tcon->tc_count;

fs/cifs/file.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -928,9 +928,7 @@ int cifs_close(struct inode *inode, struct file *file)
928928
void
929929
cifs_reopen_persistent_handles(struct cifs_tcon *tcon)
930930
{
931-
struct cifsFileInfo *open_file;
932-
struct list_head *tmp;
933-
struct list_head *tmp1;
931+
struct cifsFileInfo *open_file, *tmp;
934932
struct list_head tmp_list;
935933

936934
if (!tcon->use_persistent || !tcon->need_reopen_files)
@@ -943,17 +941,15 @@ cifs_reopen_persistent_handles(struct cifs_tcon *tcon)
943941

944942
/* list all files open on tree connection, reopen resilient handles */
945943
spin_lock(&tcon->open_file_lock);
946-
list_for_each(tmp, &tcon->openFileList) {
947-
open_file = list_entry(tmp, struct cifsFileInfo, tlist);
944+
list_for_each_entry(open_file, &tcon->openFileList, tlist) {
948945
if (!open_file->invalidHandle)
949946
continue;
950947
cifsFileInfo_get(open_file);
951948
list_add_tail(&open_file->rlist, &tmp_list);
952949
}
953950
spin_unlock(&tcon->open_file_lock);
954951

955-
list_for_each_safe(tmp, tmp1, &tmp_list) {
956-
open_file = list_entry(tmp, struct cifsFileInfo, rlist);
952+
list_for_each_entry_safe(open_file, tmp, &tmp_list, rlist) {
957953
if (cifs_reopen_file(open_file, false /* do not flush */))
958954
tcon->need_reopen_files = true;
959955
list_del_init(&open_file->rlist);

fs/cifs/misc.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)
400400
{
401401
struct smb_hdr *buf = (struct smb_hdr *)buffer;
402402
struct smb_com_lock_req *pSMB = (struct smb_com_lock_req *)buf;
403-
struct list_head *tmp, *tmp1, *tmp2;
404403
struct cifs_ses *ses;
405404
struct cifs_tcon *tcon;
406405
struct cifsInodeInfo *pCifsInode;
@@ -467,18 +466,14 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)
467466

468467
/* look up tcon based on tid & uid */
469468
spin_lock(&cifs_tcp_ses_lock);
470-
list_for_each(tmp, &srv->smb_ses_list) {
471-
ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
472-
list_for_each(tmp1, &ses->tcon_list) {
473-
tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
469+
list_for_each_entry(ses, &srv->smb_ses_list, smb_ses_list) {
470+
list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
474471
if (tcon->tid != buf->Tid)
475472
continue;
476473

477474
cifs_stats_inc(&tcon->stats.cifs_stats.num_oplock_brks);
478475
spin_lock(&tcon->open_file_lock);
479-
list_for_each(tmp2, &tcon->openFileList) {
480-
netfile = list_entry(tmp2, struct cifsFileInfo,
481-
tlist);
476+
list_for_each_entry(netfile, &tcon->openFileList, tlist) {
482477
if (pSMB->Fid != netfile->fid.netfid)
483478
continue;
484479

@@ -763,14 +758,12 @@ void
763758
cifs_close_all_deferred_files(struct cifs_tcon *tcon)
764759
{
765760
struct cifsFileInfo *cfile;
766-
struct list_head *tmp;
767761
struct file_list *tmp_list, *tmp_next_list;
768762
struct list_head file_head;
769763

770764
INIT_LIST_HEAD(&file_head);
771765
spin_lock(&tcon->open_file_lock);
772-
list_for_each(tmp, &tcon->openFileList) {
773-
cfile = list_entry(tmp, struct cifsFileInfo, tlist);
766+
list_for_each_entry(cfile, &tcon->openFileList, tlist) {
774767
if (delayed_work_pending(&cfile->deferred)) {
775768
if (cancel_delayed_work(&cfile->deferred)) {
776769
tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
@@ -793,7 +786,6 @@ void
793786
cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
794787
{
795788
struct cifsFileInfo *cfile;
796-
struct list_head *tmp;
797789
struct file_list *tmp_list, *tmp_next_list;
798790
struct list_head file_head;
799791
void *page;
@@ -802,8 +794,7 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
802794
INIT_LIST_HEAD(&file_head);
803795
page = alloc_dentry_path();
804796
spin_lock(&tcon->open_file_lock);
805-
list_for_each(tmp, &tcon->openFileList) {
806-
cfile = list_entry(tmp, struct cifsFileInfo, tlist);
797+
list_for_each_entry(cfile, &tcon->openFileList, tlist) {
807798
full_path = build_path_from_dentry(cfile->dentry, page);
808799
if (strstr(full_path, path)) {
809800
if (delayed_work_pending(&cfile->deferred)) {

fs/cifs/smb2ops.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,18 +2575,15 @@ static void
25752575
smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
25762576
{
25772577
struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2578-
struct list_head *tmp, *tmp1;
25792578
struct cifs_ses *ses;
25802579
struct cifs_tcon *tcon;
25812580

25822581
if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
25832582
return;
25842583

25852584
spin_lock(&cifs_tcp_ses_lock);
2586-
list_for_each(tmp, &server->smb_ses_list) {
2587-
ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
2588-
list_for_each(tmp1, &ses->tcon_list) {
2589-
tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
2585+
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
2586+
list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
25902587
if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
25912588
tcon->need_reconnect = true;
25922589
spin_unlock(&cifs_tcp_ses_lock);

0 commit comments

Comments
 (0)