@@ -2042,6 +2042,7 @@ static int rtrs_clt_rdma_cm_handler(struct rdma_cm_id *cm_id,
2042
2042
return 0 ;
2043
2043
}
2044
2044
2045
+ /* The caller should do the cleanup in case of error */
2045
2046
static int create_cm (struct rtrs_clt_con * con )
2046
2047
{
2047
2048
struct rtrs_path * s = con -> c .path ;
@@ -2064,14 +2065,14 @@ static int create_cm(struct rtrs_clt_con *con)
2064
2065
err = rdma_set_reuseaddr (cm_id , 1 );
2065
2066
if (err != 0 ) {
2066
2067
rtrs_err (s , "Set address reuse failed, err: %d\n" , err );
2067
- goto destroy_cm ;
2068
+ return err ;
2068
2069
}
2069
2070
err = rdma_resolve_addr (cm_id , (struct sockaddr * )& clt_path -> s .src_addr ,
2070
2071
(struct sockaddr * )& clt_path -> s .dst_addr ,
2071
2072
RTRS_CONNECT_TIMEOUT_MS );
2072
2073
if (err ) {
2073
2074
rtrs_err (s , "Failed to resolve address, err: %d\n" , err );
2074
- goto destroy_cm ;
2075
+ return err ;
2075
2076
}
2076
2077
/*
2077
2078
* Combine connection status and session events. This is needed
@@ -2086,29 +2087,15 @@ static int create_cm(struct rtrs_clt_con *con)
2086
2087
if (err == 0 )
2087
2088
err = - ETIMEDOUT ;
2088
2089
/* Timedout or interrupted */
2089
- goto errr ;
2090
- }
2091
- if (con -> cm_err < 0 ) {
2092
- err = con -> cm_err ;
2093
- goto errr ;
2090
+ return err ;
2094
2091
}
2095
- if (READ_ONCE (clt_path -> state ) != RTRS_CLT_CONNECTING ) {
2092
+ if (con -> cm_err < 0 )
2093
+ return con -> cm_err ;
2094
+ if (READ_ONCE (clt_path -> state ) != RTRS_CLT_CONNECTING )
2096
2095
/* Device removal */
2097
- err = - ECONNABORTED ;
2098
- goto errr ;
2099
- }
2096
+ return - ECONNABORTED ;
2100
2097
2101
2098
return 0 ;
2102
-
2103
- errr :
2104
- stop_cm (con );
2105
- mutex_lock (& con -> con_mutex );
2106
- destroy_con_cq_qp (con );
2107
- mutex_unlock (& con -> con_mutex );
2108
- destroy_cm :
2109
- destroy_cm (con );
2110
-
2111
- return err ;
2112
2099
}
2113
2100
2114
2101
static void rtrs_clt_path_up (struct rtrs_clt_path * clt_path )
@@ -2336,7 +2323,7 @@ static void rtrs_clt_close_work(struct work_struct *work)
2336
2323
static int init_conns (struct rtrs_clt_path * clt_path )
2337
2324
{
2338
2325
unsigned int cid ;
2339
- int err ;
2326
+ int err , i ;
2340
2327
2341
2328
/*
2342
2329
* On every new session connections increase reconnect counter
@@ -2352,10 +2339,8 @@ static int init_conns(struct rtrs_clt_path *clt_path)
2352
2339
goto destroy ;
2353
2340
2354
2341
err = create_cm (to_clt_con (clt_path -> s .con [cid ]));
2355
- if (err ) {
2356
- destroy_con (to_clt_con (clt_path -> s .con [cid ]));
2342
+ if (err )
2357
2343
goto destroy ;
2358
- }
2359
2344
}
2360
2345
err = alloc_path_reqs (clt_path );
2361
2346
if (err )
@@ -2366,15 +2351,21 @@ static int init_conns(struct rtrs_clt_path *clt_path)
2366
2351
return 0 ;
2367
2352
2368
2353
destroy :
2369
- while (cid -- ) {
2370
- struct rtrs_clt_con * con = to_clt_con (clt_path -> s .con [cid ]);
2354
+ /* Make sure we do the cleanup in the order they are created */
2355
+ for (i = 0 ; i <= cid ; i ++ ) {
2356
+ struct rtrs_clt_con * con ;
2371
2357
2372
- stop_cm (con );
2358
+ if (!clt_path -> s .con [i ])
2359
+ break ;
2373
2360
2374
- mutex_lock (& con -> con_mutex );
2375
- destroy_con_cq_qp (con );
2376
- mutex_unlock (& con -> con_mutex );
2377
- destroy_cm (con );
2361
+ con = to_clt_con (clt_path -> s .con [i ]);
2362
+ if (con -> c .cm_id ) {
2363
+ stop_cm (con );
2364
+ mutex_lock (& con -> con_mutex );
2365
+ destroy_con_cq_qp (con );
2366
+ mutex_unlock (& con -> con_mutex );
2367
+ destroy_cm (con );
2368
+ }
2378
2369
destroy_con (con );
2379
2370
}
2380
2371
/*
0 commit comments