Skip to content

Commit dfb5394

Browse files
kwan-intcjgunthorpe
authored andcommitted
IB/hfi1: Call kobject_put() when kobject_init_and_add() fails
When kobject_init_and_add() returns an error in the function hfi1_create_port_files(), the function kobject_put() is not called for the corresponding kobject, which potentially leads to memory leak. This patch fixes the issue by calling kobject_put() even if kobject_init_and_add() fails. Cc: <stable@vger.kernel.org> Link: https://lore.kernel.org/r/20200326163813.21129.44280.stgit@awfm-01.aw.intel.com Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com> Signed-off-by: Kaike Wan <kaike.wan@intel.com> Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 5c15abc commit dfb5394

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎drivers/infiniband/hw/hfi1/sysfs.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,11 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
674674
dd_dev_err(dd,
675675
"Skipping sc2vl sysfs info, (err %d) port %u\n",
676676
ret, port_num);
677-
goto bail;
677+
/*
678+
* Based on the documentation for kobject_init_and_add(), the
679+
* caller should call kobject_put even if this call fails.
680+
*/
681+
goto bail_sc2vl;
678682
}
679683
kobject_uevent(&ppd->sc2vl_kobj, KOBJ_ADD);
680684

@@ -684,7 +688,7 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
684688
dd_dev_err(dd,
685689
"Skipping sl2sc sysfs info, (err %d) port %u\n",
686690
ret, port_num);
687-
goto bail_sc2vl;
691+
goto bail_sl2sc;
688692
}
689693
kobject_uevent(&ppd->sl2sc_kobj, KOBJ_ADD);
690694

@@ -694,7 +698,7 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
694698
dd_dev_err(dd,
695699
"Skipping vl2mtu sysfs info, (err %d) port %u\n",
696700
ret, port_num);
697-
goto bail_sl2sc;
701+
goto bail_vl2mtu;
698702
}
699703
kobject_uevent(&ppd->vl2mtu_kobj, KOBJ_ADD);
700704

@@ -704,7 +708,7 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
704708
dd_dev_err(dd,
705709
"Skipping Congestion Control sysfs info, (err %d) port %u\n",
706710
ret, port_num);
707-
goto bail_vl2mtu;
711+
goto bail_cc;
708712
}
709713

710714
kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD);
@@ -742,7 +746,6 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
742746
kobject_put(&ppd->sl2sc_kobj);
743747
bail_sc2vl:
744748
kobject_put(&ppd->sc2vl_kobj);
745-
bail:
746749
return ret;
747750
}
748751

0 commit comments

Comments
 (0)