Re: [PATCH] DSPBRIDGE: MEM_Free() cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2010-02-01 at 17:57 +0100, Palande Ameya (Nokia-D/Helsinki)
wrote:
> Since kfree() checks for null pointer, there is no need to check is again in
> MEM_Free(). This patch also reorganizes the function to make it more readable.
> 
> Signed-off-by: Ameya Palande <ameya.palande@xxxxxxxxx>
> ---
>  drivers/dsp/bridge/services/mem.c |   40 ++++++++++++++----------------------
>  1 files changed, 16 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/dsp/bridge/services/mem.c b/drivers/dsp/bridge/services/mem.c
> index cee646a..dfe352d 100644
> --- a/drivers/dsp/bridge/services/mem.c
> +++ b/drivers/dsp/bridge/services/mem.c
> @@ -495,35 +495,27 @@ void MEM_VFree(IN void *pMemBuf)
>  void MEM_Free(IN void *pMemBuf)
>  {
>  #ifdef MEM_CHECK
> -	struct memInfo *pMem = (void *)((u32)pMemBuf - sizeof(struct memInfo));
> +	struct memInfo *pMem;
>  #endif
> -
> -	DBC_Require(pMemBuf != NULL);
> -
>  	GT_1trace(MEM_debugMask, GT_ENTER, "MEM_Free: pMemBufs 0x%x\n",
>  		  pMemBuf);
> -
> -	if (pMemBuf) {
> -#ifndef MEM_CHECK
> -		kfree(pMemBuf);
> +#ifdef MEM_CHECK
> +	if (!pMemBuf) {
> +		GT_1trace(MEM_debugMask, GT_7CLASS,
> +			"Invalid allocation or Buffer underflow\n");
> +		return;
> +	}
> +	pMem = (void *)((u32)pMemBuf - sizeof(struct memInfo));
> +	if (pMem && pMem->dwSignature == memInfoSign) {
> +		spin_lock(&mMan.lock);
> +		MLST_RemoveElem(&mMan.lst, (struct list_head *)pMem);
> +		spin_unlock(&mMan.lock);
> +		pMem->dwSignature = 0;
> +		kfree(pMem);
> +	}
>  #else
> -		if (pMem) {
> -			if (pMem->dwSignature == memInfoSign) {
> -				spin_lock(&mMan.lock);
> -				MLST_RemoveElem(&mMan.lst,
> -						(struct list_head *)pMem);
> -				spin_unlock(&mMan.lock);
> -				pMem->dwSignature = 0;
> -				kfree(pMem);
> -			} else {
> -				GT_1trace(MEM_debugMask, GT_7CLASS,
> -					"Invalid allocation or "
> -					"Buffer underflow at %x\n",
> -					(u32) pMem + sizeof(struct memInfo));
> -			}
> -		}
> +	kfree(pMemBuf);
>  #endif
> -	}
>  }
>  
>  /*

NACK!
I found a better solution. Will post patches soon :)

Cheers,
Ameya.

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Arm (vger)]     [ARM Kernel]     [ARM MSM]     [Linux Tegra]     [Linux WPAN Networking]     [Linux Wireless Networking]     [Maemo Users]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux