mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-04 09:59:32 +00:00
IB/core: Release allocated memory in cache setup failure
The failure in ib_cache_setup_one function during
ib_register_device will leave leaked allocated memory.
Fixes: 03db3a2d81
("IB/core: Add RoCE GID table management")
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
This commit is contained in:
parent
a0b3455fcb
commit
aa6aae38f7
1 changed files with 7 additions and 9 deletions
|
@ -770,12 +770,8 @@ static int _gid_table_setup_one(struct ib_device *ib_dev)
|
|||
int err = 0;
|
||||
|
||||
table = kcalloc(ib_dev->phys_port_cnt, sizeof(*table), GFP_KERNEL);
|
||||
|
||||
if (!table) {
|
||||
pr_warn("failed to allocate ib gid cache for %s\n",
|
||||
ib_dev->name);
|
||||
if (!table)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (port = 0; port < ib_dev->phys_port_cnt; port++) {
|
||||
u8 rdma_port = port + rdma_start_port(ib_dev);
|
||||
|
@ -1170,14 +1166,13 @@ int ib_cache_setup_one(struct ib_device *device)
|
|||
GFP_KERNEL);
|
||||
if (!device->cache.pkey_cache ||
|
||||
!device->cache.lmc_cache) {
|
||||
pr_warn("Couldn't allocate cache for %s\n", device->name);
|
||||
return -ENOMEM;
|
||||
err = -ENOMEM;
|
||||
goto free;
|
||||
}
|
||||
|
||||
err = gid_table_setup_one(device);
|
||||
if (err)
|
||||
/* Allocated memory will be cleaned in the release function */
|
||||
return err;
|
||||
goto free;
|
||||
|
||||
for (p = 0; p <= rdma_end_port(device) - rdma_start_port(device); ++p)
|
||||
ib_cache_update(device, p + rdma_start_port(device));
|
||||
|
@ -1192,6 +1187,9 @@ int ib_cache_setup_one(struct ib_device *device)
|
|||
|
||||
err:
|
||||
gid_table_cleanup_one(device);
|
||||
free:
|
||||
kfree(device->cache.pkey_cache);
|
||||
kfree(device->cache.lmc_cache);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue