@@ -132,7 +132,7 @@ static inline struct ucma_context *_ucma_find_context(int id,
132132 ctx = idr_find (& ctx_idr , id );
133133 if (!ctx )
134134 ctx = ERR_PTR (- ENOENT );
135- else if (ctx -> file != file )
135+ else if (ctx -> file != file || ! ctx -> cm_id )
136136 ctx = ERR_PTR (- EINVAL );
137137 return ctx ;
138138}
@@ -456,6 +456,7 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
456456 struct rdma_ucm_create_id cmd ;
457457 struct rdma_ucm_create_id_resp resp ;
458458 struct ucma_context * ctx ;
459+ struct rdma_cm_id * cm_id ;
459460 enum ib_qp_type qp_type ;
460461 int ret ;
461462
@@ -476,10 +477,10 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
476477 return - ENOMEM ;
477478
478479 ctx -> uid = cmd .uid ;
479- ctx -> cm_id = rdma_create_id (current -> nsproxy -> net_ns ,
480- ucma_event_handler , ctx , cmd .ps , qp_type );
481- if (IS_ERR (ctx -> cm_id )) {
482- ret = PTR_ERR (ctx -> cm_id );
480+ cm_id = rdma_create_id (current -> nsproxy -> net_ns ,
481+ ucma_event_handler , ctx , cmd .ps , qp_type );
482+ if (IS_ERR (cm_id )) {
483+ ret = PTR_ERR (cm_id );
483484 goto err1 ;
484485 }
485486
@@ -489,10 +490,12 @@ static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
489490 ret = - EFAULT ;
490491 goto err2 ;
491492 }
493+
494+ ctx -> cm_id = cm_id ;
492495 return 0 ;
493496
494497err2 :
495- rdma_destroy_id (ctx -> cm_id );
498+ rdma_destroy_id (cm_id );
496499err1 :
497500 mutex_lock (& mut );
498501 idr_remove (& ctx_idr , ctx -> id );
0 commit comments