public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* dspbridge: draft: get rid of services/list.c
@ 2009-09-01 11:39 Andy Shevchenko
  2009-09-01 11:39 ` [PATCH 1/2] DSPBRIDGE: Get rid of services/list.c (step 1) Andy Shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2009-09-01 11:39 UTC (permalink / raw)
  To: linux-omap


Hello.

Here are two patches which change driver's own circular linked list
implementation to native one in linux kernel. The initial idea was come from
Hiroshi Doyu.

P.S. Please, ignore mail with 'Message-ID:
<1251793647-14569-1-git-send-email-andy.shevchenko@gmail.com>'


-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] DSPBRIDGE: Get rid of services/list.c (step 1)
  2009-09-01 11:39 dspbridge: draft: get rid of services/list.c Andy Shevchenko
@ 2009-09-01 11:39 ` Andy Shevchenko
  2009-09-01 11:39   ` [PATCH 2/2] DSPBRIDGE: Get rid of services/list.c (step 2) Andy Shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2009-09-01 11:39 UTC (permalink / raw)
  To: linux-omap; +Cc: Andy Shevchenko

From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>

* Remove LST_Init() and LST_Exit() calls because they are doing nothing except
  tracing, Thus, remove tracing as well.

* Remove DBC_* calls. It's internal kernel business whether to have those
  assertions.

* Switch to list_head structure instead of LST_ELEM. Remove redudant code that
  uses head->self pointer.

* Use native list methods where it's possible in the list.c.

Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
---
 arch/arm/plat-omap/include/dspbridge/list.h |   43 +----------
 drivers/dsp/bridge/services/list.c          |  108 +-------------------------
 drivers/dsp/bridge/services/mem.c           |    2 -
 drivers/dsp/bridge/services/services.c      |    9 +--
 4 files changed, 10 insertions(+), 152 deletions(-)

diff --git a/arch/arm/plat-omap/include/dspbridge/list.h b/arch/arm/plat-omap/include/dspbridge/list.h
index 2e3f995..f9bbd13 100644
--- a/arch/arm/plat-omap/include/dspbridge/list.h
+++ b/arch/arm/plat-omap/include/dspbridge/list.h
@@ -24,11 +24,9 @@
  *  Public Functions:
  *      LST_Create
  *      LST_Delete
- *      LST_Exit
  *      LST_First
  *      LST_GetHead
  *      LST_InitElem
- *      LST_Init
  *      LST_InsertBefore
  *      LST_IsEmpty
  *      LST_Next
@@ -51,14 +49,10 @@
 #define LIST_
 
 #include <dspbridge/host_os.h>
+#include <linux/list.h>
 
-#define LST_IsEmpty(l)      (((l)->head.next == &(l)->head))
-
-	struct LST_ELEM {
-		struct LST_ELEM *next;
-		struct LST_ELEM *prev;
-		struct LST_ELEM *self;
-	} ;
+#define LST_ELEM            list_head
+#define LST_IsEmpty(l)      list_empty(&(l)->head)
 
 	struct LST_LIST {
 		struct LST_ELEM head;
@@ -111,20 +105,6 @@
 	extern void LST_Delete(IN struct LST_LIST *pList);
 
 /*
- *  ======== LST_Exit ========
- *  Purpose:
- *      Discontinue usage of module; free resources when reference count
- *      reaches 0.
- *  Parameters:
- *  Returns:
- *  Requires:
- *      LST initialized.
- *  Ensures:
- *      Resources used by module are freed when cRef reaches zero.
- */
-	extern void LST_Exit(void);
-
-/*
  *  ======== LST_First ========
  *  Purpose:
  *      Returns a pointer to the first element of the list, or NULL if the list
@@ -160,7 +140,6 @@
  *      Pointer to element that was at the head of the list (success)
  *      NULL          No elements in list
  *  Requires:
- *      - head.self must be correctly set to &head.
  *      - LST initialized.
  *      - pList != NULL.
  *  Ensures:
@@ -172,19 +151,6 @@
 	extern struct LST_ELEM *LST_GetHead(IN struct LST_LIST *pList);
 
 /*
- *  ======== LST_Init ========
- *  Purpose:
- *      Initializes private state of LST module.
- *  Parameters:
- *  Returns:
- *      TRUE if initialized; FALSE otherwise.
- *  Requires:
- *  Ensures:
- *      LST initialized.
- */
-	extern bool LST_Init(void);
-
-/*
  *  ======== LST_InitElem ========
  *  Purpose:
  *      Initializes a list element to default (cleared) values
@@ -262,15 +228,12 @@
  *      Void
  *  Requires:
  *      *pElem and *pList must both exist.
- *      pElem->self = pElem before pElem is passed to this function.
  *      LST initialized.
  *  Ensures:
  *  Notes:
  *      Because the tail is always "just before" the head of the list (the
  *      tail's "next" pointer points at the head of the list, and the head's
  *      "prev" pointer points at the tail of the list), the list is circular.
- *  Warning: if pElem->self is not set beforehand, LST_GetHead() will
- *      return an erroneous pointer when it is called for this element.
  */
 	extern void LST_PutTail(IN struct LST_LIST *pList,
 				IN struct LST_ELEM *pListElem);
diff --git a/drivers/dsp/bridge/services/list.c b/drivers/dsp/bridge/services/list.c
index 7fa3e76..b215b68 100644
--- a/drivers/dsp/bridge/services/list.c
+++ b/drivers/dsp/bridge/services/list.c
@@ -23,10 +23,8 @@
  *  Public Functions:
  *      LST_Create
  *      LST_Delete
- *      LST_Exit
  *      LST_First
  *      LST_GetHead
- *      LST_Init
  *      LST_InitElem
  *      LST_InsertBefore
  *      LST_Next
@@ -51,21 +49,12 @@
 #include <dspbridge/std.h>
 #include <dspbridge/dbdefs.h>
 
-/*  ----------------------------------- Trace & Debug */
-#include <dspbridge/dbc.h>
-#include <dspbridge/gt.h>
-
 /*  ----------------------------------- OS Adaptation Layer */
 #include <dspbridge/mem.h>
 
 /*  ----------------------------------- This */
 #include <dspbridge/list.h>
 
-/*  ----------------------------------- Globals */
-#if GT_TRACE
-static struct GT_Mask LST_debugMask = { NULL, NULL };	/* GT trace var. */
-#endif
-
 /*
  *  ======== LST_Create ========
  *  Purpose:
@@ -75,14 +64,10 @@ struct LST_LIST *LST_Create(void)
 {
 	struct LST_LIST *pList;
 
-	GT_0trace(LST_debugMask, GT_ENTER, "LST_Create: entered\n");
-
 	pList = (struct LST_LIST *) MEM_Calloc(sizeof(struct LST_LIST),
 		MEM_NONPAGED);
 	if (pList != NULL) {
-		pList->head.next = &pList->head;
-		pList->head.prev = &pList->head;
-		pList->head.self = NULL;
+		INIT_LIST_HEAD(&pList->head);
 	}
 
 	return pList;
@@ -95,24 +80,10 @@ struct LST_LIST *LST_Create(void)
  */
 void LST_Delete(struct LST_LIST *pList)
 {
-	DBC_Require(pList != NULL);
-
-	GT_1trace(LST_debugMask, GT_ENTER, "LST_Delete: pList 0x%x\n", pList);
-
 	MEM_Free(pList);
 }
 
 /*
- *  ======== LST_Exit ========
- *  Purpose:
- *      Discontinue usage of the LST module.
- */
-void LST_Exit(void)
-{
-	GT_0trace(LST_debugMask, GT_5CLASS, "LST_Exit\n");
-}
-
-/*
  *  ======== LST_First ========
  *  Purpose:
  *      Returns a pointer to the first element of the list, or NULL if the
@@ -122,10 +93,6 @@ struct LST_ELEM *LST_First(struct LST_LIST *pList)
 {
 	struct LST_ELEM *pElem = NULL;
 
-	DBC_Require(pList != NULL);
-
-	GT_1trace(LST_debugMask, GT_ENTER, "LST_First: pList 0x%x\n", pList);
-
 	if (!LST_IsEmpty(pList))
 		pElem = pList->head.next;
 
@@ -141,10 +108,6 @@ struct LST_ELEM *LST_GetHead(struct LST_LIST *pList)
 {
 	struct LST_ELEM *pElem;
 
-	DBC_Require(pList != NULL);
-
-	GT_1trace(LST_debugMask, GT_ENTER, "LST_GetHead: pList 0x%x\n", pList);
-
 	if (LST_IsEmpty(pList))
 		return NULL;
 
@@ -154,21 +117,7 @@ struct LST_ELEM *LST_GetHead(struct LST_LIST *pList)
 	pList->head.next = pElem->next;
 	pElem->next->prev = &pList->head;
 
-	return pElem->self;
-}
-
-/*
- *  ======== LST_Init ========
- *  Purpose:
- *      Initialize LST module private state.
- */
-bool LST_Init(void)
-{
-	GT_create(&LST_debugMask, "LS");	/* LS for LSt module */
-
-	GT_0trace(LST_debugMask, GT_5CLASS, "LST_Init\n");
-
-	return true;
+	return pElem;
 }
 
 /*
@@ -178,14 +127,9 @@ bool LST_Init(void)
  */
 void LST_InitElem(struct LST_ELEM *pElem)
 {
-	DBC_Require(pElem != NULL);
-
-	GT_1trace(LST_debugMask, GT_ENTER, "LST_InitElem: pElem 0x%x\n", pElem);
-
 	if (pElem) {
 		pElem->next = NULL;
 		pElem->prev = NULL;
-		pElem->self = pElem;
 	}
 }
 
@@ -197,18 +141,7 @@ void LST_InitElem(struct LST_ELEM *pElem)
 void LST_InsertBefore(struct LST_LIST *pList, struct LST_ELEM *pElem,
 		      struct LST_ELEM *pElemExisting)
 {
-	DBC_Require(pList != NULL);
-	DBC_Require(pElem != NULL);
-	DBC_Require(pElemExisting != NULL);
-
-	GT_3trace(LST_debugMask, GT_ENTER, "LST_InsertBefore: pList 0x%x, "
-		  "pElem 0x%x pElemExisting 0x%x\n", pList, pElem,
-		  pElemExisting);
-
-	pElemExisting->prev->next = pElem;
-	pElem->prev = pElemExisting->prev;
-	pElem->next = pElemExisting;
-	pElemExisting->prev = pElem;
+	list_add_tail(pElem, pElemExisting);
 }
 
 /*
@@ -221,13 +154,6 @@ struct LST_ELEM *LST_Next(struct LST_LIST *pList, struct LST_ELEM *pCurElem)
 {
 	struct LST_ELEM *pNextElem = NULL;
 
-	DBC_Require(pList != NULL);
-	DBC_Require(pCurElem != NULL);
-
-	GT_2trace(LST_debugMask, GT_ENTER,
-		  "LST_Next: pList 0x%x, pCurElem 0x%x\n",
-		  pList, pCurElem);
-
 	if (!LST_IsEmpty(pList)) {
 		if (pCurElem->next != &pList->head)
 			pNextElem = pCurElem->next;
@@ -243,19 +169,7 @@ struct LST_ELEM *LST_Next(struct LST_LIST *pList, struct LST_ELEM *pCurElem)
  */
 void LST_PutTail(struct LST_LIST *pList, struct LST_ELEM *pElem)
 {
-	DBC_Require(pList != NULL);
-	DBC_Require(pElem != NULL);
-
-	GT_2trace(LST_debugMask, GT_ENTER,
-		  "LST_PutTail: pList 0x%x, pElem 0x%x\n",
-		  pList, pElem);
-
-	pElem->prev = pList->head.prev;
-	pElem->next = &pList->head;
-	pList->head.prev = pElem;
-	pElem->prev->next = pElem;
-
-	DBC_Ensure(!LST_IsEmpty(pList));
+	list_add_tail(pElem, &pList->head);
 }
 
 /*
@@ -266,20 +180,8 @@ void LST_PutTail(struct LST_LIST *pList, struct LST_ELEM *pElem)
  */
 void LST_RemoveElem(struct LST_LIST *pList, struct LST_ELEM *pCurElem)
 {
-	DBC_Require(pList != NULL);
-	DBC_Require(pCurElem != NULL);
-
-	GT_2trace(LST_debugMask, GT_ENTER,
-		  "LST_RemoveElem: pList 0x%x, pCurElem "
-		  "0x%x\n", pList, pCurElem);
-
 	if (!LST_IsEmpty(pList)) {
-		pCurElem->prev->next = pCurElem->next;
-		pCurElem->next->prev = pCurElem->prev;
-
-		/* set elem fields to NULL to prevent illegal references */
-		pCurElem->next = NULL;
-		pCurElem->prev = NULL;
+		list_del_init(pCurElem);
 	}
 }
 
diff --git a/drivers/dsp/bridge/services/mem.c b/drivers/dsp/bridge/services/mem.c
index 22f382b..cc16e5d 100644
--- a/drivers/dsp/bridge/services/mem.c
+++ b/drivers/dsp/bridge/services/mem.c
@@ -125,7 +125,6 @@ static inline void MLST_PutTail(struct LST_LIST *pList, struct LST_ELEM *pElem)
 	pElem->next = &pList->head;
 	pList->head.prev = pElem;
 	pElem->prev->next = pElem;
-	pElem->self = pElem;
 }
 
 static inline void MLST_RemoveElem(struct LST_LIST *pList,
@@ -612,7 +611,6 @@ bool MEM_Init(void)
 #ifdef MEM_CHECK
 		mMan.lst.head.next = &mMan.lst.head;
 		mMan.lst.head.prev = &mMan.lst.head;
-		mMan.lst.head.self = NULL;
 		spin_lock_init(&mMan.lock);
 #endif
 
diff --git a/drivers/dsp/bridge/services/services.c b/drivers/dsp/bridge/services/services.c
index 346007e..56fca76 100644
--- a/drivers/dsp/bridge/services/services.c
+++ b/drivers/dsp/bridge/services/services.c
@@ -87,7 +87,6 @@ void SERVICES_Exit(void)
 		SYNC_Exit();
 		CLK_Exit();
 		REG_Exit();
-		LST_Exit();
 		KFILE_Exit();
 		DPC_Exit();
 		DBG_Exit();
@@ -109,7 +108,7 @@ void SERVICES_Exit(void)
 bool SERVICES_Init(void)
 {
 	bool fInit = true;
-       bool fCFG, fCSL, fDBG, fDPC, fKFILE, fLST, fMEM;
+       bool fCFG, fCSL, fDBG, fDPC, fKFILE, fMEM;
        bool fREG, fSYNC, fCLK, fUTIL, fNTFY;
 
 	DBC_Require(cRefs >= 0);
@@ -130,7 +129,6 @@ bool SERVICES_Init(void)
 		fDBG = DBG_Init();
 		fDPC = DPC_Init();
 		fKFILE = KFILE_Init();
-		fLST = LST_Init();
 		/* fREG = REG_Init(); */
 		fSYNC = SYNC_Init();
 		fCLK  = CLK_Init();
@@ -138,7 +136,7 @@ bool SERVICES_Init(void)
 		fNTFY = NTFY_Init();
 
                fInit = fCFG && fCSL && fDBG && fDPC && fKFILE &&
-                       fLST && fMEM && fREG && fSYNC && fCLK && fUTIL;
+		       fMEM && fREG && fSYNC && fCLK && fUTIL;
 
 		if (!fInit) {
 			if (fNTFY)
@@ -156,9 +154,6 @@ bool SERVICES_Init(void)
 			if (fREG)
 				REG_Exit();
 
-			if (fLST)
-				LST_Exit();
-
 			if (fKFILE)
 				KFILE_Exit();
 
-- 
1.5.6.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] DSPBRIDGE: Get rid of services/list.c (step 2)
  2009-09-01 11:39 ` [PATCH 1/2] DSPBRIDGE: Get rid of services/list.c (step 1) Andy Shevchenko
