lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 7 Jul 2015 14:53:16 -0400
From:	Doug Ledford <dledford@...hat.com>
To:	Maninder Singh <maninder1.s@...sung.com>
Cc:	Sean Hefty <sean.hefty@...el.com>,
	Or Gerlitz <ogerlitz@...lanox.com>,
	David Miller <davem@...emloft.net>, roland@...estorage.com,
	Matan Barak <matanb@...lanox.com>,
	Moni Shoua <monis@...lanox.com>, jackm@....mellanox.co.il,
	Yishai Hadas <yishaih@...lanox.com>, eranbe@...lanox.com,
	Ira Weiny <ira.weiny@...el.com>,
	linux-rdma <linux-rdma@...r.kernel.org>,
	linux-kernel <linux-kernel@...r.kernel.org>, pankaj.m@...sung.com
Subject: Re: [PATCH 1/1] infiniband: Remove redundant NULL check before kfree


> On Jun 26, 2015, at 3:09 AM, Maninder Singh <maninder1.s@...sung.com> wrote:
> 
> kfree(NULL) is safe and this check is probably not required
> 
> Signed-off-by: Maninder Singh <maninder1.s@...sung.com>
> Reviewed-by: Akhilesh Kumar <akhilesh.k@...sung.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
> 

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.

—
Doug Ledford <dledford@...hat.com>
	GPG Key ID: 0E572FDD






Download attachment "signature.asc" of type "application/pgp-signature" (843 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