dspbridge: draft: get rid of services/list.c
Subsystems (2)
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:
<[email protected]>'
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 1/2 DSPBRIDGE: Get rid of services/list.c (step 1)
From: Andy Shevchenko <[email protected]>
* 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.
--- 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(-)
arch/arm/plat-omap/include/dspbridge/list.h +3 -40
@@ -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);
drivers/dsp/bridge/services/list.c +5 -103
199 lines not on this page · raw message
drivers/dsp/bridge/services/mem.c +0 -2
@@ -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
drivers/dsp/bridge/services/services.c +2 -7
@@ -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 ();
Signature · 1 line
1.5.6.5
PATCH 2/2 DSPBRIDGE: Get rid of services/list.c (step 2)
From: Andy Shevchenko <[email protected]>
* 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.
--- 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
arch/arm/plat-omap/include/dspbridge/list.h +69 -17
@@ -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_ */
drivers/dsp/bridge/Kbuild +1 -1
@@ -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 \
drivers/dsp/bridge/services/list.c deleted +0 -187
187 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 1/1 dspbridge: use linux memory allocator directly
From: Andy Shevchenko <[email protected]>
Instead of MEM_Calloc()/MEM_Free() use kzalloc()/kfree() calls. Thus we get rid of mem.h dependency.
--- arch/arm/plat-omap/include/dspbridge/list.h | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
arch/arm/plat-omap/include/dspbridge/list.h +6 -5
@@ -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); }/*
Signature · 1 line
1.5.6.5
Re: [PATCH] dspbridge: use linux memory allocator directly
Quoted 38 lines · ext Andy Shevchenko
From: Andy Shevchenko <[email protected]>
Instead of MEM_Calloc()/MEM_Free() use kzalloc()/kfree() calls. Thus we get rid of
mem.hdependency.Signed-off-by Andy Shevchenko <[email protected]>--- arch/arm/plat-omap/include/dspbridge/list.h | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)arch/arm/plat-omap/include/dspbridge/list.h +4
-4@@ -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);
arch/arm/plat-omap/include/dspbridge/list.h static inline struct LST_LIST *LST_Create(void) · line 120
Quoted 6 lines
arch/arm/plat-omap/include/dspbridge/list.h +2
-1@@ -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
PATCH 1/1 dspbridge: use linux memory allocator directly
From: Andy Shevchenko <[email protected]>
Instead of MEM_Calloc()/MEM_Free() use kzalloc()/kfree() calls. Thus we get rid of mem.h dependency.
--- arch/arm/plat-omap/include/dspbridge/list.h | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
arch/arm/plat-omap/include/dspbridge/list.h +5 -5
@@ -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); }/*
Signature · 1 line
1.5.6.5
Re: [PATCH] dspbridge: use linux memory allocator directly
Hi,
arch/arm/plat-omap/include/dspbridge/list.h struct LST_LIST { · line 90
Quoted 9 lines · ext Andy Shevchenko
arch/arm/plat-omap/include/dspbridge/list.h +2
-2@@ -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 :-)
Signature · 1 line
balbi