Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 03db3a2d81e6 ("IB/core: Add RoCE GID table management")
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>

authored by

Leon Romanovsky and committed by
Doug Ledford
aa6aae38 a0b3455f

+7 -9
+7 -9
drivers/infiniband/core/cache.c
··· 770 770 int err = 0; 771 771 772 772 table = kcalloc(ib_dev->phys_port_cnt, sizeof(*table), GFP_KERNEL); 773 - 774 - if (!table) { 775 - pr_warn("failed to allocate ib gid cache for %s\n", 776 - ib_dev->name); 773 + if (!table) 777 774 return -ENOMEM; 778 - } 779 775 780 776 for (port = 0; port < ib_dev->phys_port_cnt; port++) { 781 777 u8 rdma_port = port + rdma_start_port(ib_dev); ··· 1166 1170 GFP_KERNEL); 1167 1171 if (!device->cache.pkey_cache || 1168 1172 !device->cache.lmc_cache) { 1169 - pr_warn("Couldn't allocate cache for %s\n", device->name); 1170 - return -ENOMEM; 1173 + err = -ENOMEM; 1174 + goto free; 1171 1175 } 1172 1176 1173 1177 err = gid_table_setup_one(device); 1174 1178 if (err) 1175 - /* Allocated memory will be cleaned in the release function */ 1176 - return err; 1179 + goto free; 1177 1180 1178 1181 for (p = 0; p <= rdma_end_port(device) - rdma_start_port(device); ++p) 1179 1182 ib_cache_update(device, p + rdma_start_port(device)); ··· 1187 1192 1188 1193 err: 1189 1194 gid_table_cleanup_one(device); 1195 + free: 1196 + kfree(device->cache.pkey_cache); 1197 + kfree(device->cache.lmc_cache); 1190 1198 return err; 1191 1199 } 1192 1200