Skip to content

Commit

Permalink
RDMA/cm: Fix memory leak in ib_cm_insert_listen
Browse files Browse the repository at this point in the history
cm_alloc_id_priv() allocates resource for the cm_id_priv. When
cm_init_listen() fails it doesn't free it, leading to memory leak.

Add the missing error unwind.

Fixes: 98f6715 ("RDMA/cm: Simplify establishing a listen cm_id")
Link: https://lore.kernel.org/r/20220621052546.4821-1-linmq006@gmail.com
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
  • Loading branch information
Miaoqian Lin authored and Jason Gunthorpe committed Jun 24, 2022
1 parent 118f767 commit 2990f22
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/infiniband/core/cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,10 @@ struct ib_cm_id *ib_cm_insert_listen(struct ib_device *device,
return ERR_CAST(cm_id_priv);

err = cm_init_listen(cm_id_priv, service_id, 0);
if (err)
if (err) {
ib_destroy_cm_id(&cm_id_priv->id);
return ERR_PTR(err);
}

spin_lock_irq(&cm_id_priv->lock);
listen_id_priv = cm_insert_listen(cm_id_priv, cm_handler);
Expand Down

0 comments on commit 2990f22

Please sign in to comment.