Skip to content

Commit 16dd9b8

Browse files
sprasad-microsoftsmfrench
authored andcommitted
cifs: added WARN_ON for all the count decrements
We have a few ref counters srv_count, ses_count and tc_count which we use for ref counting. Added a WARN_ON during the decrement of each of these counters to make sure that they don't go below their minimum values. Signed-off-by: Shyam Prasad N <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 63f94e9 commit 16dd9b8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

fs/cifs/connect.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,9 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)
12951295
return;
12961296
}
12971297

1298+
/* srv_count can never go negative */
1299+
WARN_ON(server->srv_count < 0);
1300+
12981301
put_net(cifs_net_ns(server));
12991302

13001303
list_del_init(&server->tcp_ses_list);
@@ -1654,6 +1657,9 @@ void cifs_put_smb_ses(struct cifs_ses *ses)
16541657
}
16551658
spin_unlock(&cifs_tcp_ses_lock);
16561659

1660+
/* ses_count can never go negative */
1661+
WARN_ON(ses->ses_count < 0);
1662+
16571663
spin_lock(&GlobalMid_Lock);
16581664
if (ses->status == CifsGood)
16591665
ses->status = CifsExiting;
@@ -2021,6 +2027,9 @@ cifs_put_tcon(struct cifs_tcon *tcon)
20212027
return;
20222028
}
20232029

2030+
/* tc_count can never go negative */
2031+
WARN_ON(tcon->tc_count < 0);
2032+
20242033
if (tcon->use_witness) {
20252034
int rc;
20262035

fs/cifs/smb2ops.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,6 +2910,8 @@ smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
29102910
/* ipc tcons are not refcounted */
29112911
spin_lock(&cifs_tcp_ses_lock);
29122912
tcon->tc_count--;
2913+
/* tc_count can never go negative */
2914+
WARN_ON(tcon->tc_count < 0);
29132915
spin_unlock(&cifs_tcp_ses_lock);
29142916
}
29152917
kfree(utf16_path);

0 commit comments

Comments
 (0)