@ 2009-09-01 11:39   ` Andy Shevchenko
  2009-09-02 17:27     ` [PATCH] dspbridge: use linux memory allocator directly Andy Shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2009-09-01 11:39 UTC (permalink / raw)
  To: linux-omap; +Cc: Andy Shevchenko

From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>

* Use native list_empty() method instead of LST_IsEmpty() inside list.c. Remove
  extra local variables.
* Move methods from list.c as inline functions in the list.h. Get rid of list.c
  at all.
* Use list_head natively instead of LST_ELEM in the list.h.

Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
---
 arch/arm/plat-omap/include/dspbridge/list.h |   86 ++++++++++---
 drivers/dsp/bridge/Kbuild                   |    2 +-
 drivers/dsp/bridge/services/list.c          |  187 ---------------------------
 3 files changed, 70 insertions(+), 205 deletions(-)
 delete mode 100644 drivers/dsp/bridge/services/list.c

diff --git a/arch/arm/plat-omap/include/dspbridge/list.h b/arch/arm/plat-omap/include/dspbridge/list.h
index f9bbd13..c9d9e49 100644
--- a/arch/arm/plat-omap/include/dspbridge/list.h
+++ b/arch/arm/plat-omap/include/dspbridge/list.h
@@ -49,14 +49,16 @@
 #define LIST_
 
 #include <dspbridge/host_os.h>
+/* MEM_Calloc(), MEM_NONPAGED, MEM_Free() */
+#include <dspbridge/mem.h>
 #include <linux/list.h>
 
 #define LST_ELEM            list_head
 #define LST_IsEmpty(l)      list_empty(&(l)->head)
 
-	struct LST_LIST {
-		struct LST_ELEM head;
-	} ;
+struct LST_LIST {
+	struct list_head head;
+};
 
 /*
  *  ======== LST_Create ========
@@ -80,7 +82,17 @@
  *      "empty" element, because its "next" and "prev" pointers point at
  *      the same location (the element itself).
  */
-	extern struct LST_LIST *LST_Create(void);
+static inline struct LST_LIST *LST_Create(void)
+{
+	struct LST_LIST *pList;
+
+	pList = (struct LST_LIST *) MEM_Calloc(sizeof(struct LST_LIST),
+		MEM_NONPAGED);
+	if (pList != NULL)
+		INIT_LIST_HEAD(&pList->head);
+
+	return pList;
+}
 
 /*
  *  ======== LST_Delete ========
@@ -102,7 +114,10 @@
  *      chain of list elements.  Calling this function on a non-empty list
  *      will cause a memory leak.
  */
-	extern void LST_Delete(IN struct LST_LIST *pList);
+static inline void LST_Delete(struct LST_LIST *pList)
+{
+	MEM_Free(pList);
+}
 
 /*
  *  ======== LST_First ========
@@ -118,7 +133,12 @@
  *      - pList != NULL.
  *  Ensures:
  */
-	extern struct LST_ELEM *LST_First(IN struct LST_LIST *pList);
+static inline struct list_head *LST_First(struct LST_LIST *pList)
+{
+	if (!list_empty(&pList->head))
+		return pList->head.next;
+	return NULL;
+}
 
 /*
  *  ======== LST_GetHead ========
@@ -148,7 +168,19 @@
  *      the head of the list, and the head of the list points backward (its
  *      "prev" pointer) to the tail of the list, this list is circular.
  */
-	extern struct LST_ELEM *LST_GetHead(IN struct LST_LIST *pList);
+static inline struct list_head *LST_GetHead(struct LST_LIST *pList)
+{
+	struct list_head *pElem;
+
+	if (list_empty(&pList->head))
+		return NULL;
+
+	pElem = pList->head.next;
+	pList->head.next = pElem->next;
+	pElem->next->prev = &pList->head;
+
+	return pElem;
+}
 
 /*
  *  ======== LST_InitElem ========
@@ -166,7 +198,13 @@
  *      of a list chain -- that would break the chain.
  *
  */
-	extern void LST_InitElem(IN struct LST_ELEM *pListElem);
+static inline void LST_InitElem(struct list_head *pElem)
+{
+	if (pElem) {
+		pElem->next = NULL;
+		pElem->prev = NULL;
+	}
+}
 
 /*
  *  ======== LST_InsertBefore ========
@@ -184,9 +222,12 @@
  *      - pElemExisting != NULL.
  *  Ensures:
  */
