summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManinder Singh <maninder1.s@samsung.com>2015-07-08 04:13:35 (GMT)
committerDoug Ledford <dledford@redhat.com>2015-07-14 17:20:14 (GMT)
commita39a98ff4cc8b514fe6fa551f6ed59cd60e07da2 (patch)
treea863a36fb8f1a4f0a769d5a72dc781468d3bc9ad
parent43bfb9729ea88d46e3f4d3ad7b17106c7b071fcb (diff)
downloadlinux-a39a98ff4cc8b514fe6fa551f6ed59cd60e07da2.tar.xz
IB/mlx4: Optimize freeing of items on error unwind
On failure, we loop through all possible pointers and test them before calling kfree. But really, why even attempt to free items we didn't allocate when we can easily loop through exactly and only the devices for which the original memory allocation succeeded and free just those. Signed-off-by: Maninder Singh <maninder1.s@samsung.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r--drivers/infiniband/hw/mlx4/main.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index f419a72..064454a 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -2670,17 +2670,15 @@ static void do_slave_init(struct mlx4_ib_dev *ibdev, int slave, int do_init)
dm = kcalloc(ports, sizeof(*dm), GFP_ATOMIC);
if (!dm) {
pr_err("failed to allocate memory for tunneling qp update\n");
- goto out;
+ return;
}
for (i = 0; i < ports; i++) {
dm[i] = kmalloc(sizeof (struct mlx4_ib_demux_work), GFP_ATOMIC);
if (!dm[i]) {
pr_err("failed to allocate memory for tunneling qp update work struct\n");
- for (i = 0; i < dev->caps.num_ports; i++) {
- if (dm[i])
- kfree(dm[i]);
- }
+ while (--i >= 0)
+ kfree(dm[i]);
goto out;
}
}