From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Xishi Qiu <qiuxishi@huawei.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] cma: adjust goto branch in function cma_create_area()
Date: Mon, 5 Aug 2013 16:55:12 +0800 [thread overview]
Message-ID: <20130805085512.GB22170@kroah.com> (raw)
In-Reply-To: <51FF62CB.3090906@huawei.com>
On Mon, Aug 05, 2013 at 04:31:07PM +0800, Xishi Qiu wrote:
> Adjust the function structure, one for the success path,
> the other for the failure path.
>
> Signed-off-by: Xishi Qiu <qiuxishi@huawei.com>
> ---
> drivers/base/dma-contiguous.c | 16 +++++++++-------
> 1 files changed, 9 insertions(+), 7 deletions(-)
Ick, no, you just added 2 lines for no reason, and made the code harder
to follow.
> diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
> index 1bcfaed..aa72f93 100644
> --- a/drivers/base/dma-contiguous.c
> +++ b/drivers/base/dma-contiguous.c
> @@ -167,26 +167,28 @@ static __init struct cma *cma_create_area(unsigned long base_pfn,
>
> cma = kmalloc(sizeof *cma, GFP_KERNEL);
> if (!cma)
> - return ERR_PTR(-ENOMEM);
> + goto err;
>
> cma->base_pfn = base_pfn;
> cma->count = count;
> cma->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
>
> if (!cma->bitmap)
> - goto no_mem;
> + goto err;
>
> ret = cma_activate_area(base_pfn, count);
> if (ret)
> - goto error;
> + goto err;
>
> pr_debug("%s: returned %p\n", __func__, (void *)cma);
> return cma;
>
> -error:
> - kfree(cma->bitmap);
> -no_mem:
> - kfree(cma);
> +err:
> + if (cma) {
> + if (cma->bitmap)
> + kfree(cma->bitmap);
> + kfree(cma);
> + }
kfree() can accept NULL just fine. I think the code looks acceptable
as-is, so this isn't needed.
sorry,
greg k-h
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2013-08-05 8:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-05 8:31 Xishi Qiu
2013-08-05 8:55 ` Greg Kroah-Hartman [this message]
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=20130805085512.GB22170@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=qiuxishi@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox