linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] IB/usnic: Fix memory leak in usnic_ib_sysfs_qpn_add
@ 2022-01-26  6:04 Miaoqian Lin
  2022-01-26  9:47 ` Leon Romanovsky
  0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2022-01-26  6:04 UTC (permalink / raw)
  To: Christian Benvenuti, Nelson Escobar, Jason Gunthorpe,
	Upinder Malhi, Roland Dreier, linux-rdma, linux-kernel
  Cc: linmq006

kobject_init_and_add() takes reference even when it fails.
According to the doc of kobject_init_and_add():

   If this function returns an error, kobject_put() must be called to
   properly clean up the memory associated with the object.

Fix memory leak by calling kobject_put().

Fixes: e3cf00d0a87f ("IB/usnic: Add Cisco VIC low-level hardware driver")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/infiniband/hw/usnic/usnic_ib_sysfs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c b/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c
index 7d868f033bbf..69c5854deebc 100644
--- a/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c
+++ b/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c
@@ -280,6 +280,7 @@ void usnic_ib_sysfs_qpn_add(struct usnic_ib_qp_grp *qp_grp)
 			kobject_get(us_ibdev->qpn_kobj),
 			"%d", qp_grp->grp_id);
 	if (err) {
+		kobject_put(&qp_grp->kobj);
 		kobject_put(us_ibdev->qpn_kobj);
 		return;
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-26  9:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-26  6:04 [PATCH] IB/usnic: Fix memory leak in usnic_ib_sysfs_qpn_add Miaoqian Lin
2022-01-26  9:47 ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).