public inbox for linux-rdma@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-BHEL68pLQRGGvPXPguhicg@public.gmane.org, Matan Barak,
	Moni Shoua,
	jackm-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org,
	Yishai Hadas, eranbe-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org,
	Ira Weiny, linux-rdma, linux-kernel, PANKAJ MISHRA

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
------------

^ 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
       [not found] ` <1435302547-40904-1-git-send-email-maninder1.s-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Maninder Singh @ 2015-06-26  7:09 UTC (permalink / raw)
  To: dledford-H+wXaHxf7aLQT0dZR+AlfA,
	sean.hefty-ral2JQCrhuEAvxtiuMwx3w,
	ogerlitz-VPRAkNaXOzVWk0Htik3J/w, davem-fT/PcQaiUtIeIZ0/mPfg9Q,
	roland-BHEL68pLQRGGvPXPguhicg, matanb-VPRAkNaXOzVWk0Htik3J/w,
	monis-VPRAkNaXOzVWk0Htik3J/w,
	jackm-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb,
	yishaih-VPRAkNaXOzVWk0Htik3J/w, eranbe-VPRAkNaXOzVWk0Htik3J/w,
	ira.weiny-ral2JQCrhuEAvxtiuMwx3w,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: pankaj.m-Sze3O3UU22JBDgjK7y7TUQ, Maninder Singh

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

Signed-off-by: Maninder Singh <maninder1.s-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Reviewed-by: Akhilesh Kumar <akhilesh.k-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ 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
     [not found] ` <1435302547-40904-1-git-send-email-maninder1.s-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
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