@@ -121,7 +121,7 @@ static inline struct ucma_context *_ucma_find_context(int id,
121121 ctx = idr_find (& ctx_idr , id );
122122 if (!ctx )
123123 ctx = ERR_PTR (- ENOENT );
124- else if (ctx -> file != file )
124+ else if (ctx -> file != file || ! ctx -> cm_id )
125125 ctx = ERR_PTR (- EINVAL );
126126 return ctx ;
127127}
@@ -371,6 +371,7 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
371371 struct rdma_ucm_create_id cmd ;
372372 struct rdma_ucm_create_id_resp resp ;
373373 struct ucma_context * ctx ;
374+ struct rdma_cm_id * cm_id ;
374375 enum ib_qp_type qp_type ;
375376 int ret ;
376377
@@ -391,9 +392,9 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
391392 return - ENOMEM ;
392393
393394 ctx -> uid = cmd .uid ;
394- ctx -> cm_id = rdma_create_id (ucma_event_handler , ctx , cmd .ps , qp_type );
395- if (IS_ERR (ctx -> cm_id )) {
396- ret = PTR_ERR (ctx -> cm_id );
395+ cm_id = rdma_create_id (ucma_event_handler , ctx , cmd .ps , qp_type );
396+ if (IS_ERR (cm_id )) {
397+ ret = PTR_ERR (cm_id );
397398 goto err1 ;
398399 }
399400
@@ -403,10 +404,12 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
403404 ret = - EFAULT ;
404405 goto err2 ;
405406 }
407+
408+ ctx -> cm_id = cm_id ;
406409 return 0 ;
407410
408411err2 :
409- rdma_destroy_id (ctx -> cm_id );
412+ rdma_destroy_id (cm_id );
410413err1 :
411414 mutex_lock (& mut );
412415 idr_remove (& ctx_idr , ctx -> id );
0 commit comments