diff options
author | Leon Romanovsky <leon@kernel.org> | 2016-11-03 10:44:11 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-01-26 02:24:34 -0500 |
commit | b7c55155983403fe654324e4828e79bd7aab8d76 (patch) | |
tree | ffbcde088220e7806e50443e0811879e59a4bc18 /drivers/infiniband | |
parent | 40bf0662fe3f794fef0a44456337cfb1b1eb45b5 (diff) |
IB/core: Release allocated memory in cache setup failure
commit aa6aae38f7fb2c030f326a6dd10b58fff1851dfa upstream.
The failure in ib_cache_setup_one function during
ib_register_device will leave leaked allocated memory.
Fixes: 03db3a2d81e6 ("IB/core: Add RoCE GID table management")
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r-- | drivers/infiniband/core/cache.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c index 1a2984c28b95..ae04826e82fc 100644 --- a/drivers/infiniband/core/cache.c +++ b/drivers/infiniband/core/cache.c | |||
@@ -770,12 +770,8 @@ static int _gid_table_setup_one(struct ib_device *ib_dev) | |||
770 | int err = 0; | 770 | int err = 0; |
771 | 771 | ||
772 | table = kcalloc(ib_dev->phys_port_cnt, sizeof(*table), GFP_KERNEL); | 772 | table = kcalloc(ib_dev->phys_port_cnt, sizeof(*table), GFP_KERNEL); |
773 | 773 | if (!table) | |
774 | if (!table) { | ||
775 | pr_warn("failed to allocate ib gid cache for %s\n", | ||
776 | ib_dev->name); | ||
777 | return -ENOMEM; | 774 | return -ENOMEM; |
778 | } | ||
779 | 775 | ||
780 | for (port = 0; port < ib_dev->phys_port_cnt; port++) { | 776 | for (port = 0; port < ib_dev->phys_port_cnt; port++) { |
781 | u8 rdma_port = port + rdma_start_port(ib_dev); | 777 | u8 rdma_port = port + rdma_start_port(ib_dev); |
@@ -1170,14 +1166,13 @@ int ib_cache_setup_one(struct ib_device *device) | |||
1170 | GFP_KERNEL); | 1166 | GFP_KERNEL); |
1171 | if (!device->cache.pkey_cache || | 1167 | if (!device->cache.pkey_cache || |
1172 | !device->cache.lmc_cache) { | 1168 | !device->cache.lmc_cache) { |
1173 | pr_warn("Couldn't allocate cache for %s\n", device->name); | 1169 | err = -ENOMEM; |
1174 | return -ENOMEM; | 1170 | goto free; |
1175 | } | 1171 | } |
1176 | 1172 | ||
1177 | err = gid_table_setup_one(device); | 1173 | err = gid_table_setup_one(device); |
1178 | if (err) | 1174 | if (err) |
1179 | /* Allocated memory will be cleaned in the release function */ | 1175 | goto free; |
1180 | return err; | ||
1181 | 1176 | ||
1182 | for (p = 0; p <= rdma_end_port(device) - rdma_start_port(device); ++p) | 1177 | for (p = 0; p <= rdma_end_port(device) - rdma_start_port(device); ++p) |
1183 | ib_cache_update(device, p + rdma_start_port(device)); | 1178 | ib_cache_update(device, p + rdma_start_port(device)); |
@@ -1192,6 +1187,9 @@ int ib_cache_setup_one(struct ib_device *device) | |||
1192 | 1187 | ||
1193 | err: | 1188 | err: |
1194 | gid_table_cleanup_one(device); | 1189 | gid_table_cleanup_one(device); |
1190 | free: | ||
1191 | kfree(device->cache.pkey_cache); | ||
1192 | kfree(device->cache.lmc_cache); | ||
1195 | return err; | 1193 | return err; |
1196 | } | 1194 | } |
1197 | 1195 | ||