Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a39a98ff authored by Maninder Singh's avatar Maninder Singh Committed by Doug Ledford
Browse files

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: default avatarManinder Singh <maninder1.s@samsung.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent 43bfb972
Loading
Loading
Loading
Loading
+3 −5
Original line number Original line Diff line number Diff line
@@ -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);
	dm = kcalloc(ports, sizeof(*dm), GFP_ATOMIC);
	if (!dm) {
	if (!dm) {
		pr_err("failed to allocate memory for tunneling qp update\n");
		pr_err("failed to allocate memory for tunneling qp update\n");
		goto out;
		return;
	}
	}


	for (i = 0; i < ports; i++) {
	for (i = 0; i < ports; i++) {
		dm[i] = kmalloc(sizeof (struct mlx4_ib_demux_work), GFP_ATOMIC);
		dm[i] = kmalloc(sizeof (struct mlx4_ib_demux_work), GFP_ATOMIC);
		if (!dm[i]) {
		if (!dm[i]) {
			pr_err("failed to allocate memory for tunneling qp update work struct\n");
			pr_err("failed to allocate memory for tunneling qp update work struct\n");
			for (i = 0; i < dev->caps.num_ports; i++) {
			while (--i >= 0)
				if (dm[i])
				kfree(dm[i]);
				kfree(dm[i]);
			}
			goto out;
			goto out;
		}
		}
	}
	}