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] [day] [month] [year] [list]
Date:	Mon, 5 Aug 2013 16:55:12 +0800
From:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To:	Xishi Qiu <qiuxishi@...wei.com>
Cc:	Andrew Morton <akpm@...ux-foundation.org>, linux-mm@...ck.org,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 2/2] cma: adjust goto branch in function cma_create_area()

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@...wei.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 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