Commit e5dcc260 authored by Kaike Wan's avatar Kaike Wan Committed by Kelsey Skunberg

IB/hfi1: Call kobject_put() when kobject_init_and_add() fails

BugLink: https://bugs.launchpad.net/bugs/1874045

commit dfb5394f upstream.

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.comReviewed-by: default avatarMike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: default avatarKaike Wan <kaike.wan@intel.com>
Signed-off-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
parent 91e71f9b
...@@ -620,7 +620,11 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num, ...@@ -620,7 +620,11 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
dd_dev_err(dd, dd_dev_err(dd,
"Skipping sc2vl sysfs info, (err %d) port %u\n", "Skipping sc2vl sysfs info, (err %d) port %u\n",
ret, port_num); ret, port_num);
goto bail; /*
* Based on the documentation for kobject_init_and_add(), the
* caller should call kobject_put even if this call fails.
*/
goto bail_sc2vl;
} }
kobject_uevent(&ppd->sc2vl_kobj, KOBJ_ADD); kobject_uevent(&ppd->sc2vl_kobj, KOBJ_ADD);
...@@ -630,7 +634,7 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num, ...@@ -630,7 +634,7 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
dd_dev_err(dd, dd_dev_err(dd,
"Skipping sl2sc sysfs info, (err %d) port %u\n", "Skipping sl2sc sysfs info, (err %d) port %u\n",
ret, port_num); ret, port_num);
goto bail_sc2vl; goto bail_sl2sc;
} }
kobject_uevent(&ppd->sl2sc_kobj, KOBJ_ADD); kobject_uevent(&ppd->sl2sc_kobj, KOBJ_ADD);
...@@ -640,7 +644,7 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num, ...@@ -640,7 +644,7 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
dd_dev_err(dd, dd_dev_err(dd,
"Skipping vl2mtu sysfs info, (err %d) port %u\n", "Skipping vl2mtu sysfs info, (err %d) port %u\n",
ret, port_num); ret, port_num);
goto bail_sl2sc; goto bail_vl2mtu;
} }
kobject_uevent(&ppd->vl2mtu_kobj, KOBJ_ADD); kobject_uevent(&ppd->vl2mtu_kobj, KOBJ_ADD);
...@@ -651,7 +655,7 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num, ...@@ -651,7 +655,7 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
dd_dev_err(dd, dd_dev_err(dd,
"Skipping Congestion Control sysfs info, (err %d) port %u\n", "Skipping Congestion Control sysfs info, (err %d) port %u\n",
ret, port_num); ret, port_num);
goto bail_vl2mtu; goto bail_cc;
} }
kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD); kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD);
...@@ -691,7 +695,6 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num, ...@@ -691,7 +695,6 @@ int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
kobject_put(&ppd->sl2sc_kobj); kobject_put(&ppd->sl2sc_kobj);
bail_sc2vl: bail_sc2vl:
kobject_put(&ppd->sc2vl_kobj); kobject_put(&ppd->sc2vl_kobj);
bail:
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment