Skip to content

Commit ea89c6c

Browse files
Wen Gudavem330
authored andcommitted
net/smc: Introduce a new conn->lgr validity check helper
It is no longer suitable to identify whether a smc connection is registered in a link group through checking if conn->lgr is NULL, because conn->lgr won't be reset even the connection is unregistered from a link group. So this patch introduces a new helper smc_conn_lgr_valid() and replaces all the check of conn->lgr in original implementation with the new helper to judge if conn->lgr is valid to use. Signed-off-by: Wen Gu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 91341fa commit ea89c6c

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

net/smc/af_smc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,13 @@ static void smc_conn_abort(struct smc_sock *smc, int local_first)
634634
{
635635
struct smc_connection *conn = &smc->conn;
636636
struct smc_link_group *lgr = conn->lgr;
637+
bool lgr_valid = false;
638+
639+
if (smc_conn_lgr_valid(conn))
640+
lgr_valid = true;
637641

638642
smc_conn_free(conn);
639-
if (local_first)
643+
if (local_first && lgr_valid)
640644
smc_lgr_cleanup_early(lgr);
641645
}
642646

net/smc/smc_cdc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ int smc_cdc_get_slot_and_msg_send(struct smc_connection *conn)
197197
{
198198
int rc;
199199

200-
if (!conn->lgr || (conn->lgr->is_smcd && conn->lgr->peer_shutdown))
200+
if (!smc_conn_lgr_valid(conn) ||
201+
(conn->lgr->is_smcd && conn->lgr->peer_shutdown))
201202
return -EPIPE;
202203

203204
if (conn->lgr->is_smcd) {

net/smc/smc_clc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info, u8 version)
774774
dclc.os_type = version == SMC_V1 ? 0 : SMC_CLC_OS_LINUX;
775775
dclc.hdr.typev2 = (peer_diag_info == SMC_CLC_DECL_SYNCERR) ?
776776
SMC_FIRST_CONTACT_MASK : 0;
777-
if ((!smc->conn.lgr || !smc->conn.lgr->is_smcd) &&
777+
if ((!smc_conn_lgr_valid(&smc->conn) || !smc->conn.lgr->is_smcd) &&
778778
smc_ib_is_valid_local_systemid())
779779
memcpy(dclc.id_for_peer, local_systemid,
780780
sizeof(local_systemid));

net/smc/smc_core.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static void smc_lgr_unregister_conn(struct smc_connection *conn)
211211
{
212212
struct smc_link_group *lgr = conn->lgr;
213213

214-
if (!lgr)
214+
if (!smc_conn_lgr_valid(conn))
215215
return;
216216
write_lock_bh(&lgr->conns_lock);
217217
if (conn->alert_token_local) {
@@ -1139,7 +1139,7 @@ void smc_conn_free(struct smc_connection *conn)
11391139
return;
11401140

11411141
conn->freed = 1;
1142-
if (!conn->alert_token_local)
1142+
if (!smc_conn_lgr_valid(conn))
11431143
/* Connection has already unregistered from
11441144
* link group.
11451145
*/
@@ -2278,14 +2278,16 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)
22782278

22792279
void smc_sndbuf_sync_sg_for_cpu(struct smc_connection *conn)
22802280
{
2281-
if (!conn->lgr || conn->lgr->is_smcd || !smc_link_active(conn->lnk))
2281+
if (!smc_conn_lgr_valid(conn) || conn->lgr->is_smcd ||
2282+
!smc_link_active(conn->lnk))
22822283
return;
22832284
smc_ib_sync_sg_for_cpu(conn->lnk, conn->sndbuf_desc, DMA_TO_DEVICE);
22842285
}
22852286

22862287
void smc_sndbuf_sync_sg_for_device(struct smc_connection *conn)
22872288
{
2288-
if (!conn->lgr || conn->lgr->is_smcd || !smc_link_active(conn->lnk))
2289+
if (!smc_conn_lgr_valid(conn) || conn->lgr->is_smcd ||
2290+
!smc_link_active(conn->lnk))
22892291
return;
22902292
smc_ib_sync_sg_for_device(conn->lnk, conn->sndbuf_desc, DMA_TO_DEVICE);
22912293
}
@@ -2294,7 +2296,7 @@ void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn)
22942296
{
22952297
int i;
22962298

2297-
if (!conn->lgr || conn->lgr->is_smcd)
2299+
if (!smc_conn_lgr_valid(conn) || conn->lgr->is_smcd)
22982300
return;
22992301
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
23002302
if (!smc_link_active(&conn->lgr->lnk[i]))
@@ -2308,7 +2310,7 @@ void smc_rmb_sync_sg_for_device(struct smc_connection *conn)
23082310
{
23092311
int i;
23102312

2311-
if (!conn->lgr || conn->lgr->is_smcd)
2313+
if (!smc_conn_lgr_valid(conn) || conn->lgr->is_smcd)
23122314
return;
23132315
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
23142316
if (!smc_link_active(&conn->lgr->lnk[i]))

net/smc/smc_core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ static inline struct smc_connection *smc_lgr_find_conn(
410410
return res;
411411
}
412412

413+
static inline bool smc_conn_lgr_valid(struct smc_connection *conn)
414+
{
415+
return conn->lgr && conn->alert_token_local;
416+
}
417+
413418
/*
414419
* Returns true if the specified link is usable.
415420
*

net/smc/smc_diag.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb,
8989
r->diag_state = sk->sk_state;
9090
if (smc->use_fallback)
9191
r->diag_mode = SMC_DIAG_MODE_FALLBACK_TCP;
92-
else if (smc->conn.lgr && smc->conn.lgr->is_smcd)
92+
else if (smc_conn_lgr_valid(&smc->conn) && smc->conn.lgr->is_smcd)
9393
r->diag_mode = SMC_DIAG_MODE_SMCD;
9494
else
9595
r->diag_mode = SMC_DIAG_MODE_SMCR;
@@ -142,7 +142,7 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb,
142142
goto errout;
143143
}
144144

145-
if (smc->conn.lgr && !smc->conn.lgr->is_smcd &&
145+
if (smc_conn_lgr_valid(&smc->conn) && !smc->conn.lgr->is_smcd &&
146146
(req->diag_ext & (1 << (SMC_DIAG_LGRINFO - 1))) &&
147147
!list_empty(&smc->conn.lgr->list)) {
148148
struct smc_link *link = smc->conn.lnk;
@@ -164,7 +164,7 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb,
164164
if (nla_put(skb, SMC_DIAG_LGRINFO, sizeof(linfo), &linfo) < 0)
165165
goto errout;
166166
}
167-
if (smc->conn.lgr && smc->conn.lgr->is_smcd &&
167+
if (smc_conn_lgr_valid(&smc->conn) && smc->conn.lgr->is_smcd &&
168168
(req->diag_ext & (1 << (SMC_DIAG_DMBINFO - 1))) &&
169169
!list_empty(&smc->conn.lgr->list)) {
170170
struct smc_connection *conn = &smc->conn;

0 commit comments

Comments
 (0)