-	extern void LST_InsertBefore(IN struct LST_LIST *pList,
-				     IN struct LST_ELEM *pElem,
-				     IN struct LST_ELEM *pElemExisting);
+static inline void LST_InsertBefore(struct LST_LIST *pList,
+				    struct list_head *pElem,
+				    struct list_head *pElemExisting)
+{
+	list_add_tail(pElem, pElemExisting);
+}
 
 /*
  *  ======== LST_Next ========
@@ -204,8 +245,13 @@
  *      - pCurElem != NULL.
  *  Ensures:
  */
-	extern struct LST_ELEM *LST_Next(IN struct LST_LIST *pList,
-					 IN struct LST_ELEM *pCurElem);
+static inline struct list_head *LST_Next(struct LST_LIST *pList,
+					 struct list_head *pCurElem)
+{
+	if (!list_empty(&pList->head) && (pCurElem->next != &pList->head))
+		return pCurElem->next;
+	return NULL;
+}
 
 /*
  *  ======== LST_PutTail ========
@@ -235,8 +281,10 @@
  *      tail's "next" pointer points at the head of the list, and the head's
  *      "prev" pointer points at the tail of the list), the list is circular.
  */
-	extern void LST_PutTail(IN struct LST_LIST *pList,
-				IN struct LST_ELEM *pListElem);
+static inline void LST_PutTail(struct LST_LIST *pList, struct list_head *pElem)
+{
+	list_add_tail(pElem, &pList->head);
+}
 
 /*
  *  ======== LST_RemoveElem ========
@@ -253,7 +301,11 @@
  *      - pCurElem != NULL.
  *  Ensures:
  */
-extern void LST_RemoveElem(IN struct LST_LIST *pList,
-			   IN struct LST_ELEM *pCurElem);
+static inline void LST_RemoveElem(struct LST_LIST *pList,
+				  struct list_head *pCurElem)
+{
+	if (!list_empty(&pList->head))
+		list_del_init(pCurElem);
+}
 
 #endif				/* LIST_ */
diff --git a/drivers/dsp/bridge/Kbuild b/drivers/dsp/bridge/Kbuild
index 3432ff2..30bf633 100644
--- a/drivers/dsp/bridge/Kbuild
+++ b/drivers/dsp/bridge/Kbuild
@@ -1,7 +1,7 @@
 obj-$(CONFIG_MPU_BRIDGE)	+= bridgedriver.o
 
 libgen = gen/gb.o gen/gt.o gen/gs.o gen/gh.o gen/_gt_para.o gen/uuidutil.o
-libservices = services/csl.o services/mem.o services/list.o services/dpc.o \
+libservices = services/csl.o services/mem.o services/dpc.o \
                services/kfile.o services/sync.o \
 		services/clk.o services/cfg.o services/reg.o \
                services/regsup.o services/ntfy.o \
diff --git a/drivers/dsp/bridge/services/list.c b/drivers/dsp/bridge/services/list.c
deleted file mode 100644
index b215b68..0000000
--- a/drivers/dsp/bridge/services/list.c
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * list.c
- *
- * DSP-BIOS Bridge driver support functions for TI OMAP processors.
- *
- * Copyright (C) 2005-2006 Texas Instruments, Inc.
- *
- * This package is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-
-/*
- *  ======== listce.c ========
- *  Purpose
- *      Provides standard circular list handling functions.
- *
- *  Public Functions:
- *      LST_Create
- *      LST_Delete
- *      LST_First
- *      LST_GetHead
- *      LST_InitElem
- *      LST_InsertBefore
- *      LST_Next
- *      LST_PutTail
- *      LST_RemoveElem
- *
- *! Revision History
- *! ================
- *! 06-Mar-2002 jeh Don't set element self to NULL in LST_RemoveElem().
- *! 10-Aug-2000 ag: Added LST_InsertBefore().
- *! 03-Feb-2000 rr: Module init/exit is handled by SERVICES Init/Exit.
- *!		 GT Changes.
- *! 22-Nov-1999 kc: Added changes from code review.
- *! 10-Aug-1999 kc: Based on wsx-c18.
- *! 16-Jun-1997 gp: Removed unnecessary enabling/disabling of interrupts around
- *!                 list manipulation code.
- *! 22-Oct-1996 gp: Added LST_RemoveElem, and LST_First/LST_Next iterators.
- *! 10-Aug-1996 gp: Acquired from SMM for WinSPOX v. 1.1; renamed identifiers.
- */
-
-/*  ----------------------------------- DSP/BIOS Bridge */
-#include <dspbridge/std.h>
-#include <dspbridge/dbdefs.h>
-
-/*  ----------------------------------- OS Adaptation Layer */
-#include <dspbridge/mem.h>
-
-/*  ----------------------------------- This */
-#include <dspbridge/list.h>
-
-/*
- *  ======== LST_Create ========
- *  Purpose:
- *      Allocates and initializes a circular list.
- */
-struct LST_LIST *LST_Create(void)
-{
-	struct LST_LIST *pList;
-
-	pList = (struct LST_LIST *) MEM_Calloc(sizeof(struct LST_LIST),
-		MEM_NONPAGED);
-	if (pList != NULL) {
-		INIT_LIST_HEAD(&pList->head);
-	}
-
-	return pList;
-}
-
-/*
- *  ======== LST_Delete ========
- *  Purpose:
- *      Removes a list by freeing its control structure's memory space.
- */
-void LST_Delete(struct LST_LIST *pList)
-{
-	MEM_Free(pList);
-}
-
-/*
- *  ======== LST_First ========
- *  Purpose:
- *      Returns a pointer to the first element of the list, or NULL if the
- *      list is empty.
- */
-struct LST_ELEM *LST_First(struct LST_LIST *pList)
-{
-	struct LST_ELEM *pElem = NULL;
-
-	if (!LST_IsEmpty(pList))
-		pElem = pList->head.next;
-
-	return pElem;
-}
-
-/*
- *  ======== LST_GetHead ========
- *  Purpose:
- *      "Pops" the head off the list and returns a pointer to it.
- */
-struct LST_ELEM *LST_GetHead(struct LST_LIST *pList)
-{
-	struct LST_ELEM *pElem;
-
-	if (LST_IsEmpty(pList))
-		return NULL;
-
-	/* pElem is always valid because the list cannot be empty
-	 * at this point */
-	pElem = pList->head.next;
-	pList->head.next = pElem->next;
-	pElem->next->prev = &pList->head;
-
-	return pElem;
-}
-
-/*
- *  ======== LST_InitElem ========
- *  Purpose:
- *      Initializes a list element to default (cleared) values
- */
-void LST_InitElem(struct LST_ELEM *pElem)
-{
-	if (pElem) {
-		pElem->next = NULL;
-		pElem->prev = NULL;
-	}
-}
-
-/*
- *  ======== LST_InsertBefore ========
- *  Purpose:
- *      Insert the element before the existing element.
- */
-void LST_InsertBefore(struct LST_LIST *pList, struct LST_ELEM *pElem,
-		      struct LST_ELEM *pElemExisting)
-{
-	list_add_tail(pElem, pElemExisting);
-}
-
-/*
- *  ======== LST_Next ========
- *  Purpose:
- *      Returns a pointer to the next element of the list, or NULL if the
- *      next element is the head of the list or the list is empty.
- */
-struct LST_ELEM *LST_Next(struct LST_LIST *pList, struct LST_ELEM *pCurElem)
-{
-	struct LST_ELEM *pNextElem = NULL;
-
-	if (!LST_IsEmpty(pList)) {
-		if (pCurElem->next != &pList->head)
-			pNextElem = pCurElem->next;
-	}
-
-	return pNextElem;
-}
-
-/*
- *  ======== LST_PutTail ========
- *  Purpose:
- *      Adds the specified element to the tail of the list
- */
-void LST_PutTail(struct LST_LIST *pList, struct LST_ELEM *pElem)
-{
-	list_add_tail(pElem, &pList->head);
-}
-
-/*
- *  ======== LST_RemoveElem ========
- *  Purpose:
- *      Removes (unlinks) the given element from the list, if the list is not
- *      empty.  Does not free the list element.
- */
-void LST_RemoveElem(struct LST_LIST *pList, struct LST_ELEM *pCurElem)
-{
-	if (!LST_IsEmpty(pList)) {
-		list_del_init(pCurElem);
-	}
-}
-
-- 
1.5.6.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH] dspbridge: use linux memory allocator directly
  2009-09-01 11:39   ` [PATCH 2/2] DSPBRIDGE: Get rid of services/list.c (step 2) Andy Shevchenko
@ 2009-09-02 17:27     ` Andy Shevchenko
  2009-09-02 17:49       ` Imre Deak
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2009-09-02 17:27 UTC (permalink / raw)
  To: linux-omap@vger.kernel.org; +Cc: Andy Shevchenko

From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>

Instead of MEM_Calloc()/MEM_Free() use kzalloc()/kfree() calls. Thus we get rid
of mem.h dependency.

Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
---
 arch/arm/plat-omap/include/dspbridge/list.h |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/arm/plat-omap/include/dspbridge/list.h b/arch/arm/plat-omap/include/dspbridge/list.h
index c9d9e49..cda1d21 100644
--- a/arch/arm/plat-omap/include/dspbridge/list.h
+++ b/arch/arm/plat-omap/include/dspbridge/list.h
@@ -49,8 +49,8 @@
 #define LIST_
 
 #include <dspbridge/host_os.h>
-/* MEM_Calloc(), MEM_NONPAGED, MEM_Free() */
-#include <dspbridge/mem.h>
+#include <linux/types.h>
+#include <linux/slab.h>
 #include <linux/list.h>
 
 #define LST_ELEM            list_head
@@ -85,9 +85,9 @@ struct LST_LIST {
 static inline struct LST_LIST *LST_Create(void)
 {
 	struct LST_LIST *pList;
+	gfp_t flags = (in_atomic()) ? GFP_ATOMIC : GFP_KERNEL;
 
-	pList = (struct LST_LIST *) MEM_Calloc(sizeof(struct LST_LIST),
-		MEM_NONPAGED);
+	pList = (struct LST_LIST *) kzalloc(sizeof(struct LST_LIST), flags);
 	if (pList != NULL)
 		INIT_LIST_HEAD(&pList->head);
 
@@ -116,7 +116,8 @@ static inline struct LST_LIST *LST_Create(void)
  */
 static inline void LST_Delete(struct LST_LIST *pList)
 {
-	MEM_Free(pList);
+	if (pList != NULL)
+		kfree(pList);
 }
 
 /*
-- 
1.5.6.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] dspbridge: use linux memory allocator directly
  2009-09-02 17:27     ` [PATCH] dspbridge: use linux memory allocator directly Andy Shevchenko
@ 2009-09-02 17:49       ` Imre Deak
  2009-09-03  6:48         ` Andy Shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Imre Deak @ 2009-09-02 17:49 UTC (permalink / raw)
  To: ext Andy Shevchenko
  Cc: linux-omap@vger.kernel.org,
	Shevchenko Andriy (EXT-Teleca/Helsinki)

On Wed, Sep 02, 2009 at 07:27:10PM +0200, ext Andy Shevchenko wrote:
> From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
> 
> Instead of MEM_Calloc()/MEM_Free() use kzalloc()/kfree() calls. Thus we get rid
> of mem.h dependency.
> 
> Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
> ---
>  arch/arm/plat-omap/include/dspbridge/list.h |   11 ++++++-----
>  1 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm/plat-omap/include/dspbridge/list.h b/arch/arm/plat-omap/include/dspbridge/list.h
> index c9d9e49..cda1d21 100644
> --- a/arch/arm/plat-omap/include/dspbridge/list.h
> +++ b/arch/arm/plat-omap/include/dspbridge/list.h
> @@ -49,8 +49,8 @@
>  #define LIST_
>  
>  #include <dspbridge/host_os.h>
> -/* MEM_Calloc(), MEM_NONPAGED, MEM_Free() */
> -#include <dspbridge/mem.h>
> +#include <linux/types.h>
> +#include <linux/slab.h>
>  #include <linux/list.h>
>  
>  #define LST_ELEM            list_head
> @@ -85,9 +85,9 @@ struct LST_LIST {
>  static inline struct LST_LIST *LST_Create(void)
>  {
>  	struct LST_LIST *pList;
> +	gfp_t flags = (in_atomic()) ? GFP_ATOMIC : GFP_KERNEL;
>  
> -	pList = (struct LST_LIST *) MEM_Calloc(sizeof(struct LST_LIST),
> -		MEM_NONPAGED);
> +	pList = (struct LST_LIST *) kzalloc(sizeof(struct LST_LIST), flags);
>  	if (pList != NULL)
>  		INIT_LIST_HEAD(&pList->head);
>  
> @@ -116,7 +116,8 @@ static inline struct LST_LIST *LST_Create(void)
>   */
>  static inline void LST_Delete(struct LST_LIST *pList)
>  {
> -	MEM_Free(pList);
> +	if (pList != NULL)
> +		kfree(pList);

No need to check, since kfree does it for you.

--Imre


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] dspbridge: use linux memory allocator directly
  2009-09-02 17:49       ` Imre Deak
@ 2009-09-03  6:48         ` Andy Shevchenko
  2009-09-03  6:57           ` Felipe Balbi
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2009-09-03  6:48 UTC (permalink / raw)
  To: linux-omap; +Cc: Andy Shevchenko

From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>

Instead of MEM_Calloc()/MEM_Free() use kzalloc()/kfree() calls. Thus we get rid
of mem.h dependency.

Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
---
 arch/arm/plat-omap/include/dspbridge/list.h |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/arm/plat-omap/include/dspbridge/list.h b/arch/arm/plat-omap/include/dspbridge/list.h
index c9d9e49..cda1d21 100644
--- a/arch/arm/plat-omap/include/dspbridge/list.h
+++ b/arch/arm/plat-omap/include/dspbridge/list.h
@@ -49,8 +49,8 @@
 #define LIST_
 
 #include <dspbridge/host_os.h>
-/* MEM_Calloc(), MEM_NONPAGED, MEM_Free() */
-#include <dspbridge/mem.h>
+#include <linux/types.h>
+#include <linux/slab.h>
 #include <linux/list.h>
 
 #define LST_ELEM            list_head
@@ -85,9 +85,9 @@ struct LST_LIST {
 static inline struct LST_LIST *LST_Create(void)
 {
 	struct LST_LIST *pList;
+	gfp_t flags = (in_atomic()) ? GFP_ATOMIC : GFP_KERNEL;
 
-	pList = (struct LST_LIST *) MEM_Calloc(sizeof(struct LST_LIST),
-		MEM_NONPAGED);
+	pList = (struct LST_LIST *) kzalloc(sizeof(struct LST_LIST), flags);
 	if (pList != NULL)
 		INIT_LIST_HEAD(&pList->head);
 
@@ -116,7 +116,7 @@ static inline struct LST_LIST *LST_Create(void)
  */
 static inline void LST_Delete(struct LST_LIST *pList)
 {
-	MEM_Free(pList);
+	kfree(pList);
 }
 
 /*
-- 
1.5.6.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] dspbridge: use linux memory allocator directly
  2009-09-03  6:48         ` Andy Shevchenko
@ 2009-09-03  6:57           ` Felipe Balbi
  0 siblings, 0 replies; 7+ messages in thread
From: Felipe Balbi @ 2009-09-03  6:57 UTC (permalink / raw)
  To: ext Andy Shevchenko
  Cc: linux-omap@vger.kernel.org,
	Shevchenko Andriy (EXT-Teleca/Helsinki)

Hi,

On Thu, Sep 03, 2009 at 08:48:58AM +0200, ext Andy Shevchenko wrote:
> @@ -85,9 +85,9 @@ struct LST_LIST {
>  static inline struct LST_LIST *LST_Create(void)
>  {
>  	struct LST_LIST *pList;
> +	gfp_t flags = (in_atomic()) ? GFP_ATOMIC : GFP_KERNEL;
>  
> -	pList = (struct LST_LIST *) MEM_Calloc(sizeof(struct LST_LIST),
> -		MEM_NONPAGED);
> +	pList = (struct LST_LIST *) kzalloc(sizeof(struct LST_LIST), flags);

no need for casting either :-)

-- 
balbi

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-09-03  6:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-01 11:39 dspbridge: draft: get rid of services/list.c Andy Shevchenko
2009-09-01 11:39 ` [PATCH 1/2] DSPBRIDGE: Get rid of services/list.c (step 1) Andy Shevchenko
2009-09-01 11:39   ` [PATCH 2/2] DSPBRIDGE: Get rid of services/list.c (step 2) Andy Shevchenko
2009-09-02 17:27     ` [PATCH] dspbridge: use linux memory allocator directly Andy Shevchenko
2009-09-02 17:49       ` Imre Deak
2009-09-03  6:48         ` Andy Shevchenko
2009-09-03  6:57           ` Felipe Balbi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox