From patchwork Wed Feb 3 23:32:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ameya Palande X-Patchwork-Id: 76833 X-Patchwork-Delegate: omar.ramirez@ti.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o13NWdmv015499 for ; Wed, 3 Feb 2010 23:32:40 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757889Ab0BCXck (ORCPT ); Wed, 3 Feb 2010 18:32:40 -0500 Received: from smtp.nokia.com ([192.100.105.134]:60680 "EHLO mgw-mx09.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756225Ab0BCXcj (ORCPT ); Wed, 3 Feb 2010 18:32:39 -0500 Received: from vaebh106.NOE.Nokia.com (vaebh106.europe.nokia.com [10.160.244.32]) by mgw-mx09.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o13NWWYt015355; Wed, 3 Feb 2010 17:32:33 -0600 Received: from esebh102.NOE.Nokia.com ([172.21.138.183]) by vaebh106.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 4 Feb 2010 01:32:29 +0200 Received: from mgw-sa01.ext.nokia.com ([147.243.1.47]) by esebh102.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Thu, 4 Feb 2010 01:32:30 +0200 Received: from localhost.localdomain (essapo-nirac253153.europe.nokia.com [10.162.253.153]) by mgw-sa01.ext.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o13NWQT5013007; Thu, 4 Feb 2010 01:32:28 +0200 From: Ameya Palande To: linux-omap@vger.kernel.org Cc: omar.ramirez@ti.com, nm@ti.com, deepak.chitriki@ti.com Subject: [PATCH 1/3] DSPBRIDGE: Get rid of MEM_CHECK mechanism Date: Thu, 4 Feb 2010 01:32:24 +0200 Message-Id: X-Mailer: git-send-email 1.6.3.3 In-Reply-To: References: In-Reply-To: References: X-OriginalArrivalTime: 03 Feb 2010 23:32:30.0059 (UTC) FILETIME=[27087BB0:01CAA529] X-Nokia-AV: Clean Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 03 Feb 2010 23:32:41 +0000 (UTC) diff --git a/drivers/dsp/bridge/services/mem.c b/drivers/dsp/bridge/services/mem.c index cee646a..c4b1fe1 100644 --- a/drivers/dsp/bridge/services/mem.c +++ b/drivers/dsp/bridge/services/mem.c @@ -34,11 +34,6 @@ /* ----------------------------------- Defines */ #define MEM_512MB 0x1fffffff -#define memInfoSign 0x464E494D /* "MINF" (in reverse). */ - -#ifdef CONFIG_BRIDGE_DEBUG -#define MEM_CHECK /* Use to detect source of memory leaks */ -#endif /* ----------------------------------- Globals */ #if GT_TRACE @@ -56,85 +51,6 @@ struct extPhysMemPool { static struct extPhysMemPool extMemPool; -/* Information about each element allocated on heap */ -struct memInfo { - struct list_head link; /* Must be first */ - size_t size; - void *caller; - u32 dwSignature; /* Should be last */ -}; - -#ifdef MEM_CHECK - -/* - * This structure holds a linked list to all memory elements allocated on - * heap by DSP/BIOS Bridge. This is used to report memory leaks and free - * such elements while removing the DSP/BIOS Bridge driver - */ -struct memMan { - struct LST_LIST lst; - spinlock_t lock; -}; - -static struct memMan mMan; - -/* - * These functions are similar to LST_PutTail and LST_RemoveElem and are - * duplicated here to make MEM independent of LST - */ -static inline void MLST_PutTail(struct LST_LIST *pList, struct list_head *pElem) -{ - pElem->prev = pList->head.prev; - pElem->next = &pList->head; - pList->head.prev = pElem; - pElem->prev->next = pElem; -} - -static inline void MLST_RemoveElem(struct LST_LIST *pList, - struct list_head *pCurElem) -{ - pCurElem->prev->next = pCurElem->next; - pCurElem->next->prev = pCurElem->prev; - pCurElem->next = NULL; - pCurElem->prev = NULL; -} - -static void MEM_Check(void) -{ - struct memInfo *pMem; - struct list_head *last = &mMan.lst.head; - struct list_head *curr = last->next; - - if (!LST_IsEmpty(&mMan.lst)) { - GT_0trace(MEM_debugMask, GT_7CLASS, "*** MEMORY LEAK ***\n"); - GT_0trace(MEM_debugMask, GT_7CLASS, - "Addr Size Caller\n"); - while (curr != last) { - pMem = (struct memInfo *)curr; - curr = curr->next; - if ((u32)pMem > PAGE_OFFSET && - MEM_IsValidHandle(pMem, memInfoSign)) { - GT_3trace(MEM_debugMask, GT_7CLASS, - "%lx %d\t [<%p>]\n", - (u32) pMem + sizeof(struct memInfo), - pMem->size, pMem->caller); - MLST_RemoveElem(&mMan.lst, - (struct list_head *)pMem); - kfree(pMem); - } else { - GT_1trace(MEM_debugMask, GT_7CLASS, - "Invalid allocation or " - "Buffer underflow at %x\n", - (u32)pMem + sizeof(struct memInfo)); - break; - } - } - } - DBC_Ensure(LST_IsEmpty(&mMan.lst)); -} - -#endif - void MEM_ExtPhysPoolInit(u32 poolPhysBase, u32 poolSize) { u32 poolVirtBase; @@ -233,7 +149,7 @@ static void *MEM_ExtPhysMemAlloc(u32 bytes, u32 align, OUT u32 *pPhysAddr) */ void *MEM_Alloc(u32 cBytes, enum MEM_POOLATTRS type) { - struct memInfo *pMem = NULL; + void *pMem = NULL; GT_2trace(MEM_debugMask, GT_ENTER, "MEM_Alloc: cBytes 0x%x\ttype 0x%x\n", cBytes, type); @@ -242,46 +158,11 @@ void *MEM_Alloc(u32 cBytes, enum MEM_POOLATTRS type) case MEM_NONPAGED: /* If non-paged memory required, see note at top of file. */ case MEM_PAGED: -#ifndef MEM_CHECK pMem = kmalloc(cBytes, (in_atomic()) ? GFP_ATOMIC : GFP_KERNEL); -#else - pMem = kmalloc(cBytes + sizeof(struct memInfo), - (in_atomic()) ? GFP_ATOMIC : GFP_KERNEL); - if (pMem) { - pMem->size = cBytes; - pMem->caller = __builtin_return_address(0); - pMem->dwSignature = memInfoSign; - - spin_lock(&mMan.lock); - MLST_PutTail(&mMan.lst, - (struct list_head *)pMem); - spin_unlock(&mMan.lock); - - pMem = (void *)((u32)pMem + - sizeof(struct memInfo)); - } -#endif break; case MEM_LARGEVIRTMEM: -#ifndef MEM_CHECK pMem = vmalloc(cBytes); -#else - pMem = vmalloc(cBytes + sizeof(struct memInfo)); - if (pMem) { - pMem->size = cBytes; - pMem->caller = __builtin_return_address(0); - pMem->dwSignature = memInfoSign; - - spin_lock(&mMan.lock); - MLST_PutTail(&mMan.lst, - (struct list_head *)pMem); - spin_unlock(&mMan.lock); - - pMem = (void *)((u32)pMem + - sizeof(struct memInfo)); - } -#endif break; default: @@ -335,7 +216,7 @@ void *MEM_AllocPhysMem(u32 cBytes, u32 ulAlign, OUT u32 *pPhysicalAddress) */ void *MEM_Calloc(u32 cBytes, enum MEM_POOLATTRS type) { - struct memInfo *pMem = NULL; + void *pMem = NULL; GT_2trace(MEM_debugMask, GT_ENTER, "MEM_Calloc: cBytes 0x%x\ttype 0x%x\n", @@ -346,51 +227,16 @@ void *MEM_Calloc(u32 cBytes, enum MEM_POOLATTRS type) case MEM_NONPAGED: /* If non-paged memory required, see note at top of file. */ case MEM_PAGED: -#ifndef MEM_CHECK pMem = kmalloc(cBytes, (in_atomic()) ? GFP_ATOMIC : GFP_KERNEL); if (pMem) memset(pMem, 0, cBytes); -#else - pMem = kmalloc(cBytes + sizeof(struct memInfo), - (in_atomic()) ? GFP_ATOMIC : GFP_KERNEL); - if (pMem) { - memset((void *)((u32)pMem + - sizeof(struct memInfo)), 0, cBytes); - pMem->size = cBytes; - pMem->caller = __builtin_return_address(0); - pMem->dwSignature = memInfoSign; - spin_lock(&mMan.lock); - MLST_PutTail(&mMan.lst, - (struct list_head *)pMem); - spin_unlock(&mMan.lock); - pMem = (void *)((u32)pMem + - sizeof(struct memInfo)); - } -#endif break; case MEM_LARGEVIRTMEM: -#ifndef MEM_CHECK pMem = vmalloc(cBytes); if (pMem) memset(pMem, 0, cBytes); -#else - pMem = vmalloc(cBytes + sizeof(struct memInfo)); - if (pMem) { - memset((void *)((u32)pMem + - sizeof(struct memInfo)), 0, cBytes); - pMem->size = cBytes; - pMem->caller = __builtin_return_address(0); - pMem->dwSignature = memInfoSign; - spin_lock(&mMan.lock); - MLST_PutTail(&mMan.lst, - (struct list_head *)pMem); - spin_unlock(&mMan.lock); - pMem = (void *)((u32)pMem + - sizeof(struct memInfo)); - } -#endif break; default: GT_1trace(MEM_debugMask, GT_6CLASS, @@ -410,9 +256,6 @@ void *MEM_Calloc(u32 cBytes, enum MEM_POOLATTRS type) */ void MEM_Exit(void) { -#ifdef MEM_CHECK - MEM_Check(); -#endif } /* @@ -455,35 +298,13 @@ void MEM_FlushCache(void *pMemBuf, u32 cBytes, s32 FlushType) */ void MEM_VFree(IN void *pMemBuf) { -#ifdef MEM_CHECK - struct memInfo *pMem = (void *)((u32)pMemBuf - sizeof(struct memInfo)); -#endif - DBC_Require(pMemBuf != NULL); GT_1trace(MEM_debugMask, GT_ENTER, "MEM_VFree: pMemBufs 0x%x\n", pMemBuf); if (pMemBuf) { -#ifndef MEM_CHECK vfree(pMemBuf); -#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; - vfree(pMem); - } else { - GT_1trace(MEM_debugMask, GT_7CLASS, - "Invalid allocation or " - "Buffer underflow at %x\n", - (u32) pMem + sizeof(struct memInfo)); - } - } -#endif } } @@ -494,35 +315,13 @@ void MEM_VFree(IN void *pMemBuf) */ void MEM_Free(IN void *pMemBuf) { -#ifdef MEM_CHECK - struct memInfo *pMem = (void *)((u32)pMemBuf - sizeof(struct memInfo)); -#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); -#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)); - } - } -#endif } } @@ -552,12 +351,5 @@ void MEM_FreePhysMem(void *pVirtualAddress, u32 pPhysicalAddress, bool MEM_Init(void) { GT_create(&MEM_debugMask, "MM"); /* MM for MeM module */ - -#ifdef MEM_CHECK - mMan.lst.head.next = &mMan.lst.head; - mMan.lst.head.prev = &mMan.lst.head; - spin_lock_init(&mMan.lock); -#endif - return true; }