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

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>

authored by

Maninder Singh and committed by
Doug Ledford
a39a98ff 43bfb972

+3 -5
+3 -5
drivers/infiniband/hw/mlx4/main.c
··· 2670 2670 dm = kcalloc(ports, sizeof(*dm), GFP_ATOMIC); 2671 2671 if (!dm) { 2672 2672 pr_err("failed to allocate memory for tunneling qp update\n"); 2673 - goto out; 2673 + return; 2674 2674 } 2675 2675 2676 2676 for (i = 0; i < ports; i++) { 2677 2677 dm[i] = kmalloc(sizeof (struct mlx4_ib_demux_work), GFP_ATOMIC); 2678 2678 if (!dm[i]) { 2679 2679 pr_err("failed to allocate memory for tunneling qp update work struct\n"); 2680 - for (i = 0; i < dev->caps.num_ports; i++) { 2681 - if (dm[i]) 2682 - kfree(dm[i]); 2683 - } 2680 + while (--i >= 0) 2681 + kfree(dm[i]); 2684 2682 goto out; 2685 2683 } 2686 2684 }