public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 1/1] infiniband: Remove redundant NULL check before kfree
@ 2015-07-08  4:23 Maninder Singh
  2015-07-08 22:24 ` Doug Ledford
  0 siblings, 1 reply; 5+ messages in thread
From: Maninder Singh @ 2015-07-08  4:23 UTC (permalink / raw)
  To: Doug Ledford
  Cc: Sean Hefty, Or Gerlitz, David Miller, roland@purestorage.com,
	Matan Barak, Moni Shoua, jackm@dev.mellanox.co.il, Yishai Hadas,
	eranbe@mellanox.com, Ira Weiny, linux-rdma, linux-kernel,
	PANKAJ MISHRA

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=windows-1252, Size: 992 bytes --]

Hello,

>> +			for (i = 0; i < dev->caps.num_ports; i++)
>> +				kfree(dm[i]);
>> 			goto out;
>> 		}
>> 	}
>> --
>> 1.7.9.5
>> 
>
>If you are going to change this, you might as well make it 100% correct:
>
>i—-;
>while (i >= 0)
>	kfree(dm[i]);
>
>Then you don’t have to worry about whether kfree works on NULL, every item you free will be guaranteed to be non-NULL.
Thanks for suggestion :)
Sent new patch with described changes, I was thinking one more thing.

In below code :-
        if (!ibdev->sriov.is_going_down)
            queue_work(ibdev->sriov.demux[i].ud_wq, &dm[i]->work);
        spin_unlock_irqrestore(&ibdev->sriov.going_down_lock, flags);
    }
out:
    kfree(dm);
    return;

dm is freed after queue_work, is it correct to free dm when other dm[i] are allocated ? i did not get it.

Thanks
Maninder
------------ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH 1/1] infiniband: Remove redundant NULL check before kfree
@ 2015-06-26  7:09 Maninder Singh
  2015-07-07 18:53 ` Doug Ledford
  2015-07-09 17:06 ` Christoph Lameter
  0 siblings, 2 replies; 5+ messages in thread
From: Maninder Singh @ 2015-06-26  7:09 UTC (permalink / raw)
  To: dledford, sean.hefty, ogerlitz, davem, roland, matanb, monis,
	jackm, yishaih, eranbe, ira.weiny, linux-rdma, linux-kernel
  Cc: pankaj.m, Maninder Singh

kfree(NULL) is safe and this check is probably not required

Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Reviewed-by: Akhilesh Kumar <akhilesh.k@samsung.com>
---
 drivers/infiniband/hw/mlx4/main.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index 067a691..4e60b39 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -2676,10 +2676,8 @@ static void do_slave_init(struct mlx4_ib_dev *ibdev, int slave, int do_init)
 		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]);
-			}
+			for (i = 0; i < dev->caps.num_ports; i++)
+				kfree(dm[i]);
 			goto out;
 		}
 	}
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-07-09 17:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-08  4:23 [PATCH 1/1] infiniband: Remove redundant NULL check before kfree Maninder Singh
2015-07-08 22:24 ` Doug Ledford
  -- strict thread matches above, loose matches on Subject: below --
2015-06-26  7:09 Maninder Singh
2015-07-07 18:53 ` Doug Ledford
2015-07-09 17:06 ` Christoph Lameter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox