All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Chen Feng <puck.chen@hisilicon.com>
Cc: gregkh@linuxfoundation.org, arve@android.com,
	riandrews@android.com, tranmanphong@gmail.com,
	mitchelh@codeaurora.org, tapaswenipathak@gmail.com,
	sumit.semwal@linaro.org, paul.gortmaker@windriver.com,
	gioh.kim@lge.com, devel@driverdev.osuosl.org,
	linux-kernel@vger.kernel.org, yudongbin@hisilicon.com,
	saberlily.xia@hisilicon.com, suzhuangluan@hisilicon.com,
	kong.kongxinwei@hisilicon.com, xuyiping@hisilicon.com,
	z.liuxinliang@hisilicon.com, weidong2@hisilicon.com,
	w.f@huawei.com, qijiwen@hisilicon.com,
	peter.panshilin@hisilicon.com, dan.zhao@hisilicon.com,
	linuxarm@huawei.com
Subject: Re: [PATCH V1 2/3] taging: android: ion: Add ion driver for Hi6220 SoC platform
Date: Sat, 10 Oct 2015 18:00:10 +0300	[thread overview]
Message-ID: <20151010140013.GK7289@mwanda> (raw)
In-Reply-To: <1444459703-183909-2-git-send-email-puck.chen@hisilicon.com>

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


  reply	other threads:[~2015-10-10 15:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-10  6:48 [PATCH V1 1/3] docs: dts: Add documentation for hi6220 SoC ION node Chen Feng
2015-10-10  6:48 ` [PATCH V1 2/3] taging: android: ion: Add ion driver for Hi6220 SoC platform Chen Feng
2015-10-10 15:00   ` Dan Carpenter [this message]
2015-10-12  1:15     ` chenfeng
2015-10-10  6:48 ` [PATCH V1 3/3] arm64: dts: Add dts files to enable ION on Hi6220 SoC Chen Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151010140013.GK7289@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=arve@android.com \
    --cc=dan.zhao@hisilicon.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gioh.kim@lge.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kong.kongxinwei@hisilicon.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=mitchelh@codeaurora.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=peter.panshilin@hisilicon.com \
    --cc=puck.chen@hisilicon.com \
    --cc=qijiwen@hisilicon.com \
    --cc=riandrews@android.com \
    --cc=saberlily.xia@hisilicon.com \
    --cc=sumit.semwal@linaro.org \
    --cc=suzhuangluan@hisilicon.com \
    --cc=tapaswenipathak@gmail.com \
    --cc=tranmanphong@gmail.com \
    --cc=w.f@huawei.com \
    --cc=weidong2@hisilicon.com \
    --cc=xuyiping@hisilicon.com \
    --cc=yudongbin@hisilicon.com \
    --cc=z.liuxinliang@hisilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.