@@ -67,45 +67,10 @@ static struct iscsi_login *iscsi_login_init_conn(struct iscsi_conn *conn)
67
67
goto out_req_buf ;
68
68
}
69
69
70
- conn -> conn_ops = kzalloc (sizeof (struct iscsi_conn_ops ), GFP_KERNEL );
71
- if (!conn -> conn_ops ) {
72
- pr_err ("Unable to allocate memory for"
73
- " struct iscsi_conn_ops.\n" );
74
- goto out_rsp_buf ;
75
- }
76
-
77
- init_waitqueue_head (& conn -> queues_wq );
78
- INIT_LIST_HEAD (& conn -> conn_list );
79
- INIT_LIST_HEAD (& conn -> conn_cmd_list );
80
- INIT_LIST_HEAD (& conn -> immed_queue_list );
81
- INIT_LIST_HEAD (& conn -> response_queue_list );
82
- init_completion (& conn -> conn_post_wait_comp );
83
- init_completion (& conn -> conn_wait_comp );
84
- init_completion (& conn -> conn_wait_rcfr_comp );
85
- init_completion (& conn -> conn_waiting_on_uc_comp );
86
- init_completion (& conn -> conn_logout_comp );
87
- init_completion (& conn -> rx_half_close_comp );
88
- init_completion (& conn -> tx_half_close_comp );
89
- init_completion (& conn -> rx_login_comp );
90
- spin_lock_init (& conn -> cmd_lock );
91
- spin_lock_init (& conn -> conn_usage_lock );
92
- spin_lock_init (& conn -> immed_queue_lock );
93
- spin_lock_init (& conn -> nopin_timer_lock );
94
- spin_lock_init (& conn -> response_queue_lock );
95
- spin_lock_init (& conn -> state_lock );
96
-
97
- if (!zalloc_cpumask_var (& conn -> conn_cpumask , GFP_KERNEL )) {
98
- pr_err ("Unable to allocate conn->conn_cpumask\n" );
99
- goto out_conn_ops ;
100
- }
101
70
conn -> conn_login = login ;
102
71
103
72
return login ;
104
73
105
- out_conn_ops :
106
- kfree (conn -> conn_ops );
107
- out_rsp_buf :
108
- kfree (login -> rsp_buf );
109
74
out_req_buf :
110
75
kfree (login -> req_buf );
111
76
out_login :
@@ -310,11 +275,9 @@ static int iscsi_login_zero_tsih_s1(
310
275
return - ENOMEM ;
311
276
}
312
277
313
- ret = iscsi_login_set_conn_values (sess , conn , pdu -> cid );
314
- if (unlikely (ret )) {
315
- kfree (sess );
316
- return ret ;
317
- }
278
+ if (iscsi_login_set_conn_values (sess , conn , pdu -> cid ))
279
+ goto free_sess ;
280
+
318
281
sess -> init_task_tag = pdu -> itt ;
319
282
memcpy (& sess -> isid , pdu -> isid , 6 );
320
283
sess -> exp_cmd_sn = be32_to_cpu (pdu -> cmdsn );
@@ -1149,6 +1112,75 @@ iscsit_conn_set_transport(struct iscsi_conn *conn, struct iscsit_transport *t)
1149
1112
return 0 ;
1150
1113
}
1151
1114
1115
+ static struct iscsi_conn * iscsit_alloc_conn (struct iscsi_np * np )
1116
+ {
1117
+ struct iscsi_conn * conn ;
1118
+
1119
+ conn = kzalloc (sizeof (struct iscsi_conn ), GFP_KERNEL );
1120
+ if (!conn ) {
1121
+ pr_err ("Could not allocate memory for new connection\n" );
1122
+ return NULL ;
1123
+ }
1124
+ pr_debug ("Moving to TARG_CONN_STATE_FREE.\n" );
1125
+ conn -> conn_state = TARG_CONN_STATE_FREE ;
1126
+
1127
+ init_waitqueue_head (& conn -> queues_wq );
1128
+ INIT_LIST_HEAD (& conn -> conn_list );
1129
+ INIT_LIST_HEAD (& conn -> conn_cmd_list );
1130
+ INIT_LIST_HEAD (& conn -> immed_queue_list );
1131
+ INIT_LIST_HEAD (& conn -> response_queue_list );
1132
+ init_completion (& conn -> conn_post_wait_comp );
1133
+ init_completion (& conn -> conn_wait_comp );
1134
+ init_completion (& conn -> conn_wait_rcfr_comp );
1135
+ init_completion (& conn -> conn_waiting_on_uc_comp );
1136
+ init_completion (& conn -> conn_logout_comp );
1137
+ init_completion (& conn -> rx_half_close_comp );
1138
+ init_completion (& conn -> tx_half_close_comp );
1139
+ init_completion (& conn -> rx_login_comp );
1140
+ spin_lock_init (& conn -> cmd_lock );
1141
+ spin_lock_init (& conn -> conn_usage_lock );
1142
+ spin_lock_init (& conn -> immed_queue_lock );
1143
+ spin_lock_init (& conn -> nopin_timer_lock );
1144
+ spin_lock_init (& conn -> response_queue_lock );
1145
+ spin_lock_init (& conn -> state_lock );
1146
+
1147
+ timer_setup (& conn -> nopin_response_timer ,
1148
+ iscsit_handle_nopin_response_timeout , 0 );
1149
+ timer_setup (& conn -> nopin_timer , iscsit_handle_nopin_timeout , 0 );
1150
+
1151
+ if (iscsit_conn_set_transport (conn , np -> np_transport ) < 0 )
1152
+ goto free_conn ;
1153
+
1154
+ conn -> conn_ops = kzalloc (sizeof (struct iscsi_conn_ops ), GFP_KERNEL );
1155
+ if (!conn -> conn_ops ) {
1156
+ pr_err ("Unable to allocate memory for struct iscsi_conn_ops.\n" );
1157
+ goto put_transport ;
1158
+ }
1159
+
1160
+ if (!zalloc_cpumask_var (& conn -> conn_cpumask , GFP_KERNEL )) {
1161
+ pr_err ("Unable to allocate conn->conn_cpumask\n" );
1162
+ goto free_mask ;
1163
+ }
1164
+
1165
+ return conn ;
1166
+
1167
+ free_mask :
1168
+ free_cpumask_var (conn -> conn_cpumask );
1169
+ put_transport :
1170
+ iscsit_put_transport (conn -> conn_transport );
1171
+ free_conn :
1172
+ kfree (conn );
1173
+ return NULL ;
1174
+ }
1175
+
1176
+ void iscsit_free_conn (struct iscsi_conn * conn )
1177
+ {
1178
+ free_cpumask_var (conn -> conn_cpumask );
1179
+ kfree (conn -> conn_ops );
1180
+ iscsit_put_transport (conn -> conn_transport );
1181
+ kfree (conn );
1182
+ }
1183
+
1152
1184
void iscsi_target_login_sess_out (struct iscsi_conn * conn ,
1153
1185
struct iscsi_np * np , bool zero_tsih , bool new_sess )
1154
1186
{
@@ -1198,10 +1230,6 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn,
1198
1230
crypto_free_ahash (tfm );
1199
1231
}
1200
1232
1201
- free_cpumask_var (conn -> conn_cpumask );
1202
-
1203
- kfree (conn -> conn_ops );
1204
-
1205
1233
if (conn -> param_list ) {
1206
1234
iscsi_release_param_list (conn -> param_list );
1207
1235
conn -> param_list = NULL ;
@@ -1219,8 +1247,7 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn,
1219
1247
if (conn -> conn_transport -> iscsit_free_conn )
1220
1248
conn -> conn_transport -> iscsit_free_conn (conn );
1221
1249
1222
- iscsit_put_transport (conn -> conn_transport );
1223
- kfree (conn );
1250
+ iscsit_free_conn (conn );
1224
1251
}
1225
1252
1226
1253
static int __iscsi_target_login_thread (struct iscsi_np * np )
@@ -1250,49 +1277,30 @@ static int __iscsi_target_login_thread(struct iscsi_np *np)
1250
1277
}
1251
1278
spin_unlock_bh (& np -> np_thread_lock );
1252
1279
1253
- conn = kzalloc ( sizeof ( struct iscsi_conn ), GFP_KERNEL );
1280
+ conn = iscsit_alloc_conn ( np );
1254
1281
if (!conn ) {
1255
- pr_err ("Could not allocate memory for"
1256
- " new connection\n" );
1257
1282
/* Get another socket */
1258
1283
return 1 ;
1259
1284
}
1260
- pr_debug ("Moving to TARG_CONN_STATE_FREE.\n" );
1261
- conn -> conn_state = TARG_CONN_STATE_FREE ;
1262
-
1263
- timer_setup (& conn -> nopin_response_timer ,
1264
- iscsit_handle_nopin_response_timeout , 0 );
1265
- timer_setup (& conn -> nopin_timer , iscsit_handle_nopin_timeout , 0 );
1266
-
1267
- if (iscsit_conn_set_transport (conn , np -> np_transport ) < 0 ) {
1268
- kfree (conn );
1269
- return 1 ;
1270
- }
1271
1285
1272
1286
rc = np -> np_transport -> iscsit_accept_np (np , conn );
1273
1287
if (rc == - ENOSYS ) {
1274
1288
complete (& np -> np_restart_comp );
1275
- iscsit_put_transport (conn -> conn_transport );
1276
- kfree (conn );
1277
- conn = NULL ;
1289
+ iscsit_free_conn (conn );
1278
1290
goto exit ;
1279
1291
} else if (rc < 0 ) {
1280
1292
spin_lock_bh (& np -> np_thread_lock );
1281
1293
if (atomic_dec_if_positive (& np -> np_reset_count ) >= 0 ) {
1282
1294
np -> np_thread_state = ISCSI_NP_THREAD_ACTIVE ;
1283
1295
spin_unlock_bh (& np -> np_thread_lock );
1284
1296
complete (& np -> np_restart_comp );
1285
- iscsit_put_transport (conn -> conn_transport );
1286
- kfree (conn );
1287
- conn = NULL ;
1297
+ iscsit_free_conn (conn );
1288
1298
/* Get another socket */
1289
1299
return 1 ;
1290
1300
}
1291
1301
spin_unlock_bh (& np -> np_thread_lock );
1292
- iscsit_put_transport (conn -> conn_transport );
1293
- kfree (conn );
1294
- conn = NULL ;
1295
- goto out ;
1302
+ iscsit_free_conn (conn );
1303
+ return 1 ;
1296
1304
}
1297
1305
/*
1298
1306
* Perform the remaining iSCSI connection initialization items..
@@ -1442,7 +1450,6 @@ static int __iscsi_target_login_thread(struct iscsi_np *np)
1442
1450
tpg_np = NULL ;
1443
1451
}
1444
1452
1445
- out :
1446
1453
return 1 ;
1447
1454
1448
1455
exit :
0 commit comments