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:	Sat, 10 Oct 2015 18:00:10 +0300
From:	Dan Carpenter <dan.carpenter@...cle.com>
To:	Chen Feng <puck.chen@...ilicon.com>
Cc:	gregkh@...uxfoundation.org, arve@...roid.com,
	riandrews@...roid.com, tranmanphong@...il.com,
	mitchelh@...eaurora.org, tapaswenipathak@...il.com,
	sumit.semwal@...aro.org, paul.gortmaker@...driver.com,
	gioh.kim@....com, devel@...verdev.osuosl.org,
	linux-kernel@...r.kernel.org, yudongbin@...ilicon.com,
	saberlily.xia@...ilicon.com, suzhuangluan@...ilicon.com,
	kong.kongxinwei@...ilicon.com, xuyiping@...ilicon.com,
	z.liuxinliang@...ilicon.com, weidong2@...ilicon.com,
	w.f@...wei.com, qijiwen@...ilicon.com,
	peter.panshilin@...ilicon.com, dan.zhao@...ilicon.com,
	linuxarm@...wei.com
Subject: Re: [PATCH V1 2/3] taging: android: ion: Add ion driver for Hi6220
 SoC platform

On Sat, Oct 10, 2015 at 02:48:22PM +0800, Chen Feng wrote:
> +static int hi6220_ion_probe(struct platform_device *pdev)
> +{
> +	int i;
> +	int err = 0;
> +	static struct ion_platform_heap *p_heap;
> +
> +	idev = ion_device_create(NULL);
> +	hi6220_set_platform_data(pdev);
> +	heaps = devm_kzalloc(&pdev->dev,
> +			     sizeof(struct ion_heap *) * num_heaps,
> +			     GFP_KERNEL);
> +	if (!heaps)
> +		return -ENOMEM;
> +
> +	/*
> +	 * create the heaps as specified in the dts file
> +	 */
> +	for (i = 0; i < num_heaps; i++) {
> +		p_heap = heaps_data[i];
> +		heaps[i] = ion_heap_create(p_heap);
> +		if (IS_ERR_OR_NULL(heaps[i])) {
> +			err = PTR_ERR(heaps[i]);
> +			goto err_free_heaps;
> +		}
> +
> +		ion_device_add_heap(idev, heaps[i]);
> +
> +		pr_info("%s: adding heap %s of type %d with %lx@%lx\n",
> +			__func__, p_heap->name, p_heap->type,
> +			p_heap->base, (unsigned long)p_heap->size);
> +	}
> +	return err;
> +
> +err_free_heaps:
> +	ion_device_destroy(idev);
> +	for (i = 0; i < num_heaps; ++i) {
> +		ion_heap_destroy(heaps[i]);
> +		heaps[i] = NULL;
> +	}
> +
> +	return err;
> +}

Thanks this is better but still not quite right.  You have to unwind in
the reverse order from how you allocated things.

err_free_heaps:
	for (i = 0; i < num_heaps; ++i) {
		ion_heap_destroy(heaps[i]);
		heaps[i] = NULL;
	}
err_destroy_idev:
	ion_device_destroy(idev);

	return err;

And earlier it should be:

 	idev = ion_device_create(NULL);
 	hi6220_set_platform_data(pdev);
 	heaps = devm_kzalloc(&pdev->dev,
 			     sizeof(struct ion_heap *) * num_heaps,
 			     GFP_KERNEL);
-	if (!heaps)
-		return -ENOMEM;
+	if (!heaps) {
+		err = -ENOMEM;
+		goto err_destroy_idev;
+	}

Otherwise we leak some resources if we can't allocate "heaps".

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