All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/12] staging: tidspbridge: various cleanups
@ 2010-11-05 15:13 Ionut Nicu
  2010-11-05 15:13 ` [PATCH v2 01/12] staging: tidspbridge: remove gs memory allocator Ionut Nicu
                   ` (12 more replies)
  0 siblings, 13 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

This set of patches replaces some of the redundant components of
the tidspbridge driver, such as:

* wrapper functions for kmalloc/kfree
* custom bitmap implementation
* custom linked list implementation (list_head wrapper)

with the standard linux kernel interfaces.

The patches also do some code reorganization for increasing readability.
Most of the changes reduce the code indentation level and simplify the code.
No functional changes were done.

There are many places in this driver that need this kind of cleanup, but
these patches only fix the functions that were touched while converting
the code to use linux bitmap and list_head.

Changes since v1:

* Split the bitmap patch into multiple patches
* Split the list_head patch into multiple patches

Ionut Nicu (12):
  staging: tidspbridge: remove gs memory allocator
  staging: tidspbridge: remove utildefs
  staging: tidspbridge: switch to linux bitmap API
  staging: tidspbridge: remove gb bitmap implementation
  staging: tidspbridge: rmgr/node.c code cleanup
  staging: tidspbridge: convert core to list_head
  staging: tidspbridge: convert pmgr to list_head
  staging: tidspbridge: convert rmgr to list_head
  staging: tidspbridge: remove custom linked list
  staging: tidspbridge: core code cleanup
  staging: tidspbridge: pmgr code cleanup
  staging: tidspbridge: rmgr code cleanup

 drivers/staging/tidspbridge/Makefile               |    2 +-
 drivers/staging/tidspbridge/TODO                   |    1 -
 drivers/staging/tidspbridge/core/_msg_sm.h         |   12 +-
 drivers/staging/tidspbridge/core/chnl_sm.c         |  634 +++++++---------
 drivers/staging/tidspbridge/core/io_sm.c           |  266 +++----
 drivers/staging/tidspbridge/core/msg_sm.c          |  601 ++++++---------
 drivers/staging/tidspbridge/gen/gb.c               |  166 -----
 drivers/staging/tidspbridge/gen/gh.c               |   38 +-
 drivers/staging/tidspbridge/gen/gs.c               |   88 ---
 .../tidspbridge/include/dspbridge/_chnl_sm.h       |    8 +-
 .../tidspbridge/include/dspbridge/cmmdefs.h        |    1 -
 drivers/staging/tidspbridge/include/dspbridge/gb.h |   79 --
 drivers/staging/tidspbridge/include/dspbridge/gs.h |   59 --
 .../staging/tidspbridge/include/dspbridge/list.h   |  225 ------
 .../staging/tidspbridge/include/dspbridge/sync.h   |    1 +
 .../tidspbridge/include/dspbridge/utildefs.h       |   39 -
 drivers/staging/tidspbridge/pmgr/cmm.c             |  531 +++++---------
 drivers/staging/tidspbridge/pmgr/dev.c             |   73 +--
 drivers/staging/tidspbridge/rmgr/drv.c             |  238 ++----
 drivers/staging/tidspbridge/rmgr/node.c            |  773 +++++++++-----------
 drivers/staging/tidspbridge/rmgr/proc.c            |    2 -
 drivers/staging/tidspbridge/rmgr/rmm.c             |  313 ++++-----
 22 files changed, 1449 insertions(+), 2701 deletions(-)
 delete mode 100644 drivers/staging/tidspbridge/gen/gb.c
 delete mode 100644 drivers/staging/tidspbridge/gen/gs.c
 delete mode 100644 drivers/staging/tidspbridge/include/dspbridge/gb.h
 delete mode 100644 drivers/staging/tidspbridge/include/dspbridge/gs.h
 delete mode 100644 drivers/staging/tidspbridge/include/dspbridge/list.h
 delete mode 100644 drivers/staging/tidspbridge/include/dspbridge/utildefs.h

-- 
1.7.2.3


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

* [PATCH v2 01/12] staging: tidspbridge: remove gs memory allocator
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
@ 2010-11-05 15:13 ` Ionut Nicu
  2010-11-05 15:13 ` [PATCH v2 02/12] staging: tidspbridge: remove utildefs Ionut Nicu
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

Remove unnecessary wrappers for linux kernel memory
allocation primitives.

Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
---
 drivers/staging/tidspbridge/Makefile               |    2 +-
 drivers/staging/tidspbridge/gen/gb.c               |   11 +--
 drivers/staging/tidspbridge/gen/gh.c               |   38 ++-------
 drivers/staging/tidspbridge/gen/gs.c               |   88 --------------------
 drivers/staging/tidspbridge/include/dspbridge/gs.h |   59 -------------
 5 files changed, 15 insertions(+), 183 deletions(-)
 delete mode 100644 drivers/staging/tidspbridge/gen/gs.c
 delete mode 100644 drivers/staging/tidspbridge/include/dspbridge/gs.h

diff --git a/drivers/staging/tidspbridge/Makefile b/drivers/staging/tidspbridge/Makefile
index 50decc2..aaf397f 100644
--- a/drivers/staging/tidspbridge/Makefile
+++ b/drivers/staging/tidspbridge/Makefile
@@ -1,6 +1,6 @@
 obj-$(CONFIG_TIDSPBRIDGE)	+= bridgedriver.o
 
-libgen = gen/gb.o gen/gs.o gen/gh.o gen/uuidutil.o
+libgen = gen/gb.o gen/gh.o gen/uuidutil.o
 libcore = core/chnl_sm.o core/msg_sm.o core/io_sm.o core/tiomap3430.o \
 		core/tiomap3430_pwr.o core/tiomap_io.o core/dsp-mmu.o \
 		core/ue_deh.o core/wdt.o core/dsp-clock.o core/sync.o
diff --git a/drivers/staging/tidspbridge/gen/gb.c b/drivers/staging/tidspbridge/gen/gb.c
index 9f59023..3c0e04c 100644
--- a/drivers/staging/tidspbridge/gen/gb.c
+++ b/drivers/staging/tidspbridge/gen/gb.c
@@ -19,7 +19,6 @@
 /*  ----------------------------------- DSP/BIOS Bridge */
 #include <linux/types.h>
 /*  ----------------------------------- This */
-#include <dspbridge/gs.h>
 #include <dspbridge/gb.h>
 
 struct gb_t_map {
@@ -52,17 +51,17 @@ struct gb_t_map *gb_create(u32 len)
 {
 	struct gb_t_map *map;
 	u32 i;
-	map = (struct gb_t_map *)gs_alloc(sizeof(struct gb_t_map));
+	map = kzalloc(sizeof(struct gb_t_map), GFP_KERNEL);
 	if (map != NULL) {
 		map->len = len;
 		map->wcnt = len / BITS_PER_LONG + 1;
-		map->words = (u32 *) gs_alloc(map->wcnt * sizeof(u32));
+		map->words = kzalloc(map->wcnt * sizeof(u32), GFP_KERNEL);
 		if (map->words != NULL) {
 			for (i = 0; i < map->wcnt; i++)
 				map->words[i] = 0L;
 
 		} else {
-			gs_frees(map, sizeof(struct gb_t_map));
+			kfree(map);
 			map = NULL;
 		}
 	}
@@ -78,8 +77,8 @@ struct gb_t_map *gb_create(u32 len)
 
 void gb_delete(struct gb_t_map *map)
 {
-	gs_frees(map->words, map->wcnt * sizeof(u32));
-	gs_frees(map, sizeof(struct gb_t_map));
+	kfree(map->words);
+	kfree(map);
 }
 
 /*
diff --git a/drivers/staging/tidspbridge/gen/gh.c b/drivers/staging/tidspbridge/gen/gh.c
index f72d943..cd72503 100644
--- a/drivers/staging/tidspbridge/gen/gh.c
+++ b/drivers/staging/tidspbridge/gen/gh.c
@@ -17,9 +17,6 @@
 #include <linux/types.h>
 
 #include <dspbridge/host_os.h>
-
-#include <dspbridge/gs.h>
-
 #include <dspbridge/gh.h>
 
 struct element {
@@ -37,8 +34,6 @@ struct gh_t_hash_tab {
 };
 
 static void noop(void *p);
-static s32 cur_init;
-static void myfree(void *ptr, s32 size);
 
 /*
  *  ======== gh_create ========
@@ -51,8 +46,7 @@ struct gh_t_hash_tab *gh_create(u16 max_bucket, u16 val_size,
 {
 	struct gh_t_hash_tab *hash_tab;
 	u16 i;
-	hash_tab =
-	    (struct gh_t_hash_tab *)gs_alloc(sizeof(struct gh_t_hash_tab));
+	hash_tab = kzalloc(sizeof(struct gh_t_hash_tab), GFP_KERNEL);
 	if (hash_tab == NULL)
 		return NULL;
 	hash_tab->max_bucket = max_bucket;
@@ -62,7 +56,7 @@ struct gh_t_hash_tab *gh_create(u16 max_bucket, u16 val_size,
 	hash_tab->delete = delete == NULL ? noop : delete;
 
 	hash_tab->buckets = (struct element **)
-	    gs_alloc(sizeof(struct element *) * max_bucket);
+	    kzalloc(sizeof(struct element *) * max_bucket, GFP_KERNEL);
 	if (hash_tab->buckets == NULL) {
 		gh_delete(hash_tab);
 		return NULL;
@@ -89,17 +83,14 @@ void gh_delete(struct gh_t_hash_tab *hash_tab)
 				     elem = next) {
 					next = elem->next;
 					(*hash_tab->delete) (elem->data);
-					myfree(elem,
-					       sizeof(struct element) - 1 +
-					       hash_tab->val_size);
+					kfree(elem);
 				}
 			}
 
-			myfree(hash_tab->buckets, sizeof(struct element *)
-			       * hash_tab->max_bucket);
+			kfree(hash_tab->buckets);
 		}
 
-		myfree(hash_tab, sizeof(struct gh_t_hash_tab));
+		kfree(hash_tab);
 	}
 }
 
@@ -109,9 +100,7 @@ void gh_delete(struct gh_t_hash_tab *hash_tab)
 
 void gh_exit(void)
 {
-	if (cur_init-- == 1)
-		gs_exit();
-
+	/* Do nothing */
 }
 
 /*
@@ -138,8 +127,7 @@ void *gh_find(struct gh_t_hash_tab *hash_tab, void *key)
 
 void gh_init(void)
 {
-	if (cur_init++ == 0)
-		gs_init();
+	/* Do nothing */
 }
 
 /*
@@ -152,8 +140,8 @@ void *gh_insert(struct gh_t_hash_tab *hash_tab, void *key, void *value)
 	u16 i;
 	char *src, *dst;
 
-	elem = (struct element *)gs_alloc(sizeof(struct element) - 1 +
-					  hash_tab->val_size);
+	elem = kzalloc(sizeof(struct element) - 1 + hash_tab->val_size,
+			GFP_KERNEL);
 	if (elem != NULL) {
 
 		dst = (char *)elem->data;
@@ -180,14 +168,6 @@ static void noop(void *p)
 	p = p;			/* stifle compiler warning */
 }
 
-/*
- *  ======== myfree ========
- */
-static void myfree(void *ptr, s32 size)
-{
-	gs_free(ptr);
-}
-
 #ifdef CONFIG_TIDSPBRIDGE_BACKTRACE
 /**
  * gh_iterate() - This function goes through all the elements in the hash table
diff --git a/drivers/staging/tidspbridge/gen/gs.c b/drivers/staging/tidspbridge/gen/gs.c
deleted file mode 100644
index 8335bf5..0000000
--- a/drivers/staging/tidspbridge/gen/gs.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * gs.c
- *
- * DSP-BIOS Bridge driver support functions for TI OMAP processors.
- *
- * General storage memory allocator services.
- *
- * 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.
- */
-
-#include <linux/types.h>
-/*  ----------------------------------- DSP/BIOS Bridge */
-#include <dspbridge/dbdefs.h>
-
-/*  ----------------------------------- This */
-#include <dspbridge/gs.h>
-
-#include <linux/slab.h>
-
-/*  ----------------------------------- Globals */
-static u32 cumsize;
-
-/*
- *  ======== gs_alloc ========
- *  purpose:
- *      Allocates memory of the specified size.
- */
-void *gs_alloc(u32 size)
-{
-	void *p;
-
-	p = kzalloc(size, GFP_KERNEL);
-	if (p == NULL)
-		return NULL;
-	cumsize += size;
-	return p;
-}
-
-/*
- *  ======== gs_exit ========
- *  purpose:
- *      Discontinue the usage of the GS module.
- */
-void gs_exit(void)
-{
-	/* Do nothing */
-}
-
-/*
- *  ======== gs_free ========
- *  purpose:
- *      Frees the memory.
- */
-void gs_free(void *ptr)
-{
-	kfree(ptr);
-	/* ack! no size info */
-	/* cumsize -= size; */
-}
-
-/*
- *  ======== gs_frees ========
- *  purpose:
- *      Frees the memory.
- */
-void gs_frees(void *ptr, u32 size)
-{
-	kfree(ptr);
-	cumsize -= size;
-}
-
-/*
- *  ======== gs_init ========
- *  purpose:
- *      Initializes the GS module.
- */
-void gs_init(void)
-{
-	/* Do nothing */
-}
diff --git a/drivers/staging/tidspbridge/include/dspbridge/gs.h b/drivers/staging/tidspbridge/include/dspbridge/gs.h
deleted file mode 100644
index f32d8d9..0000000
--- a/drivers/staging/tidspbridge/include/dspbridge/gs.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * gs.h
- *
- * DSP-BIOS Bridge driver support functions for TI OMAP processors.
- *
- * Memory allocation/release wrappers.  This module allows clients to
- * avoid OS spacific issues related to memory allocation.  It also provides
- * simple diagnostic capabilities to assist in the detection of memory
- * leaks.
- *
- * 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.
- */
-
-#ifndef GS_
-#define GS_
-
-/*
- *  ======== gs_alloc ========
- *  Alloc size bytes of space.  Returns pointer to space
- *  allocated, otherwise NULL.
- */
-extern void *gs_alloc(u32 size);
-
-/*
- *  ======== gs_exit ========
- *  Module exit.  Do not change to "#define gs_init()"; in
- *  some environments this operation must actually do some work!
- */
-extern void gs_exit(void);
-
-/*
- *  ======== gs_free ========
- *  Free space allocated by gs_alloc() or GS_calloc().
- */
-extern void gs_free(void *ptr);
-
-/*
- *  ======== gs_frees ========
- *  Free space allocated by gs_alloc() or GS_calloc() and assert that
- *  the size of the allocation is size bytes.
- */
-extern void gs_frees(void *ptr, u32 size);
-
-/*
- *  ======== gs_init ========
- *  Module initialization.  Do not change to "#define gs_init()"; in
- *  some environments this operation must actually do some work!
- */
-extern void gs_init(void);
-
-#endif /*GS_ */
-- 
1.7.2.3


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

* [PATCH v2 02/12] staging: tidspbridge: remove utildefs
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
  2010-11-05 15:13 ` [PATCH v2 01/12] staging: tidspbridge: remove gs memory allocator Ionut Nicu
@ 2010-11-05 15:13 ` Ionut Nicu
  2010-11-05 15:13 ` [PATCH v2 03/12] staging: tidspbridge: switch to linux bitmap API Ionut Nicu
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

Remove a header file that was not very useful to
the dspbridge driver.

Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
---
 .../tidspbridge/include/dspbridge/utildefs.h       |   39 --------------------
 drivers/staging/tidspbridge/pmgr/cmm.c             |    9 +----
 2 files changed, 1 insertions(+), 47 deletions(-)
 delete mode 100644 drivers/staging/tidspbridge/include/dspbridge/utildefs.h

diff --git a/drivers/staging/tidspbridge/include/dspbridge/utildefs.h b/drivers/staging/tidspbridge/include/dspbridge/utildefs.h
deleted file mode 100644
index 8fe5414..0000000
--- a/drivers/staging/tidspbridge/include/dspbridge/utildefs.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * utildefs.h
- *
- * DSP-BIOS Bridge driver support functions for TI OMAP processors.
- *
- * Global UTIL constants and types, shared between DSP API and DSPSYS.
- *
- * 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.
- */
-
-#ifndef UTILDEFS_
-#define UTILDEFS_
-
-/* constants taken from configmg.h */
-#define UTIL_MAXMEMREGS     9
-#define UTIL_MAXIOPORTS     20
-#define UTIL_MAXIRQS        7
-#define UTIL_MAXDMACHNLS    7
-
-/* misc. constants */
-#define UTIL_MAXARGVS       10
-
-/* Platform specific important info */
-struct util_sysinfo {
-	/* Granularity of page protection; usually 1k or 4k */
-	u32 dw_page_size;
-	u32 dw_allocation_granularity;	/* VM granularity, usually 64K */
-	u32 dw_number_of_processors;	/* Used as sanity check */
-};
-
-#endif /* UTILDEFS_ */
diff --git a/drivers/staging/tidspbridge/pmgr/cmm.c b/drivers/staging/tidspbridge/pmgr/cmm.c
index 93a7c4f..8dbdd20 100644
--- a/drivers/staging/tidspbridge/pmgr/cmm.c
+++ b/drivers/staging/tidspbridge/pmgr/cmm.c
@@ -40,7 +40,6 @@
 /*  ----------------------------------- OS Adaptation Layer */
 #include <dspbridge/list.h>
 #include <dspbridge/sync.h>
-#include <dspbridge/utildefs.h>
 
 /*  ----------------------------------- Platform Manager */
 #include <dspbridge/dev.h>
@@ -245,7 +244,6 @@ int cmm_create(struct cmm_object **ph_cmm_mgr,
 {
 	struct cmm_object *cmm_obj = NULL;
 	int status = 0;
-	struct util_sysinfo sys_info;
 
 	DBC_REQUIRE(refs > 0);
 	DBC_REQUIRE(ph_cmm_mgr != NULL);
@@ -261,12 +259,7 @@ int cmm_create(struct cmm_object **ph_cmm_mgr,
 		DBC_ASSERT(mgr_attrts->ul_min_block_size >= 4);
 		/* save away smallest block allocation for this cmm mgr */
 		cmm_obj->ul_min_block_size = mgr_attrts->ul_min_block_size;
-		/* save away the systems memory page size */
-		sys_info.dw_page_size = PAGE_SIZE;
-		sys_info.dw_allocation_granularity = PAGE_SIZE;
-		sys_info.dw_number_of_processors = 1;
-
-		cmm_obj->dw_page_size = sys_info.dw_page_size;
+		cmm_obj->dw_page_size = PAGE_SIZE;
 
 		/* Note: DSP SM seg table(aDSPSMSegTab[]) zero'd by
 		 * MEM_ALLOC_OBJECT */
-- 
1.7.2.3


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

* [PATCH v2 03/12] staging: tidspbridge: switch to linux bitmap API
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
  2010-11-05 15:13 ` [PATCH v2 01/12] staging: tidspbridge: remove gs memory allocator Ionut Nicu
  2010-11-05 15:13 ` [PATCH v2 02/12] staging: tidspbridge: remove utildefs Ionut Nicu
@ 2010-11-05 15:13 ` Ionut Nicu
  2010-11-05 15:13 ` [PATCH v2 04/12] staging: tidspbridge: remove gb bitmap implementation Ionut Nicu
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

Replace the tidspbridge generic bitmap operations
with the linux standard bitmap implementation.

Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
---
 drivers/staging/tidspbridge/rmgr/node.c |  166 ++++++++++++++-----------------
 1 files changed, 74 insertions(+), 92 deletions(-)

diff --git a/drivers/staging/tidspbridge/rmgr/node.c b/drivers/staging/tidspbridge/rmgr/node.c
index a660247..e48ddba 100644
--- a/drivers/staging/tidspbridge/rmgr/node.c
+++ b/drivers/staging/tidspbridge/rmgr/node.c
@@ -17,6 +17,7 @@
  */
 
 #include <linux/types.h>
+#include <linux/bitmap.h>
 /*  ----------------------------------- Host OS */
 #include <dspbridge/host_os.h>
 
@@ -50,7 +51,6 @@
 #include <dspbridge/dspioctl.h>
 
 /*  ----------------------------------- Others */
-#include <dspbridge/gb.h>
 #include <dspbridge/uuidutil.h>
 
 /*  ----------------------------------- This */
@@ -131,11 +131,14 @@ struct node_mgr {
 	struct lst_list *node_list;	/* List of all allocated nodes */
 	u32 num_nodes;		/* Number of nodes in node_list */
 	u32 num_created;	/* Number of nodes *created* on DSP */
-	struct gb_t_map *pipe_map;	/* Pipe connection bit map */
-	struct gb_t_map *pipe_done_map;	/* Pipes that are half free */
-	struct gb_t_map *chnl_map;	/* Channel allocation bit map */
-	struct gb_t_map *dma_chnl_map;	/* DMA Channel allocation bit map */
-	struct gb_t_map *zc_chnl_map;	/* Zero-Copy Channel alloc bit map */
+	DECLARE_BITMAP(pipe_map, MAXPIPES); /* Pipe connection bitmap */
+	DECLARE_BITMAP(pipe_done_map, MAXPIPES); /* Pipes that are half free */
+	/* Channel allocation bitmap */
+	DECLARE_BITMAP(chnl_map, CHNL_MAXCHANNELS);
+	/* DMA Channel allocation bitmap */
+	DECLARE_BITMAP(dma_chnl_map, CHNL_MAXCHANNELS);
+	/* Zero-Copy Channel alloc bitmap */
+	DECLARE_BITMAP(zc_chnl_map, CHNL_MAXCHANNELS);
 	struct ntfy_object *ntfy_obj;	/* Manages registered notifications */
 	struct mutex node_mgr_lock;	/* For critical sections */
 	u32 ul_fxn_addrs[NUMRMSFXNS];	/* RMS function addresses */
@@ -820,8 +823,8 @@ int node_connect(struct node_object *node1, u32 stream1,
 	struct node_object *dev_node_obj;
 	struct node_object *hnode;
 	struct stream_chnl *pstream;
-	u32 pipe_id = GB_NOBITS;
-	u32 chnl_id = GB_NOBITS;
+	u32 pipe_id;
+	u32 chnl_id;
 	s8 chnl_mode;
 	u32 dw_length;
 	int status = 0;
@@ -924,10 +927,11 @@ int node_connect(struct node_object *node1, u32 stream1,
 				      && (node2_type == NODE_TASK
 					  || node2_type == NODE_DAISSOCKET))) {
 		/* Find available pipe */
-		pipe_id = gb_findandset(hnode_mgr->pipe_map);
-		if (pipe_id == GB_NOBITS) {
+		pipe_id = find_first_zero_bit(hnode_mgr->pipe_map, MAXPIPES);
+		if (pipe_id == MAXPIPES) {
 			status = -ECONNREFUSED;
 		} else {
+			set_bit(pipe_id, hnode_mgr->pipe_map);
 			node1->outputs[stream1].type = NODECONNECT;
 			node2->inputs[stream2].type = NODECONNECT;
 			node1->outputs[stream1].dev_id = pipe_id;
@@ -944,7 +948,7 @@ int node_connect(struct node_object *node1, u32 stream1,
 
 				output->sz_device = NULL;
 				input->sz_device = NULL;
-				gb_clear(hnode_mgr->pipe_map, pipe_id);
+				clear_bit(pipe_id, hnode_mgr->pipe_map);
 				status = -ENOMEM;
 			} else {
 				/* Copy "/dbpipe<pipId>" name to device names */
@@ -969,34 +973,47 @@ int node_connect(struct node_object *node1, u32 stream1,
 		 *  called for this node. */
 		if (pattrs) {
 			if (pattrs->strm_mode == STRMMODE_RDMA) {
-				chnl_id =
-				    gb_findandset(hnode_mgr->dma_chnl_map);
+				chnl_id = find_first_zero_bit(
+						hnode_mgr->dma_chnl_map,
+						CHNL_MAXCHANNELS);
 				/* dma chans are 2nd transport chnl set
 				 * ids(e.g. 16-31) */
-				(chnl_id != GB_NOBITS) ?
-				    (chnl_id =
-				     chnl_id +
-				     hnode_mgr->ul_num_chnls) : chnl_id;
+				if (chnl_id != CHNL_MAXCHANNELS) {
+					set_bit(chnl_id,
+						hnode_mgr->dma_chnl_map);
+					chnl_id = chnl_id +
+						hnode_mgr->ul_num_chnls;
+				}
 			} else if (pattrs->strm_mode == STRMMODE_ZEROCOPY) {
-				chnl_id = gb_findandset(hnode_mgr->zc_chnl_map);
+				chnl_id = find_first_zero_bit(
+						hnode_mgr->zc_chnl_map,
+						CHNL_MAXCHANNELS);
 				/* zero-copy chans are 3nd transport set
 				 * (e.g. 32-47) */
-				(chnl_id != GB_NOBITS) ? (chnl_id = chnl_id +
-							  (2 *
-							   hnode_mgr->
-							   ul_num_chnls))
-				    : chnl_id;
+				if (chnl_id != CHNL_MAXCHANNELS) {
+					set_bit(chnl_id,
+						hnode_mgr->zc_chnl_map);
+					chnl_id = chnl_id +
+						(2 * hnode_mgr->ul_num_chnls);
+				}
 			} else {	/* must be PROCCOPY */
 				DBC_ASSERT(pattrs->strm_mode ==
 					   STRMMODE_PROCCOPY);
-				chnl_id = gb_findandset(hnode_mgr->chnl_map);
+				chnl_id = find_first_zero_bit(
+						hnode_mgr->chnl_map,
+						CHNL_MAXCHANNELS);
 				/* e.g. 0-15 */
+				if (chnl_id != CHNL_MAXCHANNELS)
+					set_bit(chnl_id, hnode_mgr->chnl_map);
 			}
 		} else {
 			/* default to PROCCOPY */
-			chnl_id = gb_findandset(hnode_mgr->chnl_map);
+			chnl_id = find_first_zero_bit(hnode_mgr->chnl_map,
+					CHNL_MAXCHANNELS);
+			if (chnl_id != CHNL_MAXCHANNELS)
+				set_bit(chnl_id, hnode_mgr->chnl_map);
 		}
-		if (chnl_id == GB_NOBITS) {
+		if (chnl_id == CHNL_MAXCHANNELS) {
 			status = -ECONNREFUSED;
 			goto func_cont2;
 		}
@@ -1006,18 +1023,19 @@ int node_connect(struct node_object *node1, u32 stream1,
 
 		if (pattrs) {
 			if (pattrs->strm_mode == STRMMODE_RDMA) {
-				gb_clear(hnode_mgr->dma_chnl_map, chnl_id -
-					 hnode_mgr->ul_num_chnls);
+				clear_bit(chnl_id - hnode_mgr->ul_num_chnls,
+						hnode_mgr->dma_chnl_map);
 			} else if (pattrs->strm_mode == STRMMODE_ZEROCOPY) {
-				gb_clear(hnode_mgr->zc_chnl_map, chnl_id -
-					 (2 * hnode_mgr->ul_num_chnls));
+				clear_bit(chnl_id -
+						(2 * hnode_mgr->ul_num_chnls),
+						hnode_mgr->zc_chnl_map);
 			} else {
 				DBC_ASSERT(pattrs->strm_mode ==
 					   STRMMODE_PROCCOPY);
-				gb_clear(hnode_mgr->chnl_map, chnl_id);
+				clear_bit(chnl_id, hnode_mgr->chnl_map);
 			}
 		} else {
-			gb_clear(hnode_mgr->chnl_map, chnl_id);
+			clear_bit(chnl_id, hnode_mgr->chnl_map);
 		}
 		status = -ENOMEM;
 func_cont2:
@@ -1294,22 +1312,14 @@ int node_create_mgr(struct node_mgr **node_man,
 	if (node_mgr_obj) {
 		node_mgr_obj->hdev_obj = hdev_obj;
 		node_mgr_obj->node_list = kzalloc(sizeof(struct lst_list),
-							GFP_KERNEL);
-		node_mgr_obj->pipe_map = gb_create(MAXPIPES);
-		node_mgr_obj->pipe_done_map = gb_create(MAXPIPES);
-		if (node_mgr_obj->node_list == NULL
-		    || node_mgr_obj->pipe_map == NULL
-		    || node_mgr_obj->pipe_done_map == NULL) {
-			status = -ENOMEM;
-		} else {
-			INIT_LIST_HEAD(&node_mgr_obj->node_list->head);
-			node_mgr_obj->ntfy_obj = kmalloc(
+				GFP_KERNEL);
+		INIT_LIST_HEAD(&node_mgr_obj->node_list->head);
+		node_mgr_obj->ntfy_obj = kmalloc(
 				sizeof(struct ntfy_object), GFP_KERNEL);
-			if (node_mgr_obj->ntfy_obj)
-				ntfy_init(node_mgr_obj->ntfy_obj);
-			else
-				status = -ENOMEM;
-		}
+		if (node_mgr_obj->ntfy_obj)
+			ntfy_init(node_mgr_obj->ntfy_obj);
+		else
+			status = -ENOMEM;
 		node_mgr_obj->num_created = 0;
 	} else {
 		status = -ENOMEM;
@@ -1345,27 +1355,14 @@ int node_create_mgr(struct node_mgr **node_man,
 		/* Get msg_ctrl queue manager */
 		dev_get_msg_mgr(hdev_obj, &node_mgr_obj->msg_mgr_obj);
 		mutex_init(&node_mgr_obj->node_mgr_lock);
-		node_mgr_obj->chnl_map = gb_create(node_mgr_obj->ul_num_chnls);
-		/* dma chnl map. ul_num_chnls is # per transport */
-		node_mgr_obj->dma_chnl_map =
-		    gb_create(node_mgr_obj->ul_num_chnls);
-		node_mgr_obj->zc_chnl_map =
-		    gb_create(node_mgr_obj->ul_num_chnls);
-		if ((node_mgr_obj->chnl_map == NULL)
-		    || (node_mgr_obj->dma_chnl_map == NULL)
-		    || (node_mgr_obj->zc_chnl_map == NULL)) {
-			status = -ENOMEM;
-		} else {
-			/* Block out reserved channels */
-			for (i = 0; i < node_mgr_obj->ul_chnl_offset; i++)
-				gb_set(node_mgr_obj->chnl_map, i);
+		/* Block out reserved channels */
+		for (i = 0; i < node_mgr_obj->ul_chnl_offset; i++)
+			set_bit(i, node_mgr_obj->chnl_map);
 
-			/* Block out channels reserved for RMS */
-			gb_set(node_mgr_obj->chnl_map,
-			       node_mgr_obj->ul_chnl_offset);
-			gb_set(node_mgr_obj->chnl_map,
-			       node_mgr_obj->ul_chnl_offset + 1);
-		}
+		/* Block out channels reserved for RMS */
+		set_bit(node_mgr_obj->ul_chnl_offset, node_mgr_obj->chnl_map);
+		set_bit(node_mgr_obj->ul_chnl_offset + 1,
+				node_mgr_obj->chnl_map);
 	}
 	if (!status) {
 		/* NO RM Server on the IVA */
@@ -2613,21 +2610,6 @@ static void delete_node_mgr(struct node_mgr *hnode_mgr)
 			kfree(hnode_mgr->ntfy_obj);
 		}
 
-		if (hnode_mgr->pipe_map)
-			gb_delete(hnode_mgr->pipe_map);
-
-		if (hnode_mgr->pipe_done_map)
-			gb_delete(hnode_mgr->pipe_done_map);
-
-		if (hnode_mgr->chnl_map)
-			gb_delete(hnode_mgr->chnl_map);
-
-		if (hnode_mgr->dma_chnl_map)
-			gb_delete(hnode_mgr->dma_chnl_map);
-
-		if (hnode_mgr->zc_chnl_map)
-			gb_delete(hnode_mgr->zc_chnl_map);
-
 		if (hnode_mgr->disp_obj)
 			disp_delete(hnode_mgr->disp_obj);
 
@@ -2742,25 +2724,25 @@ static void free_stream(struct node_mgr *hnode_mgr, struct stream_chnl stream)
 {
 	/* Free up the pipe id unless other node has not yet been deleted. */
 	if (stream.type == NODECONNECT) {
-		if (gb_test(hnode_mgr->pipe_done_map, stream.dev_id)) {
+		if (test_bit(stream.dev_id, hnode_mgr->pipe_done_map)) {
 			/* The other node has already been deleted */
-			gb_clear(hnode_mgr->pipe_done_map, stream.dev_id);
-			gb_clear(hnode_mgr->pipe_map, stream.dev_id);
+			clear_bit(stream.dev_id, hnode_mgr->pipe_done_map);
+			clear_bit(stream.dev_id, hnode_mgr->pipe_map);
 		} else {
 			/* The other node has not been deleted yet */
-			gb_set(hnode_mgr->pipe_done_map, stream.dev_id);
+			set_bit(stream.dev_id, hnode_mgr->pipe_done_map);
 		}
 	} else if (stream.type == HOSTCONNECT) {
 		if (stream.dev_id < hnode_mgr->ul_num_chnls) {
-			gb_clear(hnode_mgr->chnl_map, stream.dev_id);
+			clear_bit(stream.dev_id, hnode_mgr->chnl_map);
 		} else if (stream.dev_id < (2 * hnode_mgr->ul_num_chnls)) {
 			/* dsp-dma */
-			gb_clear(hnode_mgr->dma_chnl_map, stream.dev_id -
-				 (1 * hnode_mgr->ul_num_chnls));
+			clear_bit(stream.dev_id - (1 * hnode_mgr->ul_num_chnls),
+					hnode_mgr->dma_chnl_map);
 		} else if (stream.dev_id < (3 * hnode_mgr->ul_num_chnls)) {
 			/* zero-copy */
-			gb_clear(hnode_mgr->zc_chnl_map, stream.dev_id -
-				 (2 * hnode_mgr->ul_num_chnls));
+			clear_bit(stream.dev_id - (2 * hnode_mgr->ul_num_chnls),
+					hnode_mgr->zc_chnl_map);
 		}
 	}
 }
-- 
1.7.2.3


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

* [PATCH v2 04/12] staging: tidspbridge: remove gb bitmap implementation
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
                   ` (2 preceding siblings ...)
  2010-11-05 15:13 ` [PATCH v2 03/12] staging: tidspbridge: switch to linux bitmap API Ionut Nicu
@ 2010-11-05 15:13 ` Ionut Nicu
  2010-11-05 15:13 ` [PATCH v2 05/12] staging: tidspbridge: rmgr/node.c code cleanup Ionut Nicu
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

Now that all users of gb have been converted to the
standard linux bitmap API, we can remove it from the
gen library.

Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
---
 drivers/staging/tidspbridge/Makefile               |    2 +-
 drivers/staging/tidspbridge/gen/gb.c               |  165 --------------------
 drivers/staging/tidspbridge/include/dspbridge/gb.h |   79 ----------
 3 files changed, 1 insertions(+), 245 deletions(-)
 delete mode 100644 drivers/staging/tidspbridge/gen/gb.c
 delete mode 100644 drivers/staging/tidspbridge/include/dspbridge/gb.h

diff --git a/drivers/staging/tidspbridge/Makefile b/drivers/staging/tidspbridge/Makefile
index aaf397f..6080e7e 100644
--- a/drivers/staging/tidspbridge/Makefile
+++ b/drivers/staging/tidspbridge/Makefile
@@ -1,6 +1,6 @@
 obj-$(CONFIG_TIDSPBRIDGE)	+= bridgedriver.o
 
-libgen = gen/gb.o gen/gh.o gen/uuidutil.o
+libgen = gen/gh.o gen/uuidutil.o
 libcore = core/chnl_sm.o core/msg_sm.o core/io_sm.o core/tiomap3430.o \
 		core/tiomap3430_pwr.o core/tiomap_io.o core/dsp-mmu.o \
 		core/ue_deh.o core/wdt.o core/dsp-clock.o core/sync.o
diff --git a/drivers/staging/tidspbridge/gen/gb.c b/drivers/staging/tidspbridge/gen/gb.c
deleted file mode 100644
index 3c0e04c..0000000
--- a/drivers/staging/tidspbridge/gen/gb.c
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * gb.c
- *
- * DSP-BIOS Bridge driver support functions for TI OMAP processors.
- *
- * Generic bitmap operations.
- *
- * 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.
- */
-
-/*  ----------------------------------- DSP/BIOS Bridge */
-#include <linux/types.h>
-/*  ----------------------------------- This */
-#include <dspbridge/gb.h>
-
-struct gb_t_map {
-	u32 len;
-	u32 wcnt;
-	u32 *words;
-};
-
-/*
- *  ======== gb_clear ========
- *  purpose:
- *      Clears a bit in the bit map.
- */
-
-void gb_clear(struct gb_t_map *map, u32 bitn)
-{
-	u32 mask;
-
-	mask = 1L << (bitn % BITS_PER_LONG);
-	map->words[bitn / BITS_PER_LONG] &= ~mask;
-}
-
-/*
- *  ======== gb_create ========
- *  purpose:
- *      Creates a bit map.
- */
-
-struct gb_t_map *gb_create(u32 len)
-{
-	struct gb_t_map *map;
-	u32 i;
-	map = kzalloc(sizeof(struct gb_t_map), GFP_KERNEL);
-	if (map != NULL) {
-		map->len = len;
-		map->wcnt = len / BITS_PER_LONG + 1;
-		map->words = kzalloc(map->wcnt * sizeof(u32), GFP_KERNEL);
-		if (map->words != NULL) {
-			for (i = 0; i < map->wcnt; i++)
-				map->words[i] = 0L;
-
-		} else {
-			kfree(map);
-			map = NULL;
-		}
-	}
-
-	return map;
-}
-
-/*
- *  ======== gb_delete ========
- *  purpose:
- *      Frees a bit map.
- */
-
-void gb_delete(struct gb_t_map *map)
-{
-	kfree(map->words);
-	kfree(map);
-}
-
-/*
- *  ======== gb_findandset ========
- *  purpose:
- *      Finds a free bit and sets it.
- */
-u32 gb_findandset(struct gb_t_map *map)
-{
-	u32 bitn;
-
-	bitn = gb_minclear(map);
-
-	if (bitn != GB_NOBITS)
-		gb_set(map, bitn);
-
-	return bitn;
-}
-
-/*
- *  ======== gb_minclear ========
- *  purpose:
- *      returns the location of the first unset bit in the bit map.
- */
-u32 gb_minclear(struct gb_t_map *map)
-{
-	u32 bit_location = 0;
-	u32 bit_acc = 0;
-	u32 i;
-	u32 bit;
-	u32 *word;
-
-	for (word = map->words, i = 0; i < map->wcnt; word++, i++) {
-		if (~*word) {
-			for (bit = 0; bit < BITS_PER_LONG; bit++, bit_acc++) {
-				if (bit_acc == map->len)
-					return GB_NOBITS;
-
-				if (~*word & (1L << bit)) {
-					bit_location = i * BITS_PER_LONG + bit;
-					return bit_location;
-				}
-
-			}
-		} else {
-			bit_acc += BITS_PER_LONG;
-		}
-	}
-
-	return GB_NOBITS;
-}
-
-/*
- *  ======== gb_set ========
- *  purpose:
- *      Sets a bit in the bit map.
- */
-
-void gb_set(struct gb_t_map *map, u32 bitn)
-{
-	u32 mask;
-
-	mask = 1L << (bitn % BITS_PER_LONG);
-	map->words[bitn / BITS_PER_LONG] |= mask;
-}
-
-/*
- *  ======== gb_test ========
- *  purpose:
- *      Returns true if the bit is set in the specified location.
- */
-
-bool gb_test(struct gb_t_map *map, u32 bitn)
-{
-	bool state;
-	u32 mask;
-	u32 word;
-
-	mask = 1L << (bitn % BITS_PER_LONG);
-	word = map->words[bitn / BITS_PER_LONG];
-	state = word & mask ? true : false;
-
-	return state;
-}
diff --git a/drivers/staging/tidspbridge/include/dspbridge/gb.h b/drivers/staging/tidspbridge/include/dspbridge/gb.h
deleted file mode 100644
index fda783a..0000000
--- a/drivers/staging/tidspbridge/include/dspbridge/gb.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * gb.h
- *
- * DSP-BIOS Bridge driver support functions for TI OMAP processors.
- *
- * Generic bitmap manager.
- *
- * 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.
- */
-
-#ifndef GB_
-#define GB_
-
-#define GB_NOBITS (~0)
-#include <dspbridge/host_os.h>
-
-struct gb_t_map;
-
-/*
- *  ======== gb_clear ========
- *  Clear the bit in position bitn in the bitmap map.  Bit positions are
- *  zero based.
- */
-
-extern void gb_clear(struct gb_t_map *map, u32 bitn);
-
-/*
- *  ======== gb_create ========
- *  Create a bit map with len bits.  Initially all bits are cleared.
- */
-
-extern struct gb_t_map *gb_create(u32 len);
-
-/*
- *  ======== gb_delete ========
- *  Delete previously created bit map
- */
-
-extern void gb_delete(struct gb_t_map *map);
-
-/*
- *  ======== gb_findandset ========
- *  Finds a clear bit, sets it, and returns the position
- */
-
-extern u32 gb_findandset(struct gb_t_map *map);
-
-/*
- *  ======== gb_minclear ========
- *  gb_minclear returns the minimum clear bit position.  If no bit is
- *  clear, gb_minclear returns -1.
- */
-extern u32 gb_minclear(struct gb_t_map *map);
-
-/*
- *  ======== gb_set ========
- *  Set the bit in position bitn in the bitmap map.  Bit positions are
- *  zero based.
- */
-
-extern void gb_set(struct gb_t_map *map, u32 bitn);
-
-/*
- *  ======== gb_test ========
- *  Returns TRUE if the bit in position bitn is set in map; otherwise
- *  gb_test returns FALSE.  Bit positions are zero based.
- */
-
-extern bool gb_test(struct gb_t_map *map, u32 bitn);
-
-#endif /*GB_ */
-- 
1.7.2.3


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

* [PATCH v2 05/12] staging: tidspbridge: rmgr/node.c code cleanup
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
                   ` (3 preceding siblings ...)
  2010-11-05 15:13 ` [PATCH v2 04/12] staging: tidspbridge: remove gb bitmap implementation Ionut Nicu
@ 2010-11-05 15:13 ` Ionut Nicu
  2010-11-05 15:13 ` [PATCH v2 06/12] staging: tidspbridge: convert core to list_head Ionut Nicu
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

Reorganized some code in rmgr/node.c to increase its
readability. Most of the changes reduce the code
indentation level and simplifiy the code. No functional
changes were done.

Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
---
 drivers/staging/tidspbridge/rmgr/node.c |  607 +++++++++++++++----------------
 1 files changed, 284 insertions(+), 323 deletions(-)

diff --git a/drivers/staging/tidspbridge/rmgr/node.c b/drivers/staging/tidspbridge/rmgr/node.c
index e48ddba..f660d1f 100644
--- a/drivers/staging/tidspbridge/rmgr/node.c
+++ b/drivers/staging/tidspbridge/rmgr/node.c
@@ -234,9 +234,9 @@ struct node_object {
 
 /* Default buffer attributes */
 static struct dsp_bufferattr node_dfltbufattrs = {
-	0,			/* cb_struct */
-	1,			/* segment_id */
-	0,			/* buf_alignment */
+	.cb_struct = 0,
+	.segment_id = 1,
+	.buf_alignment = 0,
 };
 
 static void delete_node(struct node_object *hnode,
@@ -282,8 +282,7 @@ enum node_state node_get_state(void *hnode)
 	struct node_object *pnode = (struct node_object *)hnode;
 	if (!pnode)
 		return -1;
-	else
-		return pnode->node_state;
+	return pnode->node_state;
 }
 
 /*
@@ -817,6 +816,7 @@ int node_connect(struct node_object *node1, u32 stream1,
 	char *pstr_dev_name = NULL;
 	enum node_type node1_type = NODE_TASK;
 	enum node_type node2_type = NODE_TASK;
+	enum dsp_strmmode strm_mode;
 	struct node_strmdef *pstrm_def;
 	struct node_strmdef *input = NULL;
 	struct node_strmdef *output = NULL;
@@ -830,60 +830,50 @@ int node_connect(struct node_object *node1, u32 stream1,
 	int status = 0;
 	DBC_REQUIRE(refs > 0);
 
-	if ((node1 != (struct node_object *)DSP_HGPPNODE && !node1) ||
-	    (node2 != (struct node_object *)DSP_HGPPNODE && !node2))
-		status = -EFAULT;
+	if (!node1 || !node2)
+		return -EFAULT;
 
-	if (!status) {
-		/* The two nodes must be on the same processor */
-		if (node1 != (struct node_object *)DSP_HGPPNODE &&
-		    node2 != (struct node_object *)DSP_HGPPNODE &&
-		    node1->hnode_mgr != node2->hnode_mgr)
-			status = -EPERM;
-		/* Cannot connect a node to itself */
-		if (node1 == node2)
-			status = -EPERM;
+	/* The two nodes must be on the same processor */
+	if (node1 != (struct node_object *)DSP_HGPPNODE &&
+			node2 != (struct node_object *)DSP_HGPPNODE &&
+			node1->hnode_mgr != node2->hnode_mgr)
+		return -EPERM;
 
-	}
-	if (!status) {
-		/* node_get_type() will return NODE_GPP if hnode =
-		 * DSP_HGPPNODE. */
-		node1_type = node_get_type(node1);
-		node2_type = node_get_type(node2);
-		/* Check stream indices ranges */
-		if ((node1_type != NODE_GPP && node1_type != NODE_DEVICE &&
-		     stream1 >= MAX_OUTPUTS(node1)) || (node2_type != NODE_GPP
-							  && node2_type !=
-							  NODE_DEVICE
-							  && stream2 >=
-							  MAX_INPUTS(node2)))
-			status = -EINVAL;
-	}
-	if (!status) {
-		/*
-		 *  Only the following types of connections are allowed:
-		 *      task/dais socket < == > task/dais socket
-		 *      task/dais socket < == > device
-		 *      task/dais socket < == > GPP
-		 *
-		 *  ie, no message nodes, and at least one task or dais
-		 *  socket node.
-		 */
-		if (node1_type == NODE_MESSAGE || node2_type == NODE_MESSAGE ||
-		    (node1_type != NODE_TASK && node1_type != NODE_DAISSOCKET &&
-		     node2_type != NODE_TASK && node2_type != NODE_DAISSOCKET))
-			status = -EPERM;
-	}
+	/* Cannot connect a node to itself */
+	if (node1 == node2)
+		return -EPERM;
+
+	/* node_get_type() will return NODE_GPP if hnode =
+	 * DSP_HGPPNODE. */
+	node1_type = node_get_type(node1);
+	node2_type = node_get_type(node2);
+	/* Check stream indices ranges */
+	if ((node1_type != NODE_GPP && node1_type != NODE_DEVICE &&
+				stream1 >= MAX_OUTPUTS(node1)) ||
+			(node2_type != NODE_GPP && node2_type != NODE_DEVICE &&
+			 stream2 >= MAX_INPUTS(node2)))
+		return -EINVAL;
+
+	/*
+	 *  Only the following types of connections are allowed:
+	 *      task/dais socket < == > task/dais socket
+	 *      task/dais socket < == > device
+	 *      task/dais socket < == > GPP
+	 *
+	 *  ie, no message nodes, and at least one task or dais
+	 *  socket node.
+	 */
+	if (node1_type == NODE_MESSAGE || node2_type == NODE_MESSAGE ||
+			(node1_type != NODE_TASK &&
+			 node1_type != NODE_DAISSOCKET &&
+			 node2_type != NODE_TASK &&
+			 node2_type != NODE_DAISSOCKET))
+		return -EPERM;
 	/*
 	 * Check stream mode. Default is STRMMODE_PROCCOPY.
 	 */
-	if (!status && pattrs) {
-		if (pattrs->strm_mode != STRMMODE_PROCCOPY)
-			status = -EPERM;	/* illegal stream mode */
-
-	}
-	if (status)
-		goto func_end;
+	if (pattrs && pattrs->strm_mode != STRMMODE_PROCCOPY)
+		return -EPERM;	/* illegal stream mode */
 
 	if (node1_type != NODE_GPP) {
 		hnode_mgr = node1->hnode_mgr;
@@ -891,170 +881,143 @@ int node_connect(struct node_object *node1, u32 stream1,
 		DBC_ASSERT(node2 != (struct node_object *)DSP_HGPPNODE);
 		hnode_mgr = node2->hnode_mgr;
 	}
+
 	/* Enter critical section */
 	mutex_lock(&hnode_mgr->node_mgr_lock);
 
 	/* Nodes must be in the allocated state */
-	if (node1_type != NODE_GPP && node_get_state(node1) != NODE_ALLOCATED)
+	if (node1_type != NODE_GPP &&
+			node_get_state(node1) != NODE_ALLOCATED) {
 		status = -EBADR;
+		goto out_unlock;
+	}
 
-	if (node2_type != NODE_GPP && node_get_state(node2) != NODE_ALLOCATED)
+	if (node2_type != NODE_GPP &&
+			node_get_state(node2) != NODE_ALLOCATED) {
 		status = -EBADR;
+		goto out_unlock;
+	}
 
-	if (!status) {
-		/*  Check that stream indices for task and dais socket nodes
-		 *  are not already be used. (Device nodes checked later) */
-		if (node1_type == NODE_TASK || node1_type == NODE_DAISSOCKET) {
-			output =
-			    &(node1->create_args.asa.
-			      task_arg_obj.strm_out_def[stream1]);
-			if (output->sz_device != NULL)
-				status = -EISCONN;
-
+	/*  Check that stream indices for task and dais socket nodes
+	 *  are not already be used. (Device nodes checked later) */
+	if (node1_type == NODE_TASK || node1_type == NODE_DAISSOCKET) {
+		output = &(node1->create_args.asa.
+				task_arg_obj.strm_out_def[stream1]);
+		if (output->sz_device != NULL) {
+			status = -EISCONN;
+			goto out_unlock;
 		}
-		if (node2_type == NODE_TASK || node2_type == NODE_DAISSOCKET) {
-			input =
-			    &(node2->create_args.asa.
-			      task_arg_obj.strm_in_def[stream2]);
-			if (input->sz_device != NULL)
-				status = -EISCONN;
 
+	}
+	if (node2_type == NODE_TASK || node2_type == NODE_DAISSOCKET) {
+		input = &(node2->create_args.asa.
+				task_arg_obj.strm_in_def[stream2]);
+		if (input->sz_device != NULL) {
+			status = -EISCONN;
+			goto out_unlock;
 		}
+
 	}
 	/* Connecting two task nodes? */
-	if (!status && ((node1_type == NODE_TASK ||
-				       node1_type == NODE_DAISSOCKET)
-				      && (node2_type == NODE_TASK
-					  || node2_type == NODE_DAISSOCKET))) {
+	if (((node1_type == NODE_TASK || node1_type == NODE_DAISSOCKET) &&
+				(node2_type == NODE_TASK ||
+				 node2_type == NODE_DAISSOCKET))) {
 		/* Find available pipe */
 		pipe_id = find_first_zero_bit(hnode_mgr->pipe_map, MAXPIPES);
 		if (pipe_id == MAXPIPES) {
 			status = -ECONNREFUSED;
-		} else {
-			set_bit(pipe_id, hnode_mgr->pipe_map);
-			node1->outputs[stream1].type = NODECONNECT;
-			node2->inputs[stream2].type = NODECONNECT;
-			node1->outputs[stream1].dev_id = pipe_id;
-			node2->inputs[stream2].dev_id = pipe_id;
-			output->sz_device = kzalloc(PIPENAMELEN + 1,
-							GFP_KERNEL);
-			input->sz_device = kzalloc(PIPENAMELEN + 1, GFP_KERNEL);
-			if (output->sz_device == NULL ||
-			    input->sz_device == NULL) {
-				/* Undo the connection */
-				kfree(output->sz_device);
-
-				kfree(input->sz_device);
-
-				output->sz_device = NULL;
-				input->sz_device = NULL;
-				clear_bit(pipe_id, hnode_mgr->pipe_map);
-				status = -ENOMEM;
-			} else {
-				/* Copy "/dbpipe<pipId>" name to device names */
-				sprintf(output->sz_device, "%s%d",
-					PIPEPREFIX, pipe_id);
-				strcpy(input->sz_device, output->sz_device);
-			}
+			goto out_unlock;
+		}
+		set_bit(pipe_id, hnode_mgr->pipe_map);
+		node1->outputs[stream1].type = NODECONNECT;
+		node2->inputs[stream2].type = NODECONNECT;
+		node1->outputs[stream1].dev_id = pipe_id;
+		node2->inputs[stream2].dev_id = pipe_id;
+		output->sz_device = kzalloc(PIPENAMELEN + 1, GFP_KERNEL);
+		input->sz_device = kzalloc(PIPENAMELEN + 1, GFP_KERNEL);
+		if (output->sz_device == NULL || input->sz_device == NULL) {
+			/* Undo the connection */
+			kfree(output->sz_device);
+			kfree(input->sz_device);
+			output->sz_device = NULL;
+			input->sz_device = NULL;
+			clear_bit(pipe_id, hnode_mgr->pipe_map);
+			status = -ENOMEM;
+			goto out_unlock;
 		}
+		/* Copy "/dbpipe<pipId>" name to device names */
+		sprintf(output->sz_device, "%s%d", PIPEPREFIX, pipe_id);
+		strcpy(input->sz_device, output->sz_device);
 	}
 	/* Connecting task node to host? */
-	if (!status && (node1_type == NODE_GPP ||
-				      node2_type == NODE_GPP)) {
-		if (node1_type == NODE_GPP) {
-			chnl_mode = CHNL_MODETODSP;
-		} else {
-			DBC_ASSERT(node2_type == NODE_GPP);
-			chnl_mode = CHNL_MODEFROMDSP;
+	if ((node1_type == NODE_GPP || node2_type == NODE_GPP)) {
+		pstr_dev_name = kzalloc(HOSTNAMELEN + 1, GFP_KERNEL);
+		if (!pstr_dev_name) {
+			status = -ENOMEM;
+			goto out_unlock;
 		}
+
+		DBC_ASSERT((node1_type == NODE_GPP) ||
+				(node2_type == NODE_GPP));
+
+		chnl_mode = (node1_type == NODE_GPP) ?
+			CHNL_MODETODSP : CHNL_MODEFROMDSP;
+
 		/*  Reserve a channel id. We need to put the name "/host<id>"
 		 *  in the node's create_args, but the host
 		 *  side channel will not be opened until DSPStream_Open is
 		 *  called for this node. */
-		if (pattrs) {
-			if (pattrs->strm_mode == STRMMODE_RDMA) {
-				chnl_id = find_first_zero_bit(
-						hnode_mgr->dma_chnl_map,
-						CHNL_MAXCHANNELS);
+		strm_mode = pattrs ? pattrs->strm_mode : STRMMODE_PROCCOPY;
+		switch (strm_mode) {
+		case STRMMODE_RDMA:
+			chnl_id = find_first_zero_bit(hnode_mgr->dma_chnl_map,
+					CHNL_MAXCHANNELS);
+			if (chnl_id < CHNL_MAXCHANNELS) {
+				set_bit(chnl_id, hnode_mgr->dma_chnl_map);
 				/* dma chans are 2nd transport chnl set
 				 * ids(e.g. 16-31) */
-				if (chnl_id != CHNL_MAXCHANNELS) {
-					set_bit(chnl_id,
-						hnode_mgr->dma_chnl_map);
-					chnl_id = chnl_id +
-						hnode_mgr->ul_num_chnls;
-				}
-			} else if (pattrs->strm_mode == STRMMODE_ZEROCOPY) {
-				chnl_id = find_first_zero_bit(
-						hnode_mgr->zc_chnl_map,
-						CHNL_MAXCHANNELS);
+				chnl_id = chnl_id + hnode_mgr->ul_num_chnls;
+			}
+			break;
+		case STRMMODE_ZEROCOPY:
+			chnl_id = find_first_zero_bit(hnode_mgr->zc_chnl_map,
+					CHNL_MAXCHANNELS);
+			if (chnl_id < CHNL_MAXCHANNELS) {
+				set_bit(chnl_id, hnode_mgr->zc_chnl_map);
 				/* zero-copy chans are 3nd transport set
 				 * (e.g. 32-47) */
-				if (chnl_id != CHNL_MAXCHANNELS) {
-					set_bit(chnl_id,
-						hnode_mgr->zc_chnl_map);
-					chnl_id = chnl_id +
-						(2 * hnode_mgr->ul_num_chnls);
-				}
-			} else {	/* must be PROCCOPY */
-				DBC_ASSERT(pattrs->strm_mode ==
-					   STRMMODE_PROCCOPY);
-				chnl_id = find_first_zero_bit(
-						hnode_mgr->chnl_map,
-						CHNL_MAXCHANNELS);
-				/* e.g. 0-15 */
-				if (chnl_id != CHNL_MAXCHANNELS)
-					set_bit(chnl_id, hnode_mgr->chnl_map);
+				chnl_id = chnl_id +
+					(2 * hnode_mgr->ul_num_chnls);
 			}
-		} else {
-			/* default to PROCCOPY */
+			break;
+		case STRMMODE_PROCCOPY:
 			chnl_id = find_first_zero_bit(hnode_mgr->chnl_map,
 					CHNL_MAXCHANNELS);
-			if (chnl_id != CHNL_MAXCHANNELS)
+			if (chnl_id < CHNL_MAXCHANNELS)
 				set_bit(chnl_id, hnode_mgr->chnl_map);
+			break;
+		default:
+			status = -EINVAL;
+			goto out_unlock;
 		}
 		if (chnl_id == CHNL_MAXCHANNELS) {
 			status = -ECONNREFUSED;
-			goto func_cont2;
+			goto out_unlock;
 		}
-		pstr_dev_name = kzalloc(HOSTNAMELEN + 1, GFP_KERNEL);
-		if (pstr_dev_name != NULL)
-			goto func_cont2;
-
-		if (pattrs) {
-			if (pattrs->strm_mode == STRMMODE_RDMA) {
-				clear_bit(chnl_id - hnode_mgr->ul_num_chnls,
-						hnode_mgr->dma_chnl_map);
-			} else if (pattrs->strm_mode == STRMMODE_ZEROCOPY) {
-				clear_bit(chnl_id -
-						(2 * hnode_mgr->ul_num_chnls),
-						hnode_mgr->zc_chnl_map);
-			} else {
-				DBC_ASSERT(pattrs->strm_mode ==
-					   STRMMODE_PROCCOPY);
-				clear_bit(chnl_id, hnode_mgr->chnl_map);
-			}
+
+		if (node1 == (struct node_object *)DSP_HGPPNODE) {
+			node2->inputs[stream2].type = HOSTCONNECT;
+			node2->inputs[stream2].dev_id = chnl_id;
+			input->sz_device = pstr_dev_name;
 		} else {
-			clear_bit(chnl_id, hnode_mgr->chnl_map);
-		}
-		status = -ENOMEM;
-func_cont2:
-		if (!status) {
-			if (node1 == (struct node_object *)DSP_HGPPNODE) {
-				node2->inputs[stream2].type = HOSTCONNECT;
-				node2->inputs[stream2].dev_id = chnl_id;
-				input->sz_device = pstr_dev_name;
-			} else {
-				node1->outputs[stream1].type = HOSTCONNECT;
-				node1->outputs[stream1].dev_id = chnl_id;
-				output->sz_device = pstr_dev_name;
-			}
-			sprintf(pstr_dev_name, "%s%d", HOSTPREFIX, chnl_id);
+			node1->outputs[stream1].type = HOSTCONNECT;
+			node1->outputs[stream1].dev_id = chnl_id;
+			output->sz_device = pstr_dev_name;
 		}
+		sprintf(pstr_dev_name, "%s%d", HOSTPREFIX, chnl_id);
 	}
 	/* Connecting task node to device node? */
-	if (!status && ((node1_type == NODE_DEVICE) ||
-				      (node2_type == NODE_DEVICE))) {
+	if (((node1_type == NODE_DEVICE) || (node2_type == NODE_DEVICE))) {
 		if (node2_type == NODE_DEVICE) {
 			/* node1 == > device */
 			dev_node_obj = node2;
@@ -1071,60 +1034,57 @@ func_cont2:
 		/* Set up create args */
 		pstream->type = DEVICECONNECT;
 		dw_length = strlen(dev_node_obj->pstr_dev_name);
-		if (conn_param != NULL) {
+		if (conn_param != NULL)
 			pstrm_def->sz_device = kzalloc(dw_length + 1 +
-							conn_param->cb_data,
-							GFP_KERNEL);
-		} else {
+					conn_param->cb_data,
+					GFP_KERNEL);
 			pstrm_def->sz_device = kzalloc(dw_length + 1,
-							GFP_KERNEL);
-		}
-		if (pstrm_def->sz_device == NULL) {
+					GFP_KERNEL);
+		if (!pstrm_def->sz_device) {
 			status = -ENOMEM;
-		} else {
-			/* Copy device name */
-			strncpy(pstrm_def->sz_device,
+			goto out_unlock;
+		}
+		/* Copy device name */
+		strncpy(pstrm_def->sz_device,
 				dev_node_obj->pstr_dev_name, dw_length);
-			if (conn_param != NULL) {
-				strncat(pstrm_def->sz_device,
+		if (conn_param != NULL)
+			strncat(pstrm_def->sz_device,
 					(char *)conn_param->node_data,
 					(u32) conn_param->cb_data);
-			}
-			dev_node_obj->device_owner = hnode;
-		}
+		dev_node_obj->device_owner = hnode;
 	}
-	if (!status) {
-		/* Fill in create args */
-		if (node1_type == NODE_TASK || node1_type == NODE_DAISSOCKET) {
-			node1->create_args.asa.task_arg_obj.num_outputs++;
-			fill_stream_def(node1, output, pattrs);
-		}
-		if (node2_type == NODE_TASK || node2_type == NODE_DAISSOCKET) {
-			node2->create_args.asa.task_arg_obj.num_inputs++;
-			fill_stream_def(node2, input, pattrs);
-		}
-		/* Update node1 and node2 stream_connect */
-		if (node1_type != NODE_GPP && node1_type != NODE_DEVICE) {
-			node1->num_outputs++;
-			if (stream1 > node1->max_output_index)
-				node1->max_output_index = stream1;
+	/* Fill in create args */
+	if (node1_type == NODE_TASK || node1_type == NODE_DAISSOCKET) {
+		node1->create_args.asa.task_arg_obj.num_outputs++;
+		fill_stream_def(node1, output, pattrs);
+	}
+	if (node2_type == NODE_TASK || node2_type == NODE_DAISSOCKET) {
+		node2->create_args.asa.task_arg_obj.num_inputs++;
+		fill_stream_def(node2, input, pattrs);
+	}
+	/* Update node1 and node2 stream_connect */
+	if (node1_type != NODE_GPP && node1_type != NODE_DEVICE) {
+		node1->num_outputs++;
+		if (stream1 > node1->max_output_index)
+			node1->max_output_index = stream1;
 
-		}
-		if (node2_type != NODE_GPP && node2_type != NODE_DEVICE) {
-			node2->num_inputs++;
-			if (stream2 > node2->max_input_index)
-				node2->max_input_index = stream2;
+	}
+	if (node2_type != NODE_GPP && node2_type != NODE_DEVICE) {
+		node2->num_inputs++;
+		if (stream2 > node2->max_input_index)
+			node2->max_input_index = stream2;
 
-		}
-		fill_stream_connect(node1, node2, stream1, stream2);
 	}
+	fill_stream_connect(node1, node2, stream1, stream2);
 	/* end of sync_enter_cs */
 	/* Exit critical section */
+out_unlock:
+	if (status && pstr_dev_name)
+		kfree(pstr_dev_name);
 	mutex_unlock(&hnode_mgr->node_mgr_lock);
-func_end:
 	dev_dbg(bridge, "%s: node1: %p stream1: %d node2: %p stream2: %d"
-		"pattrs: %p status: 0x%x\n", __func__, node1,
-		stream1, node2, stream2, pattrs, status);
+			"pattrs: %p status: 0x%x\n", __func__, node1,
+			stream1, node2, stream2, pattrs, status);
 	return status;
 }
 
@@ -1302,6 +1262,7 @@ int node_create_mgr(struct node_mgr **node_man,
 	struct nldr_attrs nldr_attrs_obj;
 	int status = 0;
 	u8 dev_type;
+
 	DBC_REQUIRE(refs > 0);
 	DBC_REQUIRE(node_man != NULL);
 	DBC_REQUIRE(hdev_obj != NULL);
@@ -1309,92 +1270,95 @@ int node_create_mgr(struct node_mgr **node_man,
 	*node_man = NULL;
 	/* Allocate Node manager object */
 	node_mgr_obj = kzalloc(sizeof(struct node_mgr), GFP_KERNEL);
-	if (node_mgr_obj) {
-		node_mgr_obj->hdev_obj = hdev_obj;
-		node_mgr_obj->node_list = kzalloc(sizeof(struct lst_list),
-				GFP_KERNEL);
-		INIT_LIST_HEAD(&node_mgr_obj->node_list->head);
-		node_mgr_obj->ntfy_obj = kmalloc(
-				sizeof(struct ntfy_object), GFP_KERNEL);
-		if (node_mgr_obj->ntfy_obj)
-			ntfy_init(node_mgr_obj->ntfy_obj);
-		else
-			status = -ENOMEM;
-		node_mgr_obj->num_created = 0;
-	} else {
+	if (!node_mgr_obj)
+		return -ENOMEM;
+
+	node_mgr_obj->hdev_obj = hdev_obj;
+	node_mgr_obj->node_list = kzalloc(sizeof(struct lst_list), GFP_KERNEL);
+	if (!node_mgr_obj->node_list) {
 		status = -ENOMEM;
+		goto out_err;
 	}
-	/* get devNodeType */
-	if (!status)
-		status = dev_get_dev_type(hdev_obj, &dev_type);
+
+	node_mgr_obj->ntfy_obj = kmalloc(sizeof(struct ntfy_object),
+			GFP_KERNEL);
+	if (!node_mgr_obj->ntfy_obj) {
+		status = -ENOMEM;
+		goto out_err;
+	}
+	ntfy_init(node_mgr_obj->ntfy_obj);
+
+	INIT_LIST_HEAD(&node_mgr_obj->node_list->head);
+
+	dev_get_dev_type(hdev_obj, &dev_type);
 
 	/* Create the DCD Manager */
-	if (!status) {
-		status =
-		    dcd_create_manager(sz_zl_file, &node_mgr_obj->hdcd_mgr);
-		if (!status)
-			status = get_proc_props(node_mgr_obj, hdev_obj);
+	status = dcd_create_manager(sz_zl_file, &node_mgr_obj->hdcd_mgr);
+	if (status)
+		goto out_err;
+
+	status = get_proc_props(node_mgr_obj, hdev_obj);
+	if (status)
+		goto out_err;
 
-	}
 	/* Create NODE Dispatcher */
-	if (!status) {
-		disp_attr_obj.ul_chnl_offset = node_mgr_obj->ul_chnl_offset;
-		disp_attr_obj.ul_chnl_buf_size = node_mgr_obj->ul_chnl_buf_size;
-		disp_attr_obj.proc_family = node_mgr_obj->proc_family;
-		disp_attr_obj.proc_type = node_mgr_obj->proc_type;
-		status =
-		    disp_create(&node_mgr_obj->disp_obj, hdev_obj,
-				&disp_attr_obj);
-	}
+	disp_attr_obj.ul_chnl_offset = node_mgr_obj->ul_chnl_offset;
+	disp_attr_obj.ul_chnl_buf_size = node_mgr_obj->ul_chnl_buf_size;
+	disp_attr_obj.proc_family = node_mgr_obj->proc_family;
+	disp_attr_obj.proc_type = node_mgr_obj->proc_type;
+
+	status = disp_create(&node_mgr_obj->disp_obj, hdev_obj, &disp_attr_obj);
+	if (status)
+		goto out_err;
+
 	/* Create a STRM Manager */
-	if (!status)
-		status = strm_create(&node_mgr_obj->strm_mgr_obj, hdev_obj);
+	status = strm_create(&node_mgr_obj->strm_mgr_obj, hdev_obj);
+	if (status)
+		goto out_err;
 
-	if (!status) {
-		dev_get_intf_fxns(hdev_obj, &node_mgr_obj->intf_fxns);
-		/* Get msg_ctrl queue manager */
-		dev_get_msg_mgr(hdev_obj, &node_mgr_obj->msg_mgr_obj);
-		mutex_init(&node_mgr_obj->node_mgr_lock);
-		/* Block out reserved channels */
-		for (i = 0; i < node_mgr_obj->ul_chnl_offset; i++)
-			set_bit(i, node_mgr_obj->chnl_map);
-
-		/* Block out channels reserved for RMS */
-		set_bit(node_mgr_obj->ul_chnl_offset, node_mgr_obj->chnl_map);
-		set_bit(node_mgr_obj->ul_chnl_offset + 1,
-				node_mgr_obj->chnl_map);
-	}
-	if (!status) {
-		/* NO RM Server on the IVA */
-		if (dev_type != IVA_UNIT) {
-			/* Get addresses of any RMS functions loaded */
-			status = get_rms_fxns(node_mgr_obj);
-		}
+	dev_get_intf_fxns(hdev_obj, &node_mgr_obj->intf_fxns);
+	/* Get msg_ctrl queue manager */
+	dev_get_msg_mgr(hdev_obj, &node_mgr_obj->msg_mgr_obj);
+	mutex_init(&node_mgr_obj->node_mgr_lock);
+
+	/* Block out reserved channels */
+	for (i = 0; i < node_mgr_obj->ul_chnl_offset; i++)
+		set_bit(i, node_mgr_obj->chnl_map);
+
+	/* Block out channels reserved for RMS */
+	set_bit(node_mgr_obj->ul_chnl_offset, node_mgr_obj->chnl_map);
+	set_bit(node_mgr_obj->ul_chnl_offset + 1, node_mgr_obj->chnl_map);
+
+	/* NO RM Server on the IVA */
+	if (dev_type != IVA_UNIT) {
+		/* Get addresses of any RMS functions loaded */
+		status = get_rms_fxns(node_mgr_obj);
+		if (status)
+			goto out_err;
 	}
 
 	/* Get loader functions and create loader */
-	if (!status)
-		node_mgr_obj->nldr_fxns = nldr_fxns;	/* Dyn loader funcs */
+	node_mgr_obj->nldr_fxns = nldr_fxns;	/* Dyn loader funcs */
+
+	nldr_attrs_obj.pfn_ovly = ovly;
+	nldr_attrs_obj.pfn_write = mem_write;
+	nldr_attrs_obj.us_dsp_word_size = node_mgr_obj->udsp_word_size;
+	nldr_attrs_obj.us_dsp_mau_size = node_mgr_obj->udsp_mau_size;
+	node_mgr_obj->loader_init = node_mgr_obj->nldr_fxns.pfn_init();
+	status = node_mgr_obj->nldr_fxns.pfn_create(&node_mgr_obj->nldr_obj,
+			hdev_obj,
+			&nldr_attrs_obj);
+	if (status)
+		goto out_err;
 
-	if (!status) {
-		nldr_attrs_obj.pfn_ovly = ovly;
-		nldr_attrs_obj.pfn_write = mem_write;
-		nldr_attrs_obj.us_dsp_word_size = node_mgr_obj->udsp_word_size;
-		nldr_attrs_obj.us_dsp_mau_size = node_mgr_obj->udsp_mau_size;
-		node_mgr_obj->loader_init = node_mgr_obj->nldr_fxns.pfn_init();
-		status =
-		    node_mgr_obj->nldr_fxns.pfn_create(&node_mgr_obj->nldr_obj,
-						       hdev_obj,
-						       &nldr_attrs_obj);
-	}
-	if (!status)
-		*node_man = node_mgr_obj;
-	else
-		delete_node_mgr(node_mgr_obj);
+	*node_man = node_mgr_obj;
 
 	DBC_ENSURE((status && *node_man == NULL) || (!status && *node_man));
 
 	return status;
+out_err:
+	delete_node_mgr(node_mgr_obj);
+	return status;
 }
 
 /*
@@ -1568,16 +1532,14 @@ func_end:
  */
 int node_delete_mgr(struct node_mgr *hnode_mgr)
 {
-	int status = 0;
-
 	DBC_REQUIRE(refs > 0);
 
-	if (hnode_mgr)
-		delete_node_mgr(hnode_mgr);
-	else
-		status = -EFAULT;
+	if (!hnode_mgr)
+		return -EFAULT;
 
-	return status;
+	delete_node_mgr(hnode_mgr);
+
+	return 0;
 }
 
 /*
@@ -1692,38 +1654,37 @@ int node_get_attr(struct node_object *hnode,
 			 struct dsp_nodeattr *pattr, u32 attr_size)
 {
 	struct node_mgr *hnode_mgr;
-	int status = 0;
 	DBC_REQUIRE(refs > 0);
 	DBC_REQUIRE(pattr != NULL);
 	DBC_REQUIRE(attr_size >= sizeof(struct dsp_nodeattr));
 
-	if (!hnode) {
-		status = -EFAULT;
-	} else {
-		hnode_mgr = hnode->hnode_mgr;
-		/* Enter hnode_mgr critical section (since we're accessing
-		 * data that could be changed by node_change_priority() and
-		 * node_connect(). */
-		mutex_lock(&hnode_mgr->node_mgr_lock);
-		pattr->cb_struct = sizeof(struct dsp_nodeattr);
-		/* dsp_nodeattrin */
-		pattr->in_node_attr_in.cb_struct =
-				 sizeof(struct dsp_nodeattrin);
-		pattr->in_node_attr_in.prio = hnode->prio;
-		pattr->in_node_attr_in.utimeout = hnode->utimeout;
-		pattr->in_node_attr_in.heap_size =
-			hnode->create_args.asa.task_arg_obj.heap_size;
-		pattr->in_node_attr_in.pgpp_virt_addr = (void *)
-			hnode->create_args.asa.task_arg_obj.ugpp_heap_addr;
-		pattr->node_attr_inputs = hnode->num_gpp_inputs;
-		pattr->node_attr_outputs = hnode->num_gpp_outputs;
-		/* dsp_nodeinfo */
-		get_node_info(hnode, &(pattr->node_info));
-		/* end of sync_enter_cs */
-		/* Exit critical section */
-		mutex_unlock(&hnode_mgr->node_mgr_lock);
-	}
-	return status;
+	if (!hnode)
+		return -EFAULT;
+
+	hnode_mgr = hnode->hnode_mgr;
+	/* Enter hnode_mgr critical section (since we're accessing
+	 * data that could be changed by node_change_priority() and
+	 * node_connect(). */
+	mutex_lock(&hnode_mgr->node_mgr_lock);
+	pattr->cb_struct = sizeof(struct dsp_nodeattr);
+	/* dsp_nodeattrin */
+	pattr->in_node_attr_in.cb_struct =
+		sizeof(struct dsp_nodeattrin);
+	pattr->in_node_attr_in.prio = hnode->prio;
+	pattr->in_node_attr_in.utimeout = hnode->utimeout;
+	pattr->in_node_attr_in.heap_size =
+		hnode->create_args.asa.task_arg_obj.heap_size;
+	pattr->in_node_attr_in.pgpp_virt_addr = (void *)
+		hnode->create_args.asa.task_arg_obj.ugpp_heap_addr;
+	pattr->node_attr_inputs = hnode->num_gpp_inputs;
+	pattr->node_attr_outputs = hnode->num_gpp_outputs;
+	/* dsp_nodeinfo */
+	get_node_info(hnode, &(pattr->node_info));
+	/* end of sync_enter_cs */
+	/* Exit critical section */
+	mutex_unlock(&hnode_mgr->node_mgr_lock);
+
+	return 0;
 }
 
 /*
-- 
1.7.2.3


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

* [PATCH v2 06/12] staging: tidspbridge: convert core to list_head
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
                   ` (4 preceding siblings ...)
  2010-11-05 15:13 ` [PATCH v2 05/12] staging: tidspbridge: rmgr/node.c code cleanup Ionut Nicu
@ 2010-11-05 15:13 ` Ionut Nicu
  2010-11-05 21:07   ` Sapiens, Rene
  2010-11-05 22:12   ` Sapiens, Rene
  2010-11-05 15:13 ` [PATCH v2 07/12] staging: tidspbridge: convert pmgr " Ionut Nicu
                   ` (6 subsequent siblings)
  12 siblings, 2 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

Convert the core module of the tidspbridge driver
to use struct list_head instead of struct lst_list.

Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
---
 drivers/staging/tidspbridge/core/_msg_sm.h         |   12 +-
 drivers/staging/tidspbridge/core/chnl_sm.c         |  245 +++++++++-----------
 drivers/staging/tidspbridge/core/io_sm.c           |  141 +++++-------
 drivers/staging/tidspbridge/core/msg_sm.c          |  236 +++++++------------
 .../tidspbridge/include/dspbridge/_chnl_sm.h       |    8 +-
 .../tidspbridge/include/dspbridge/cmmdefs.h        |    1 -
 .../staging/tidspbridge/include/dspbridge/sync.h   |    1 +
 7 files changed, 264 insertions(+), 380 deletions(-)

diff --git a/drivers/staging/tidspbridge/core/_msg_sm.h b/drivers/staging/tidspbridge/core/_msg_sm.h
index 556de5c..b78d1a6 100644
--- a/drivers/staging/tidspbridge/core/_msg_sm.h
+++ b/drivers/staging/tidspbridge/core/_msg_sm.h
@@ -20,7 +20,7 @@
 #ifndef _MSG_SM_
 #define _MSG_SM_
 
-#include <dspbridge/list.h>
+#include <linux/list.h>
 #include <dspbridge/msgdefs.h>
 
 /*
@@ -86,12 +86,12 @@ struct msg_mgr {
 	struct bridge_drv_interface *intf_fxns;
 
 	struct io_mgr *hio_mgr;	/* IO manager */
-	struct lst_list *queue_list;	/* List of MSG_QUEUEs */
+	struct list_head queue_list;	/* List of MSG_QUEUEs */
 	spinlock_t msg_mgr_lock;	/* For critical sections */
 	/* Signalled when MsgFrame is available */
 	struct sync_object *sync_event;
-	struct lst_list *msg_free_list;	/* Free MsgFrames ready to be filled */
-	struct lst_list *msg_used_list;	/* MsgFrames ready to go to DSP */
+	struct list_head msg_free_list;	/* Free MsgFrames ready to be filled */
+	struct list_head msg_used_list;	/* MsgFrames ready to go to DSP */
 	u32 msgs_pending;	/* # of queued messages to go to DSP */
 	u32 max_msgs;		/* Max # of msgs that fit in buffer */
 	msg_onexit on_exit;	/* called when RMS_EXIT is received */
@@ -111,9 +111,9 @@ struct msg_queue {
 	struct msg_mgr *hmsg_mgr;
 	u32 max_msgs;		/* Node message depth */
 	u32 msgq_id;		/* Node environment pointer */
-	struct lst_list *msg_free_list;	/* Free MsgFrames ready to be filled */
+	struct list_head msg_free_list;	/* Free MsgFrames ready to be filled */
 	/* Filled MsgFramess waiting to be read */
-	struct lst_list *msg_used_list;
+	struct list_head msg_used_list;
 	void *arg;		/* Handle passed to mgr on_exit callback */
 	struct sync_object *sync_event;	/* Signalled when message is ready */
 	struct sync_object *sync_done;	/* For synchronizing cleanup */
diff --git a/drivers/staging/tidspbridge/core/chnl_sm.c b/drivers/staging/tidspbridge/core/chnl_sm.c
index 662a5b5..83403bb 100644
--- a/drivers/staging/tidspbridge/core/chnl_sm.c
+++ b/drivers/staging/tidspbridge/core/chnl_sm.c
@@ -37,9 +37,9 @@
  *      which may cause timeouts and/or failure offunction sync_wait_on_event.
  *      This invariant condition is:
  *
- *          LST_Empty(pchnl->pio_completions) ==> pchnl->sync_event is reset
+ *          list_empty(&pchnl->pio_completions) ==> pchnl->sync_event is reset
  *      and
- *          !LST_Empty(pchnl->pio_completions) ==> pchnl->sync_event is set.
+ *          !list_empty(&pchnl->pio_completions) ==> pchnl->sync_event is set.
  */
 
 #include <linux/types.h>
@@ -73,11 +73,9 @@
 #define MAILBOX_IRQ INT_MAIL_MPU_IRQ
 
 /*  ----------------------------------- Function Prototypes */
-static struct lst_list *create_chirp_list(u32 chirps);
+static int create_chirp_list(struct list_head *list, u32 chirps);
 
-static void free_chirp_list(struct lst_list *chirp_list);
-
-static struct chnl_irp *make_new_chirp(void);
+static void free_chirp_list(struct list_head *list);
 
 static int search_free_channel(struct chnl_mgr *chnl_mgr_obj,
 				      u32 *chnl);
@@ -179,9 +177,12 @@ func_cont:
 	}
 	if (!status) {
 		/* Get a free chirp: */
-		chnl_packet_obj =
-		    (struct chnl_irp *)lst_get_head(pchnl->free_packets_list);
-		if (chnl_packet_obj == NULL)
+		if (!list_empty(&pchnl->free_packets_list)) {
+			chnl_packet_obj = list_first_entry(
+					&pchnl->free_packets_list,
+					struct chnl_irp, link);
+			list_del(&chnl_packet_obj->link);
+		} else
 			status = -EIO;
 
 	}
@@ -206,8 +207,7 @@ func_cont:
 		chnl_packet_obj->dw_arg = dw_arg;
 		chnl_packet_obj->status = (is_eos ? CHNL_IOCSTATEOS :
 					   CHNL_IOCSTATCOMPLETE);
-		lst_put_tail(pchnl->pio_requests,
-			     (struct list_head *)chnl_packet_obj);
+		list_add_tail(&chnl_packet_obj->link, &pchnl->pio_requests);
 		pchnl->cio_reqs++;
 		DBC_ASSERT(pchnl->cio_reqs <= pchnl->chnl_packets);
 		/*
@@ -272,7 +272,7 @@ int bridge_chnl_cancel_io(struct chnl_object *chnl_obj)
 	 *  IORequests or dispatching. */
 	spin_lock_bh(&chnl_mgr_obj->chnl_mgr_lock);
 	pchnl->dw_state |= CHNL_STATECANCEL;
-	if (LST_IS_EMPTY(pchnl->pio_requests))
+	if (list_empty(&pchnl->pio_requests))
 		goto func_cont;
 
 	if (pchnl->chnl_type == CHNL_PCPY) {
@@ -286,18 +286,16 @@ int bridge_chnl_cancel_io(struct chnl_object *chnl_obj)
 		}
 	}
 	/* Move all IOR's to IOC queue: */
-	while (!LST_IS_EMPTY(pchnl->pio_requests)) {
-		chnl_packet_obj =
-		    (struct chnl_irp *)lst_get_head(pchnl->pio_requests);
-		if (chnl_packet_obj) {
-			chnl_packet_obj->byte_size = 0;
-			chnl_packet_obj->status |= CHNL_IOCSTATCANCEL;
-			lst_put_tail(pchnl->pio_completions,
-				     (struct list_head *)chnl_packet_obj);
-			pchnl->cio_cs++;
-			pchnl->cio_reqs--;
-			DBC_ASSERT(pchnl->cio_reqs >= 0);
-		}
+	while (!list_empty(&pchnl->pio_requests)) {
+		chnl_packet_obj = list_first_entry(&pchnl->pio_requests,
+				struct chnl_irp, link);
+		list_del(&chnl_packet_obj->link);
+		chnl_packet_obj->byte_size = 0;
+		chnl_packet_obj->status |= CHNL_IOCSTATCANCEL;
+		list_add_tail(&chnl_packet_obj->link, &pchnl->pio_completions);
+		pchnl->cio_cs++;
+		pchnl->cio_reqs--;
+		DBC_ASSERT(pchnl->cio_reqs >= 0);
 	}
 func_cont:
 	spin_unlock_bh(&chnl_mgr_obj->chnl_mgr_lock);
@@ -353,20 +351,14 @@ func_cont:
 			pchnl->sync_event = NULL;
 		}
 		/* Free I/O request and I/O completion queues: */
-		if (pchnl->pio_completions) {
-			free_chirp_list(pchnl->pio_completions);
-			pchnl->pio_completions = NULL;
-			pchnl->cio_cs = 0;
-		}
-		if (pchnl->pio_requests) {
-			free_chirp_list(pchnl->pio_requests);
-			pchnl->pio_requests = NULL;
-			pchnl->cio_reqs = 0;
-		}
-		if (pchnl->free_packets_list) {
-			free_chirp_list(pchnl->free_packets_list);
-			pchnl->free_packets_list = NULL;
-		}
+		free_chirp_list(&pchnl->pio_completions);
+		pchnl->cio_cs = 0;
+
+		free_chirp_list(&pchnl->pio_requests);
+		pchnl->cio_reqs = 0;
+
+		free_chirp_list(&pchnl->free_packets_list);
+
 		/* Release channel object. */
 		kfree(pchnl);
 		pchnl = NULL;
@@ -505,7 +497,7 @@ int bridge_chnl_flush_io(struct chnl_object *chnl_obj, u32 timeout)
 		    && (pchnl->chnl_type == CHNL_PCPY)) {
 			/* Wait for IO completions, up to the specified
 			 * timeout: */
-			while (!LST_IS_EMPTY(pchnl->pio_requests) && !status) {
+			while (!list_empty(&pchnl->pio_requests) && !status) {
 				status = bridge_chnl_get_ioc(chnl_obj,
 						timeout, &chnl_ioc_obj);
 				if (status)
@@ -521,7 +513,7 @@ int bridge_chnl_flush_io(struct chnl_object *chnl_obj, u32 timeout)
 			pchnl->dw_state &= ~CHNL_STATECANCEL;
 		}
 	}
-	DBC_ENSURE(status || LST_IS_EMPTY(pchnl->pio_requests));
+	DBC_ENSURE(status || list_empty(&pchnl->pio_requests));
 	return status;
 }
 
@@ -581,7 +573,7 @@ int bridge_chnl_get_ioc(struct chnl_object *chnl_obj, u32 timeout,
 	if (!chan_ioc || !pchnl) {
 		status = -EFAULT;
 	} else if (timeout == CHNL_IOCNOWAIT) {
-		if (LST_IS_EMPTY(pchnl->pio_completions))
+		if (list_empty(&pchnl->pio_completions))
 			status = -EREMOTEIO;
 
 	}
@@ -596,7 +588,7 @@ int bridge_chnl_get_ioc(struct chnl_object *chnl_obj, u32 timeout,
 
 	ioc.status = CHNL_IOCSTATCOMPLETE;
 	if (timeout !=
-	    CHNL_IOCNOWAIT && LST_IS_EMPTY(pchnl->pio_completions)) {
+	    CHNL_IOCNOWAIT && list_empty(&pchnl->pio_completions)) {
 		if (timeout == CHNL_IOCINFINITE)
 			timeout = SYNC_INFINITE;
 
@@ -611,7 +603,7 @@ int bridge_chnl_get_ioc(struct chnl_object *chnl_obj, u32 timeout,
 			 * fails due to unkown causes. */
 			/* Even though Wait failed, there may be something in
 			 * the Q: */
-			if (LST_IS_EMPTY(pchnl->pio_completions)) {
+			if (list_empty(&pchnl->pio_completions)) {
 				ioc.status |= CHNL_IOCSTATCANCEL;
 				dequeue_ioc = false;
 			}
@@ -622,30 +614,24 @@ int bridge_chnl_get_ioc(struct chnl_object *chnl_obj, u32 timeout,
 	omap_mbox_disable_irq(dev_ctxt->mbox, IRQ_RX);
 	if (dequeue_ioc) {
 		/* Dequeue IOC and set chan_ioc; */
-		DBC_ASSERT(!LST_IS_EMPTY(pchnl->pio_completions));
-		chnl_packet_obj =
-		    (struct chnl_irp *)lst_get_head(pchnl->pio_completions);
+		DBC_ASSERT(!list_empty(&pchnl->pio_completions));
+		chnl_packet_obj = list_first_entry(&pchnl->pio_completions,
+				struct chnl_irp, link);
+		list_del(&chnl_packet_obj->link);
 		/* Update chan_ioc from channel state and chirp: */
-		if (chnl_packet_obj) {
-			pchnl->cio_cs--;
-			/*  If this is a zero-copy channel, then set IOC's pbuf
-			 *  to the DSP's address. This DSP address will get
-			 *  translated to user's virtual addr later. */
-			{
-				host_sys_buf = chnl_packet_obj->host_sys_buf;
-				ioc.pbuf = chnl_packet_obj->host_user_buf;
-			}
-			ioc.byte_size = chnl_packet_obj->byte_size;
-			ioc.buf_size = chnl_packet_obj->buf_size;
-			ioc.dw_arg = chnl_packet_obj->dw_arg;
-			ioc.status |= chnl_packet_obj->status;
-			/* Place the used chirp on the free list: */
-			lst_put_tail(pchnl->free_packets_list,
-				     (struct list_head *)chnl_packet_obj);
-		} else {
-			ioc.pbuf = NULL;
-			ioc.byte_size = 0;
-		}
+		pchnl->cio_cs--;
+		/*  If this is a zero-copy channel, then set IOC's pbuf
+		 *  to the DSP's address. This DSP address will get
+		 *  translated to user's virtual addr later. */
+		host_sys_buf = chnl_packet_obj->host_sys_buf;
+		ioc.pbuf = chnl_packet_obj->host_user_buf;
+		ioc.byte_size = chnl_packet_obj->byte_size;
+		ioc.buf_size = chnl_packet_obj->buf_size;
+		ioc.dw_arg = chnl_packet_obj->dw_arg;
+		ioc.status |= chnl_packet_obj->status;
+		/* Place the used chirp on the free list: */
+		list_add_tail(&chnl_packet_obj->link,
+				&pchnl->free_packets_list);
 	} else {
 		ioc.pbuf = NULL;
 		ioc.byte_size = 0;
@@ -653,7 +639,7 @@ int bridge_chnl_get_ioc(struct chnl_object *chnl_obj, u32 timeout,
 		ioc.buf_size = 0;
 	}
 	/* Ensure invariant: If any IOC's are queued for this channel... */
-	if (!LST_IS_EMPTY(pchnl->pio_completions)) {
+	if (!list_empty(&pchnl->pio_completions)) {
 		/*  Since DSPStream_Reclaim() does not take a timeout
 		 *  parameter, we pass the stream's timeout value to
 		 *  bridge_chnl_get_ioc. We cannot determine whether or not
@@ -818,9 +804,19 @@ int bridge_chnl_open(struct chnl_object **chnl,
 	/* Protect queues from io_dpc: */
 	pchnl->dw_state = CHNL_STATECANCEL;
 	/* Allocate initial IOR and IOC queues: */
-	pchnl->free_packets_list = create_chirp_list(pattrs->uio_reqs);
-	pchnl->pio_requests = create_chirp_list(0);
-	pchnl->pio_completions = create_chirp_list(0);
+	status = create_chirp_list(&pchnl->free_packets_list,
+			pattrs->uio_reqs);
+	if (status)
+		goto func_end;
+
+	status = create_chirp_list(&pchnl->pio_requests, 0);
+	if (status)
+		goto func_end;
+
+	status = create_chirp_list(&pchnl->pio_completions, 0);
+	if (status)
+		goto func_end;
+
 	pchnl->chnl_packets = pattrs->uio_reqs;
 	pchnl->cio_cs = 0;
 	pchnl->cio_reqs = 0;
@@ -840,40 +836,26 @@ int bridge_chnl_open(struct chnl_object **chnl,
 	}
 
 	if (!status) {
-		if (pchnl->pio_completions && pchnl->pio_requests &&
-		    pchnl->free_packets_list) {
-			/* Initialize CHNL object fields: */
-			pchnl->chnl_mgr_obj = chnl_mgr_obj;
-			pchnl->chnl_id = ch_id;
-			pchnl->chnl_mode = chnl_mode;
-			pchnl->user_event = sync_event;
-			pchnl->sync_event = sync_event;
-			/* Get the process handle */
-			pchnl->process = current->tgid;
-			pchnl->pcb_arg = 0;
-			pchnl->bytes_moved = 0;
-			/* Default to proc-copy */
-			pchnl->chnl_type = CHNL_PCPY;
-		} else {
-			status = -ENOMEM;
-		}
+		/* Initialize CHNL object fields: */
+		pchnl->chnl_mgr_obj = chnl_mgr_obj;
+		pchnl->chnl_id = ch_id;
+		pchnl->chnl_mode = chnl_mode;
+		pchnl->user_event = sync_event;
+		pchnl->sync_event = sync_event;
+		/* Get the process handle */
+		pchnl->process = current->tgid;
+		pchnl->pcb_arg = 0;
+		pchnl->bytes_moved = 0;
+		/* Default to proc-copy */
+		pchnl->chnl_type = CHNL_PCPY;
 	}
 
 	if (status) {
 		/* Free memory */
-		if (pchnl->pio_completions) {
-			free_chirp_list(pchnl->pio_completions);
-			pchnl->pio_completions = NULL;
-			pchnl->cio_cs = 0;
-		}
-		if (pchnl->pio_requests) {
-			free_chirp_list(pchnl->pio_requests);
-			pchnl->pio_requests = NULL;
-		}
-		if (pchnl->free_packets_list) {
-			free_chirp_list(pchnl->free_packets_list);
-			pchnl->free_packets_list = NULL;
-		}
+		free_chirp_list(&pchnl->pio_completions);
+		pchnl->cio_cs = 0;
+		free_chirp_list(&pchnl->pio_requests);
+		free_chirp_list(&pchnl->free_packets_list);
 		kfree(sync_event);
 		sync_event = NULL;
 
@@ -924,37 +906,35 @@ int bridge_chnl_register_notify(struct chnl_object *chnl_obj,
  *  Purpose:
  *      Initialize a queue of channel I/O Request/Completion packets.
  *  Parameters:
+ *      list:       Pointer to a list_head
  *      chirps:     Number of Chirps to allocate.
  *  Returns:
- *      Pointer to queue of IRPs, or NULL.
+ *      0 if successful, error code otherwise.
  *  Requires:
  *  Ensures:
  */
-static struct lst_list *create_chirp_list(u32 chirps)
+static int create_chirp_list(struct list_head *list, u32 chirps)
 {
-	struct lst_list *chirp_list;
-	struct chnl_irp *chnl_packet_obj;
+	struct chnl_irp *chirp;
 	u32 i;
 
-	chirp_list = kzalloc(sizeof(struct lst_list), GFP_KERNEL);
+	INIT_LIST_HEAD(list);
 
-	if (chirp_list) {
-		INIT_LIST_HEAD(&chirp_list->head);
-		/* Make N chirps and place on queue. */
-		for (i = 0; (i < chirps)
-		     && ((chnl_packet_obj = make_new_chirp()) != NULL); i++) {
-			lst_put_tail(chirp_list,
-				     (struct list_head *)chnl_packet_obj);
-		}
+	/* Make N chirps and place on queue. */
+	for (i = 0; i < chirps; i++) {
+		chirp = kzalloc(sizeof(struct chnl_irp), GFP_KERNEL);
+		if (!chirp)
+			break;
+		list_add_tail(&chirp->link, list);
+	}
 
-		/* If we couldn't allocate all chirps, free those allocated: */
-		if (i != chirps) {
-			free_chirp_list(chirp_list);
-			chirp_list = NULL;
-		}
+	/* If we couldn't allocate all chirps, free those allocated: */
+	if (i != chirps) {
+		free_chirp_list(list);
+		return -ENOMEM;
 	}
 
-	return chirp_list;
+	return 0;
 }
 
 /*
@@ -962,31 +942,16 @@ static struct lst_list *create_chirp_list(u32 chirps)
  *  Purpose:
  *      Free the queue of Chirps.
  */
-static void free_chirp_list(struct lst_list *chirp_list)
+static void free_chirp_list(struct list_head *chirp_list)
 {
-	DBC_REQUIRE(chirp_list != NULL);
-
-	while (!LST_IS_EMPTY(chirp_list))
-		kfree(lst_get_head(chirp_list));
+	struct chnl_irp *chirp, *tmp;
 
-	kfree(chirp_list);
-}
-
-/*
- *  ======== make_new_chirp ========
- *      Allocate the memory for a new channel IRP.
- */
-static struct chnl_irp *make_new_chirp(void)
-{
-	struct chnl_irp *chnl_packet_obj;
+	DBC_REQUIRE(chirp_list != NULL);
 
-	chnl_packet_obj = kzalloc(sizeof(struct chnl_irp), GFP_KERNEL);
-	if (chnl_packet_obj != NULL) {
-		/* lst_init_elem only resets the list's member values. */
-		lst_init_elem(&chnl_packet_obj->link);
+	list_for_each_entry_safe(chirp, tmp, chirp_list, link) {
+		list_del(&chirp->link);
+		kfree(chirp);
 	}
-
-	return chnl_packet_obj;
 }
 
 /*
diff --git a/drivers/staging/tidspbridge/core/io_sm.c b/drivers/staging/tidspbridge/core/io_sm.c
index 194bada..9851f32 100644
--- a/drivers/staging/tidspbridge/core/io_sm.c
+++ b/drivers/staging/tidspbridge/core/io_sm.c
@@ -24,6 +24,7 @@
  * function.
  */
 #include <linux/types.h>
+#include <linux/list.h>
 
 /* Host OS */
 #include <dspbridge/host_os.h>
@@ -961,15 +962,17 @@ static void input_chnl(struct io_mgr *pio_mgr, struct chnl_object *pchnl,
 	pchnl = chnl_mgr_obj->ap_channel[chnl_id];
 	if ((pchnl != NULL) && CHNL_IS_INPUT(pchnl->chnl_mode)) {
 		if ((pchnl->dw_state & ~CHNL_STATEEOS) == CHNL_STATEREADY) {
-			if (!pchnl->pio_requests)
-				goto func_end;
 			/* Get the I/O request, and attempt a transfer */
-			chnl_packet_obj = (struct chnl_irp *)
-			    lst_get_head(pchnl->pio_requests);
-			if (chnl_packet_obj) {
-				pchnl->cio_reqs--;
-				if (pchnl->cio_reqs < 0)
+			if (!list_empty(&pchnl->pio_requests)) {
+				if (!pchnl->cio_reqs)
 					goto func_end;
+
+				chnl_packet_obj = list_first_entry(
+						&pchnl->pio_requests,
+						struct chnl_irp, link);
+				list_del(&chnl_packet_obj->link);
+				pchnl->cio_reqs--;
+
 				/*
 				 * Ensure we don't overflow the client's
 				 * buffer.
@@ -996,21 +999,18 @@ static void input_chnl(struct io_mgr *pio_mgr, struct chnl_object *pchnl,
 					 * the channel state.
 					 */
 					chnl_packet_obj->status |=
-					    CHNL_IOCSTATEOS;
+						CHNL_IOCSTATEOS;
 					pchnl->dw_state |= CHNL_STATEEOS;
 					/*
 					 * Notify that end of stream has
 					 * occurred.
 					 */
 					ntfy_notify(pchnl->ntfy_obj,
-						    DSP_STREAMDONE);
+							DSP_STREAMDONE);
 				}
 				/* Tell DSP if no more I/O buffers available */
-				if (!pchnl->pio_requests)
-					goto func_end;
-				if (LST_IS_EMPTY(pchnl->pio_requests)) {
+				if (list_empty(&pchnl->pio_requests))
 					set_chnl_free(sm, pchnl->chnl_id);
-				}
 				clear_chnl = true;
 				notify_client = true;
 			} else {
@@ -1082,21 +1082,18 @@ static void input_msg(struct io_mgr *pio_mgr, struct msg_mgr *hmsg_mgr)
 		msg.msgq_id =
 		    read_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr);
 		msg_input += sizeof(struct msg_dspmsg);
-		if (!hmsg_mgr->queue_list)
-			goto func_end;
 
 		/* Determine which queue to put the message in */
-		msg_queue_obj =
-		    (struct msg_queue *)lst_first(hmsg_mgr->queue_list);
 		dev_dbg(bridge,	"input msg: dw_cmd=0x%x dw_arg1=0x%x "
-			"dw_arg2=0x%x msgq_id=0x%x \n", msg.msg.dw_cmd,
+			"dw_arg2=0x%x msgq_id=0x%x\n", msg.msg.dw_cmd,
 			msg.msg.dw_arg1, msg.msg.dw_arg2, msg.msgq_id);
 		/*
 		 * Interrupt may occur before shared memory and message
 		 * input locations have been set up. If all nodes were
 		 * cleaned up, hmsg_mgr->max_msgs should be 0.
 		 */
-		while (msg_queue_obj != NULL) {
+		list_for_each_entry(msg_queue_obj, &hmsg_mgr->queue_list,
+				list_elem) {
 			if (msg.msgq_id == msg_queue_obj->msgq_id) {
 				/* Found it */
 				if (msg.msg.dw_cmd == RMS_EXITACK) {
@@ -1106,47 +1103,38 @@ static void input_msg(struct io_mgr *pio_mgr, struct msg_mgr *hmsg_mgr)
 					 * queued.
 					 */
 					(*hmsg_mgr->on_exit) ((void *)
-							   msg_queue_obj->arg,
-							   msg.msg.dw_arg1);
+							msg_queue_obj->arg,
+							msg.msg.dw_arg1);
+					break;
+				}
+				/*
+				 * Not an exit acknowledgement, queue
+				 * the message.
+				 */
+				if (!list_empty(&msg_queue_obj->msg_free_list)) {
+					pmsg = list_first_entry(
+						&msg_queue_obj->msg_free_list,
+						struct msg_frame, list_elem);
+					list_del(&pmsg->list_elem);
+					pmsg->msg_data = msg;
+					list_add_tail(&pmsg->list_elem,
+						&msg_queue_obj->msg_used_list);
+					ntfy_notify
+						(msg_queue_obj->ntfy_obj,
+						 DSP_NODEMESSAGEREADY);
+					sync_set_event
+						(msg_queue_obj->sync_event);
 				} else {
 					/*
-					 * Not an exit acknowledgement, queue
-					 * the message.
+					 * No free frame to copy the
+					 * message into.
 					 */
-					if (!msg_queue_obj->msg_free_list)
-						goto func_end;
-					pmsg = (struct msg_frame *)lst_get_head
-					    (msg_queue_obj->msg_free_list);
-					if (msg_queue_obj->msg_used_list
-					    && pmsg) {
-						pmsg->msg_data = msg;
-						lst_put_tail
-						 (msg_queue_obj->msg_used_list,
-						     (struct list_head *)pmsg);
-						ntfy_notify
-						    (msg_queue_obj->ntfy_obj,
-						     DSP_NODEMESSAGEREADY);
-						sync_set_event
-						    (msg_queue_obj->sync_event);
-					} else {
-						/*
-						 * No free frame to copy the
-						 * message into.
-						 */
-						pr_err("%s: no free msg frames,"
-						       " discarding msg\n",
-						       __func__);
-					}
+					pr_err("%s: no free msg frames,"
+							" discarding msg\n",
+							__func__);
 				}
 				break;
 			}
-
-			if (!hmsg_mgr->queue_list || !msg_queue_obj)
-				goto func_end;
-			msg_queue_obj =
-			    (struct msg_queue *)lst_next(hmsg_mgr->queue_list,
-							 (struct list_head *)
-							 msg_queue_obj);
 		}
 	}
 	/* Set the post SWI flag */
@@ -1170,8 +1158,7 @@ static void notify_chnl_complete(struct chnl_object *pchnl,
 {
 	bool signal_event;
 
-	if (!pchnl || !pchnl->sync_event ||
-	    !pchnl->pio_completions || !chnl_packet_obj)
+	if (!pchnl || !pchnl->sync_event || !chnl_packet_obj)
 		goto func_end;
 
 	/*
@@ -1180,10 +1167,9 @@ static void notify_chnl_complete(struct chnl_object *pchnl,
 	 * signalled by the only IO completion list consumer:
 	 * bridge_chnl_get_ioc().
 	 */
-	signal_event = LST_IS_EMPTY(pchnl->pio_completions);
+	signal_event = list_empty(&pchnl->pio_completions);
 	/* Enqueue the IO completion info for the client */
-	lst_put_tail(pchnl->pio_completions,
-		     (struct list_head *)chnl_packet_obj);
+	list_add_tail(&chnl_packet_obj->link, &pchnl->pio_completions);
 	pchnl->cio_cs++;
 
 	if (pchnl->cio_cs > pchnl->chnl_packets)
@@ -1230,21 +1216,23 @@ static void output_chnl(struct io_mgr *pio_mgr, struct chnl_object *pchnl,
 		goto func_end;
 
 	pchnl = chnl_mgr_obj->ap_channel[chnl_id];
-	if (!pchnl || !pchnl->pio_requests) {
+	if (!pchnl || list_empty(&pchnl->pio_requests)) {
 		/* Shouldn't get here */
 		goto func_end;
 	}
-	/* Get the I/O request, and attempt a transfer */
-	chnl_packet_obj = (struct chnl_irp *)lst_get_head(pchnl->pio_requests);
-	if (!chnl_packet_obj)
+
+	if (!pchnl->cio_reqs)
 		goto func_end;
 
+	/* Get the I/O request, and attempt a transfer */
+	chnl_packet_obj = list_first_entry(&pchnl->pio_requests,
+			struct chnl_irp, link);
+	list_del(&chnl_packet_obj->link);
+
 	pchnl->cio_reqs--;
-	if (pchnl->cio_reqs < 0 || !pchnl->pio_requests)
-		goto func_end;
 
 	/* Record fact that no more I/O buffers available */
-	if (LST_IS_EMPTY(pchnl->pio_requests))
+	if (list_empty(&pchnl->pio_requests))
 		chnl_mgr_obj->dw_output_mask &= ~(1 << chnl_id);
 
 	/* Transfer buffer to DSP side */
@@ -1305,14 +1293,11 @@ static void output_msg(struct io_mgr *pio_mgr, struct msg_mgr *hmsg_mgr)
 		msg_output = pio_mgr->msg_output;
 		/* Copy num_msgs messages into shared memory */
 		for (i = 0; i < num_msgs; i++) {
-			if (!hmsg_mgr->msg_used_list) {
-				pmsg = NULL;
-				goto func_end;
-			} else {
-				pmsg = (struct msg_frame *)
-				    lst_get_head(hmsg_mgr->msg_used_list);
-			}
-			if (pmsg != NULL) {
+			if (!list_empty(&hmsg_mgr->msg_used_list)) {
+				pmsg = list_first_entry(
+						&hmsg_mgr->msg_used_list,
+						struct msg_frame, list_elem);
+				list_del(&pmsg->list_elem);
 				val = (pmsg->msg_data).msgq_id;
 				addr = (u32) &(((struct msg_dspmsg *)
 						 msg_output)->msgq_id);
@@ -1334,10 +1319,8 @@ static void output_msg(struct io_mgr *pio_mgr, struct msg_mgr *hmsg_mgr)
 				write_ext32_bit_dsp_data(
 					pio_mgr->hbridge_context, addr, val);
 				msg_output += sizeof(struct msg_dspmsg);
-				if (!hmsg_mgr->msg_free_list)
-					goto func_end;
-				lst_put_tail(hmsg_mgr->msg_free_list,
-					     (struct list_head *)pmsg);
+				list_add_tail(&pmsg->list_elem,
+						&hmsg_mgr->msg_free_list);
 				sync_set_event(hmsg_mgr->sync_event);
 			}
 		}
@@ -1361,8 +1344,6 @@ static void output_msg(struct io_mgr *pio_mgr, struct msg_mgr *hmsg_mgr)
 						MBX_PCPY_CLASS);
 		}
 	}
-func_end:
-	return;
 }
 
 /*
diff --git a/drivers/staging/tidspbridge/core/msg_sm.c b/drivers/staging/tidspbridge/core/msg_sm.c
index 87712e2..de2cb83 100644
--- a/drivers/staging/tidspbridge/core/msg_sm.c
+++ b/drivers/staging/tidspbridge/core/msg_sm.c
@@ -24,7 +24,6 @@
 #include <dspbridge/dbc.h>
 
 /*  ----------------------------------- OS Adaptation Layer */
-#include <dspbridge/list.h>
 #include <dspbridge/sync.h>
 
 /*  ----------------------------------- Platform Manager */
@@ -38,10 +37,10 @@
 #include <dspbridge/dspmsg.h>
 
 /*  ----------------------------------- Function Prototypes */
-static int add_new_msg(struct lst_list *msg_list);
+static int add_new_msg(struct list_head *msg_list);
 static void delete_msg_mgr(struct msg_mgr *hmsg_mgr);
 static void delete_msg_queue(struct msg_queue *msg_queue_obj, u32 num_to_dsp);
-static void free_msg_list(struct lst_list *msg_list);
+static void free_msg_list(struct list_head *msg_list);
 
 /*
  *  ======== bridge_msg_create ========
@@ -73,25 +72,13 @@ int bridge_msg_create(struct msg_mgr **msg_man,
 		msg_mgr_obj->on_exit = msg_callback;
 		msg_mgr_obj->hio_mgr = hio_mgr;
 		/* List of MSG_QUEUEs */
-		msg_mgr_obj->queue_list = kzalloc(sizeof(struct lst_list),
-							GFP_KERNEL);
+		INIT_LIST_HEAD(&msg_mgr_obj->queue_list);
 		/*  Queues of message frames for messages to the DSP. Message
 		 * frames will only be added to the free queue when a
 		 * msg_queue object is created. */
-		msg_mgr_obj->msg_free_list = kzalloc(sizeof(struct lst_list),
-							GFP_KERNEL);
-		msg_mgr_obj->msg_used_list = kzalloc(sizeof(struct lst_list),
-							GFP_KERNEL);
-		if (msg_mgr_obj->queue_list == NULL ||
-		    msg_mgr_obj->msg_free_list == NULL ||
-		    msg_mgr_obj->msg_used_list == NULL) {
-			status = -ENOMEM;
-		} else {
-			INIT_LIST_HEAD(&msg_mgr_obj->queue_list->head);
-			INIT_LIST_HEAD(&msg_mgr_obj->msg_free_list->head);
-			INIT_LIST_HEAD(&msg_mgr_obj->msg_used_list->head);
-			spin_lock_init(&msg_mgr_obj->msg_mgr_lock);
-		}
+		INIT_LIST_HEAD(&msg_mgr_obj->msg_free_list);
+		INIT_LIST_HEAD(&msg_mgr_obj->msg_used_list);
+		spin_lock_init(&msg_mgr_obj->msg_mgr_lock);
 
 		/*  Create an event to be used by bridge_msg_put() in waiting
 		 *  for an available free frame from the message manager. */
@@ -128,7 +115,7 @@ int bridge_msg_create_queue(struct msg_mgr *hmsg_mgr,
 	struct msg_queue *msg_q;
 	int status = 0;
 
-	if (!hmsg_mgr || msgq == NULL || !hmsg_mgr->msg_free_list) {
+	if (!hmsg_mgr || msgq == NULL) {
 		status = -EFAULT;
 		goto func_end;
 	}
@@ -140,20 +127,13 @@ int bridge_msg_create_queue(struct msg_mgr *hmsg_mgr,
 		status = -ENOMEM;
 		goto func_end;
 	}
-	lst_init_elem((struct list_head *)msg_q);
 	msg_q->max_msgs = max_msgs;
 	msg_q->hmsg_mgr = hmsg_mgr;
 	msg_q->arg = arg;	/* Node handle */
 	msg_q->msgq_id = msgq_id;	/* Node env (not valid yet) */
 	/* Queues of Message frames for messages from the DSP */
-	msg_q->msg_free_list = kzalloc(sizeof(struct lst_list), GFP_KERNEL);
-	msg_q->msg_used_list = kzalloc(sizeof(struct lst_list), GFP_KERNEL);
-	if (msg_q->msg_free_list == NULL || msg_q->msg_used_list == NULL)
-		status = -ENOMEM;
-	else {
-		INIT_LIST_HEAD(&msg_q->msg_free_list->head);
-		INIT_LIST_HEAD(&msg_q->msg_used_list->head);
-	}
+	INIT_LIST_HEAD(&msg_q->msg_free_list);
+	INIT_LIST_HEAD(&msg_q->msg_used_list);
 
 	/*  Create event that will be signalled when a message from
 	 *  the DSP is available. */
@@ -204,10 +184,10 @@ int bridge_msg_create_queue(struct msg_mgr *hmsg_mgr,
 		spin_lock_bh(&hmsg_mgr->msg_mgr_lock);
 		/* Initialize message frames and put in appropriate queues */
 		for (i = 0; i < max_msgs && !status; i++) {
-			status = add_new_msg(hmsg_mgr->msg_free_list);
+			status = add_new_msg(&hmsg_mgr->msg_free_list);
 			if (!status) {
 				num_allocated++;
-				status = add_new_msg(msg_q->msg_free_list);
+				status = add_new_msg(&msg_q->msg_free_list);
 			}
 		}
 		if (status) {
@@ -215,11 +195,11 @@ int bridge_msg_create_queue(struct msg_mgr *hmsg_mgr,
 			 *  of the newly allocated message frames. */
 			delete_msg_queue(msg_q, num_allocated);
 		} else {
-			lst_put_tail(hmsg_mgr->queue_list,
-				     (struct list_head *)msg_q);
+			list_add_tail(&msg_q->list_elem,
+					&hmsg_mgr->queue_list);
 			*msgq = msg_q;
 			/* Signal that free frames are now available */
-			if (!LST_IS_EMPTY(hmsg_mgr->msg_free_list))
+			if (!list_empty(&hmsg_mgr->msg_free_list))
 				sync_set_event(hmsg_mgr->sync_event);
 
 		}
@@ -267,15 +247,12 @@ void bridge_msg_delete_queue(struct msg_queue *msg_queue_obj)
 	}
 	/* Remove message queue from hmsg_mgr->queue_list */
 	spin_lock_bh(&hmsg_mgr->msg_mgr_lock);
-	lst_remove_elem(hmsg_mgr->queue_list,
-			(struct list_head *)msg_queue_obj);
+	list_del(&msg_queue_obj->list_elem);
 	/* Free the message queue object */
 	delete_msg_queue(msg_queue_obj, msg_queue_obj->max_msgs);
-	if (!hmsg_mgr->msg_free_list)
-		goto func_cont;
-	if (LST_IS_EMPTY(hmsg_mgr->msg_free_list))
+	if (list_empty(&hmsg_mgr->msg_free_list))
 		sync_reset_event(hmsg_mgr->sync_event);
-func_cont:
+
 	spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
 func_end:
 	return;
@@ -301,26 +278,21 @@ int bridge_msg_get(struct msg_queue *msg_queue_obj,
 	}
 
 	hmsg_mgr = msg_queue_obj->hmsg_mgr;
-	if (!msg_queue_obj->msg_used_list) {
-		status = -EFAULT;
-		goto func_end;
-	}
 
 	/* Enter critical section */
 	spin_lock_bh(&hmsg_mgr->msg_mgr_lock);
 	/* If a message is already there, get it */
-	if (!LST_IS_EMPTY(msg_queue_obj->msg_used_list)) {
-		msg_frame_obj = (struct msg_frame *)
-		    lst_get_head(msg_queue_obj->msg_used_list);
-		if (msg_frame_obj != NULL) {
-			*pmsg = msg_frame_obj->msg_data.msg;
-			lst_put_tail(msg_queue_obj->msg_free_list,
-				     (struct list_head *)msg_frame_obj);
-			if (LST_IS_EMPTY(msg_queue_obj->msg_used_list))
-				sync_reset_event(msg_queue_obj->sync_event);
-
-			got_msg = true;
-		}
+	if (!list_empty(&msg_queue_obj->msg_used_list)) {
+		msg_frame_obj = list_first_entry(&msg_queue_obj->msg_used_list,
+				struct msg_frame, list_elem);
+		list_del(&msg_frame_obj->list_elem);
+		*pmsg = msg_frame_obj->msg_data.msg;
+		list_add_tail(&msg_frame_obj->list_elem,
+				&msg_queue_obj->msg_free_list);
+		if (list_empty(&msg_queue_obj->msg_used_list))
+			sync_reset_event(msg_queue_obj->sync_event);
+
+		got_msg = true;
 	} else {
 		if (msg_queue_obj->done)
 			status = -EPERM;
@@ -349,25 +321,22 @@ int bridge_msg_get(struct msg_queue *msg_queue_obj,
 			(void)sync_set_event(msg_queue_obj->sync_done_ack);
 			status = -EPERM;
 		} else {
-			if (!status) {
-				DBC_ASSERT(!LST_IS_EMPTY
-					   (msg_queue_obj->msg_used_list));
+			if (!status && !list_empty(&msg_queue_obj->
+						msg_used_list)) {
 				/* Get msg from used list */
-				msg_frame_obj = (struct msg_frame *)
-				    lst_get_head(msg_queue_obj->msg_used_list);
+				msg_frame_obj = list_first_entry(
+						&msg_queue_obj->msg_used_list,
+						struct msg_frame, list_elem);
+				list_del(&msg_frame_obj->list_elem);
 				/* Copy message into pmsg and put frame on the
 				 * free list */
-				if (msg_frame_obj != NULL) {
-					*pmsg = msg_frame_obj->msg_data.msg;
-					lst_put_tail
-					    (msg_queue_obj->msg_free_list,
-					     (struct list_head *)
-					     msg_frame_obj);
-				}
+				*pmsg = msg_frame_obj->msg_data.msg;
+				list_add_tail(&msg_frame_obj->list_elem,
+						&msg_queue_obj->msg_free_list);
 			}
 			msg_queue_obj->io_msg_pend--;
 			/* Reset the event if there are still queued messages */
-			if (!LST_IS_EMPTY(msg_queue_obj->msg_used_list))
+			if (!list_empty(&msg_queue_obj->msg_used_list))
 				sync_set_event(msg_queue_obj->sync_event);
 
 			/* Exit critical section */
@@ -397,27 +366,22 @@ int bridge_msg_put(struct msg_queue *msg_queue_obj,
 		goto func_end;
 	}
 	hmsg_mgr = msg_queue_obj->hmsg_mgr;
-	if (!hmsg_mgr->msg_free_list) {
-		status = -EFAULT;
-		goto func_end;
-	}
 
 	spin_lock_bh(&hmsg_mgr->msg_mgr_lock);
 
 	/* If a message frame is available, use it */
-	if (!LST_IS_EMPTY(hmsg_mgr->msg_free_list)) {
-		msg_frame_obj =
-		    (struct msg_frame *)lst_get_head(hmsg_mgr->msg_free_list);
-		if (msg_frame_obj != NULL) {
-			msg_frame_obj->msg_data.msg = *pmsg;
-			msg_frame_obj->msg_data.msgq_id =
-			    msg_queue_obj->msgq_id;
-			lst_put_tail(hmsg_mgr->msg_used_list,
-				     (struct list_head *)msg_frame_obj);
-			hmsg_mgr->msgs_pending++;
-			put_msg = true;
-		}
-		if (LST_IS_EMPTY(hmsg_mgr->msg_free_list))
+	if (!list_empty(&hmsg_mgr->msg_free_list)) {
+		msg_frame_obj = list_first_entry(&hmsg_mgr->msg_free_list,
+				struct msg_frame, list_elem);
+		list_del(&msg_frame_obj->list_elem);
+		msg_frame_obj->msg_data.msg = *pmsg;
+		msg_frame_obj->msg_data.msgq_id =
+			msg_queue_obj->msgq_id;
+		list_add_tail(&msg_frame_obj->list_elem,
+				&hmsg_mgr->msg_used_list);
+		hmsg_mgr->msgs_pending++;
+		put_msg = true;
+		if (list_empty(&hmsg_mgr->msg_free_list))
 			sync_reset_event(hmsg_mgr->sync_event);
 
 		/* Release critical section before scheduling DPC */
@@ -452,34 +416,34 @@ int bridge_msg_put(struct msg_queue *msg_queue_obj,
 			(void)sync_set_event(msg_queue_obj->sync_done_ack);
 			status = -EPERM;
 		} else {
-			if (LST_IS_EMPTY(hmsg_mgr->msg_free_list)) {
+			if (list_empty(&hmsg_mgr->msg_free_list)) {
 				status = -EFAULT;
 				goto func_cont;
 			}
 			/* Get msg from free list */
-			msg_frame_obj = (struct msg_frame *)
-			    lst_get_head(hmsg_mgr->msg_free_list);
+			msg_frame_obj = list_first_entry(
+					&hmsg_mgr->msg_free_list,
+					struct msg_frame, list_elem);
+			list_del(&msg_frame_obj->list_elem);
 			/*
 			 * Copy message into pmsg and put frame on the
 			 * used list.
 			 */
-			if (msg_frame_obj) {
-				msg_frame_obj->msg_data.msg = *pmsg;
-				msg_frame_obj->msg_data.msgq_id =
-				    msg_queue_obj->msgq_id;
-				lst_put_tail(hmsg_mgr->msg_used_list,
-					     (struct list_head *)msg_frame_obj);
-				hmsg_mgr->msgs_pending++;
-				/*
-				 * Schedule a DPC, to do the actual
-				 * data transfer.
-				 */
-				iosm_schedule(hmsg_mgr->hio_mgr);
-			}
+			msg_frame_obj->msg_data.msg = *pmsg;
+			msg_frame_obj->msg_data.msgq_id =
+				msg_queue_obj->msgq_id;
+			list_add_tail(&msg_frame_obj->list_elem,
+					&hmsg_mgr->msg_used_list);
+			hmsg_mgr->msgs_pending++;
+			/*
+			 * Schedule a DPC, to do the actual
+			 * data transfer.
+			 */
+			iosm_schedule(hmsg_mgr->hio_mgr);
 
 			msg_queue_obj->io_msg_pend--;
 			/* Reset event if there are still frames available */
-			if (!LST_IS_EMPTY(hmsg_mgr->msg_free_list))
+			if (!list_empty(&hmsg_mgr->msg_free_list))
 				sync_set_event(hmsg_mgr->sync_event);
 func_cont:
 			/* Exit critical section */
@@ -551,15 +515,14 @@ void bridge_msg_set_queue_id(struct msg_queue *msg_queue_obj, u32 msgq_id)
  *  ======== add_new_msg ========
  *      Must be called in message manager critical section.
  */
-static int add_new_msg(struct lst_list *msg_list)
+static int add_new_msg(struct list_head *msg_list)
 {
 	struct msg_frame *pmsg;
 	int status = 0;
 
 	pmsg = kzalloc(sizeof(struct msg_frame), GFP_ATOMIC);
 	if (pmsg != NULL) {
-		lst_init_elem((struct list_head *)pmsg);
-		lst_put_tail(msg_list, (struct list_head *)pmsg);
+		list_add_tail(&pmsg->list_elem, msg_list);
 	} else {
 		status = -ENOMEM;
 	}
@@ -575,22 +538,9 @@ static void delete_msg_mgr(struct msg_mgr *hmsg_mgr)
 	if (!hmsg_mgr)
 		goto func_end;
 
-	if (hmsg_mgr->queue_list) {
-		if (LST_IS_EMPTY(hmsg_mgr->queue_list)) {
-			kfree(hmsg_mgr->queue_list);
-			hmsg_mgr->queue_list = NULL;
-		}
-	}
-
-	if (hmsg_mgr->msg_free_list) {
-		free_msg_list(hmsg_mgr->msg_free_list);
-		hmsg_mgr->msg_free_list = NULL;
-	}
-
-	if (hmsg_mgr->msg_used_list) {
-		free_msg_list(hmsg_mgr->msg_used_list);
-		hmsg_mgr->msg_used_list = NULL;
-	}
+	/* FIXME: free elements from queue_list? */
+	free_msg_list(&hmsg_mgr->msg_free_list);
+	free_msg_list(&hmsg_mgr->msg_used_list);
 
 	kfree(hmsg_mgr->sync_event);
 
@@ -605,37 +555,26 @@ func_end:
 static void delete_msg_queue(struct msg_queue *msg_queue_obj, u32 num_to_dsp)
 {
 	struct msg_mgr *hmsg_mgr;
-	struct msg_frame *pmsg;
+	struct msg_frame *pmsg, *tmp;
 	u32 i;
 
-	if (!msg_queue_obj ||
-	    !msg_queue_obj->hmsg_mgr || !msg_queue_obj->hmsg_mgr->msg_free_list)
+	if (!msg_queue_obj || !msg_queue_obj->hmsg_mgr)
 		goto func_end;
 
 	hmsg_mgr = msg_queue_obj->hmsg_mgr;
 
 	/* Pull off num_to_dsp message frames from Msg manager and free */
-	for (i = 0; i < num_to_dsp; i++) {
-
-		if (!LST_IS_EMPTY(hmsg_mgr->msg_free_list)) {
-			pmsg = (struct msg_frame *)
-			    lst_get_head(hmsg_mgr->msg_free_list);
-			kfree(pmsg);
-		} else {
-			/* Cannot free all of the message frames */
+	i = 0;
+	list_for_each_entry_safe(pmsg, tmp, &hmsg_mgr->msg_free_list,
+			list_elem) {
+		list_del(&pmsg->list_elem);
+		kfree(pmsg);
+		if (i++ >= num_to_dsp)
 			break;
-		}
 	}
 
-	if (msg_queue_obj->msg_free_list) {
-		free_msg_list(msg_queue_obj->msg_free_list);
-		msg_queue_obj->msg_free_list = NULL;
-	}
-
-	if (msg_queue_obj->msg_used_list) {
-		free_msg_list(msg_queue_obj->msg_used_list);
-		msg_queue_obj->msg_used_list = NULL;
-	}
+	free_msg_list(&msg_queue_obj->msg_free_list);
+	free_msg_list(&msg_queue_obj->msg_used_list);
 
 	if (msg_queue_obj->ntfy_obj) {
 		ntfy_delete(msg_queue_obj->ntfy_obj);
@@ -655,19 +594,18 @@ func_end:
 /*
  *  ======== free_msg_list ========
  */
-static void free_msg_list(struct lst_list *msg_list)
+static void free_msg_list(struct list_head *msg_list)
 {
-	struct msg_frame *pmsg;
+	struct msg_frame *pmsg, *tmp;
 
 	if (!msg_list)
 		goto func_end;
 
-	while ((pmsg = (struct msg_frame *)lst_get_head(msg_list)) != NULL)
+	list_for_each_entry_safe(pmsg, tmp, msg_list, list_elem) {
+		list_del(&pmsg->list_elem);
 		kfree(pmsg);
+	}
 
-	DBC_ASSERT(LST_IS_EMPTY(msg_list));
-
-	kfree(msg_list);
 func_end:
 	return;
 }
diff --git a/drivers/staging/tidspbridge/include/dspbridge/_chnl_sm.h b/drivers/staging/tidspbridge/include/dspbridge/_chnl_sm.h
index 8efd1fb..8a22317 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/_chnl_sm.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/_chnl_sm.h
@@ -26,7 +26,7 @@
 #include <dspbridge/dspapi.h>
 #include <dspbridge/dspdefs.h>
 
-#include <dspbridge/list.h>
+#include <linux/list.h>
 #include <dspbridge/ntfy.h>
 
 /*
@@ -148,13 +148,13 @@ struct chnl_object {
 	struct sync_object *sync_event;
 	u32 process;		/* Process which created this channel */
 	u32 pcb_arg;		/* Argument to use with callback */
-	struct lst_list *pio_requests;	/* List of IOR's to driver */
+	struct list_head pio_requests;	/* List of IOR's to driver */
 	s32 cio_cs;		/* Number of IOC's in queue */
 	s32 cio_reqs;		/* Number of IORequests in queue */
 	s32 chnl_packets;	/* Initial number of free Irps */
 	/* List of IOC's from driver */
-	struct lst_list *pio_completions;
-	struct lst_list *free_packets_list;	/* List of free Irps */
+	struct list_head pio_completions;
+	struct list_head free_packets_list;	/* List of free Irps */
 	struct ntfy_object *ntfy_obj;
 	u32 bytes_moved;	/* Total number of bytes transfered */
 
diff --git a/drivers/staging/tidspbridge/include/dspbridge/cmmdefs.h b/drivers/staging/tidspbridge/include/dspbridge/cmmdefs.h
index fbff372..e748ba8 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/cmmdefs.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/cmmdefs.h
@@ -19,7 +19,6 @@
 #ifndef CMMDEFS_
 #define CMMDEFS_
 
-#include <dspbridge/list.h>
 
 /* Cmm attributes used in cmm_create() */
 struct cmm_mgrattrs {
diff --git a/drivers/staging/tidspbridge/include/dspbridge/sync.h b/drivers/staging/tidspbridge/include/dspbridge/sync.h
index e2651e7..630beac 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/sync.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/sync.h
@@ -20,6 +20,7 @@
 #define _SYNC_H
 
 #include <dspbridge/dbdefs.h>
+#include <dspbridge/host_os.h>
 
 
 /* Special timeout value indicating an infinite wait: */
-- 
1.7.2.3


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

* [PATCH v2 07/12] staging: tidspbridge: convert pmgr to list_head
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
                   ` (5 preceding siblings ...)
  2010-11-05 15:13 ` [PATCH v2 06/12] staging: tidspbridge: convert core to list_head Ionut Nicu
@ 2010-11-05 15:13 ` Ionut Nicu
  2010-11-05 22:41   ` Sapiens, Rene
  2010-11-05 15:13 ` [PATCH v2 08/12] staging: tidspbridge: convert rmgr " Ionut Nicu
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

Convert the pmgr module of the tidspbridge driver
to use struct list_head instead of struct lst_list.

Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
---
 drivers/staging/tidspbridge/pmgr/cmm.c |  230 ++++++++++----------------------
 drivers/staging/tidspbridge/pmgr/dev.c |   59 +++-----
 2 files changed, 93 insertions(+), 196 deletions(-)

diff --git a/drivers/staging/tidspbridge/pmgr/cmm.c b/drivers/staging/tidspbridge/pmgr/cmm.c
index 8dbdd20..603ed55 100644
--- a/drivers/staging/tidspbridge/pmgr/cmm.c
+++ b/drivers/staging/tidspbridge/pmgr/cmm.c
@@ -12,7 +12,7 @@
  * describes a block of physically contiguous shared memory used for
  * future allocations by CMM.
  *
- * Memory is coelesced back to the appropriate heap when a buffer is
+ * Memory is coalesced back to the appropriate heap when a buffer is
  * freed.
  *
  * Notes:
@@ -30,6 +30,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 #include <linux/types.h>
+#include <linux/list.h>
 
 /*  ----------------------------------- DSP/BIOS Bridge */
 #include <dspbridge/dbdefs.h>
@@ -38,7 +39,6 @@
 #include <dspbridge/dbc.h>
 
 /*  ----------------------------------- OS Adaptation Layer */
-#include <dspbridge/list.h>
 #include <dspbridge/sync.h>
 
 /*  ----------------------------------- Platform Manager */
@@ -73,9 +73,9 @@ struct cmm_allocator {		/* sma */
 	u32 ul_dsp_size;	/* DSP seg size in bytes */
 	struct cmm_object *hcmm_mgr;	/* back ref to parent mgr */
 	/* node list of available memory */
-	struct lst_list *free_list_head;
+	struct list_head free_list;
 	/* node list of memory in use */
-	struct lst_list *in_use_list_head;
+	struct list_head in_use_list;
 };
 
 struct cmm_xlator {		/* Pa<->Va translator object */
@@ -97,7 +97,7 @@ struct cmm_object {
 	 * Cmm Lock is used to serialize access mem manager for multi-threads.
 	 */
 	struct mutex cmm_lock;	/* Lock to access cmm mgr */
-	struct lst_list *node_free_list_head;	/* Free list of memory nodes */
+	struct list_head node_free_list;	/* Free list of memory nodes */
 	u32 ul_min_block_size;	/* Min SM block; default 16 bytes */
 	u32 dw_page_size;	/* Memory Page size (1k/4k) */
 	/* GPP SM segment ptrs */
@@ -215,8 +215,7 @@ void *cmm_calloc_buf(struct cmm_object *hcmm_mgr, u32 usize,
 			pnode->client_proc = current->tgid;
 
 			/* put our node on InUse list */
-			lst_put_tail(allocator->in_use_list_head,
-				     (struct list_head *)pnode);
+			list_add_tail(&pnode->link, &allocator->in_use_list);
 			buf_pa = (void *)pnode->dw_pa;	/* physical address */
 			/* clear mem */
 			pbyte = (u8 *) pnode->dw_va;
@@ -265,18 +264,9 @@ int cmm_create(struct cmm_object **ph_cmm_mgr,
 		 * MEM_ALLOC_OBJECT */
 
 		/* create node free list */
-		cmm_obj->node_free_list_head =
-				kzalloc(sizeof(struct lst_list),
-						GFP_KERNEL);
-		if (cmm_obj->node_free_list_head == NULL) {
-			status = -ENOMEM;
-			cmm_destroy(cmm_obj, true);
-		} else {
-			INIT_LIST_HEAD(&cmm_obj->
-				       node_free_list_head->head);
-			mutex_init(&cmm_obj->cmm_lock);
-			*ph_cmm_mgr = cmm_obj;
-		}
+		INIT_LIST_HEAD(&cmm_obj->node_free_list);
+		mutex_init(&cmm_obj->cmm_lock);
+		*ph_cmm_mgr = cmm_obj;
 	} else {
 		status = -ENOMEM;
 	}
@@ -294,7 +284,7 @@ int cmm_destroy(struct cmm_object *hcmm_mgr, bool force)
 	struct cmm_info temp_info;
 	int status = 0;
 	s32 slot_seg;
-	struct cmm_mnode *pnode;
+	struct cmm_mnode *node, *tmp;
 
 	DBC_REQUIRE(refs > 0);
 	if (!hcmm_mgr) {
@@ -324,15 +314,10 @@ int cmm_destroy(struct cmm_object *hcmm_mgr, bool force)
 			}
 		}
 	}
-	if (cmm_mgr_obj->node_free_list_head != NULL) {
-		/* Free the free nodes */
-		while (!LST_IS_EMPTY(cmm_mgr_obj->node_free_list_head)) {
-			pnode = (struct cmm_mnode *)
-			    lst_get_head(cmm_mgr_obj->node_free_list_head);
-			kfree(pnode);
-		}
-		/* delete NodeFreeList list */
-		kfree(cmm_mgr_obj->node_free_list_head);
+	list_for_each_entry_safe(node, tmp, &cmm_mgr_obj->node_free_list,
+			link) {
+		list_del(&node->link);
+		kfree(node);
 	}
 	mutex_unlock(&cmm_mgr_obj->cmm_lock);
 	if (!status) {
@@ -366,7 +351,7 @@ int cmm_free_buf(struct cmm_object *hcmm_mgr, void *buf_pa,
 {
 	struct cmm_object *cmm_mgr_obj = (struct cmm_object *)hcmm_mgr;
 	int status = -EFAULT;
-	struct cmm_mnode *mnode_obj = NULL;
+	struct cmm_mnode *curr, *tmp;
 	struct cmm_allocator *allocator = NULL;
 	struct cmm_attrs *pattrs;
 
@@ -385,22 +370,14 @@ int cmm_free_buf(struct cmm_object *hcmm_mgr, void *buf_pa,
 	allocator = get_allocator(cmm_mgr_obj, ul_seg_id);
 	if (allocator != NULL) {
 		mutex_lock(&cmm_mgr_obj->cmm_lock);
-		mnode_obj =
-		    (struct cmm_mnode *)lst_first(allocator->in_use_list_head);
-		while (mnode_obj) {
-			if ((u32) buf_pa == mnode_obj->dw_pa) {
-				/* Found it */
-				lst_remove_elem(allocator->in_use_list_head,
-						(struct list_head *)mnode_obj);
-				/* back to freelist */
-				add_to_free_list(allocator, mnode_obj);
-				status = 0;	/* all right! */
+		list_for_each_entry_safe(curr, tmp, &allocator->in_use_list,
+				link) {
+			if (curr->dw_pa == (u32) buf_pa) {
+				list_del(&curr->link);
+				add_to_free_list(allocator, curr);
+				status = 0;
 				break;
 			}
-			/* next node. */
-			mnode_obj = (struct cmm_mnode *)
-			    lst_next(allocator->in_use_list_head,
-				     (struct list_head *)mnode_obj);
 		}
 		mutex_unlock(&cmm_mgr_obj->cmm_lock);
 	}
@@ -443,7 +420,7 @@ int cmm_get_info(struct cmm_object *hcmm_mgr,
 	u32 ul_seg;
 	int status = 0;
 	struct cmm_allocator *altr;
-	struct cmm_mnode *mnode_obj = NULL;
+	struct cmm_mnode *curr;
 
 	DBC_REQUIRE(cmm_info_obj != NULL);
 
@@ -478,17 +455,11 @@ int cmm_get_info(struct cmm_object *hcmm_mgr,
 			cmm_info_obj->seg_info[ul_seg - 1].dw_seg_base_va =
 			    altr->dw_vm_base - altr->ul_dsp_size;
 			cmm_info_obj->seg_info[ul_seg - 1].ul_in_use_cnt = 0;
-			mnode_obj = (struct cmm_mnode *)
-			    lst_first(altr->in_use_list_head);
 			/* Count inUse blocks */
-			while (mnode_obj) {
+			list_for_each_entry(curr, &altr->in_use_list, link) {
 				cmm_info_obj->ul_total_in_use_cnt++;
 				cmm_info_obj->seg_info[ul_seg -
 						       1].ul_in_use_cnt++;
-				/* next node. */
-				mnode_obj = (struct cmm_mnode *)
-				    lst_next(altr->in_use_list_head,
-					     (struct list_head *)mnode_obj);
 			}
 		}
 	}			/* end for */
@@ -578,30 +549,17 @@ int cmm_register_gppsm_seg(struct cmm_object *hcmm_mgr,
 		/* return the actual segment identifier */
 		*sgmt_id = (u32) slot_seg + 1;
 		/* create memory free list */
-		psma->free_list_head = kzalloc(sizeof(struct lst_list),
-							GFP_KERNEL);
-		if (psma->free_list_head == NULL) {
-			status = -ENOMEM;
-			goto func_end;
-		}
-		INIT_LIST_HEAD(&psma->free_list_head->head);
+		INIT_LIST_HEAD(&psma->free_list);
 
 		/* create memory in-use list */
-		psma->in_use_list_head = kzalloc(sizeof(struct
-						lst_list), GFP_KERNEL);
-		if (psma->in_use_list_head == NULL) {
-			status = -ENOMEM;
-			goto func_end;
-		}
-		INIT_LIST_HEAD(&psma->in_use_list_head->head);
+		INIT_LIST_HEAD(&psma->in_use_list);
 
 		/* Get a mem node for this hunk-o-memory */
 		new_node = get_node(cmm_mgr_obj, dw_gpp_base_pa,
 				    psma->dw_vm_base, ul_size);
 		/* Place node on the SM allocator's free list */
 		if (new_node) {
-			lst_put_tail(psma->free_list_head,
-				     (struct list_head *)new_node);
+			list_add_tail(&new_node->link, &psma->free_list);
 		} else {
 			status = -ENOMEM;
 			goto func_end;
@@ -680,41 +638,22 @@ int cmm_un_register_gppsm_seg(struct cmm_object *hcmm_mgr,
  */
 static void un_register_gppsm_seg(struct cmm_allocator *psma)
 {
-	struct cmm_mnode *mnode_obj = NULL;
-	struct cmm_mnode *next_node = NULL;
+	struct cmm_mnode *curr, *tmp;
 
 	DBC_REQUIRE(psma != NULL);
-	if (psma->free_list_head != NULL) {
-		/* free nodes on free list */
-		mnode_obj = (struct cmm_mnode *)lst_first(psma->free_list_head);
-		while (mnode_obj) {
-			next_node =
-			    (struct cmm_mnode *)lst_next(psma->free_list_head,
-							 (struct list_head *)
-							 mnode_obj);
-			lst_remove_elem(psma->free_list_head,
-					(struct list_head *)mnode_obj);
-			kfree((void *)mnode_obj);
-			/* next node. */
-			mnode_obj = next_node;
-		}
-		kfree(psma->free_list_head);	/* delete freelist */
-		/* free nodes on InUse list */
-		mnode_obj =
-		    (struct cmm_mnode *)lst_first(psma->in_use_list_head);
-		while (mnode_obj) {
-			next_node =
-			    (struct cmm_mnode *)lst_next(psma->in_use_list_head,
-							 (struct list_head *)
-							 mnode_obj);
-			lst_remove_elem(psma->in_use_list_head,
-					(struct list_head *)mnode_obj);
-			kfree((void *)mnode_obj);
-			/* next node. */
-			mnode_obj = next_node;
-		}
-		kfree(psma->in_use_list_head);	/* delete InUse list */
+
+	/* free nodes on free list */
+	list_for_each_entry_safe(curr, tmp, &psma->free_list, link) {
+		list_del(&curr->link);
+		kfree(curr);
+	}
+
+	/* free nodes on InUse list */
+	list_for_each_entry_safe(curr, tmp, &psma->in_use_list, link) {
+		list_del(&curr->link);
+		kfree(curr);
 	}
+
 	if ((void *)psma->dw_vm_base != NULL)
 		MEM_UNMAP_LINEAR_ADDRESS((void *)psma->dw_vm_base);
 
@@ -758,15 +697,15 @@ static struct cmm_mnode *get_node(struct cmm_object *cmm_mgr_obj, u32 dw_pa,
 	DBC_REQUIRE(dw_va != 0);
 	DBC_REQUIRE(ul_size != 0);
 	/* Check cmm mgr's node freelist */
-	if (LST_IS_EMPTY(cmm_mgr_obj->node_free_list_head)) {
+	if (list_empty(&cmm_mgr_obj->node_free_list)) {
 		pnode = kzalloc(sizeof(struct cmm_mnode), GFP_KERNEL);
 	} else {
 		/* surely a valid element */
-		pnode = (struct cmm_mnode *)
-		    lst_get_head(cmm_mgr_obj->node_free_list_head);
+		pnode = list_first_entry(&cmm_mgr_obj->node_free_list,
+				struct cmm_mnode, link);
+		list_del(&pnode->link);
 	}
 	if (pnode) {
-		lst_init_elem((struct list_head *)pnode);	/* set self */
 		pnode->dw_pa = dw_pa;	/* Physical addr of start of block */
 		pnode->dw_va = dw_va;	/* Virtual   "            " */
 		pnode->ul_size = ul_size;	/* Size of block */
@@ -783,9 +722,7 @@ static struct cmm_mnode *get_node(struct cmm_object *cmm_mgr_obj, u32 dw_pa,
 static void delete_node(struct cmm_object *cmm_mgr_obj, struct cmm_mnode *pnode)
 {
 	DBC_REQUIRE(pnode != NULL);
-	lst_init_elem((struct list_head *)pnode);	/* init .self ptr */
-	lst_put_tail(cmm_mgr_obj->node_free_list_head,
-		     (struct list_head *)pnode);
+	list_add_tail(&pnode->link, &cmm_mgr_obj->node_free_list);
 }
 
 /*
@@ -797,28 +734,26 @@ static void delete_node(struct cmm_object *cmm_mgr_obj, struct cmm_mnode *pnode)
 static struct cmm_mnode *get_free_block(struct cmm_allocator *allocator,
 					u32 usize)
 {
-	if (allocator) {
-		struct cmm_mnode *mnode_obj = (struct cmm_mnode *)
-		    lst_first(allocator->free_list_head);
-		while (mnode_obj) {
-			if (usize <= (u32) mnode_obj->ul_size) {
-				lst_remove_elem(allocator->free_list_head,
-						(struct list_head *)mnode_obj);
-				return mnode_obj;
-			}
-			/* next node. */
-			mnode_obj = (struct cmm_mnode *)
-			    lst_next(allocator->free_list_head,
-				     (struct list_head *)mnode_obj);
+	struct cmm_mnode *node, *tmp;
+
+	if (!allocator)
+		return NULL;
+
+	list_for_each_entry_safe(node, tmp, &allocator->free_list, link) {
+		if (usize <= (u32) node->ul_size) {
+			list_del(&node->link);
+			return node;
 		}
+
 	}
+
 	return NULL;
 }
 
 /*
  *  ======== add_to_free_list ========
  *  Purpose:
- *      Coelesce node into the freelist in ascending size order.
+ *      Coalesce node into the freelist in ascending size order.
  */
 static void add_to_free_list(struct cmm_allocator *allocator,
 			     struct cmm_mnode *pnode)
@@ -833,67 +768,44 @@ static void add_to_free_list(struct cmm_allocator *allocator,
 	DBC_REQUIRE(allocator != NULL);
 	dw_this_pa = pnode->dw_pa;
 	dw_next_pa = NEXT_PA(pnode);
-	mnode_obj = (struct cmm_mnode *)lst_first(allocator->free_list_head);
-	while (mnode_obj) {
+	list_for_each_entry(mnode_obj, &allocator->free_list, link) {
 		if (dw_this_pa == NEXT_PA(mnode_obj)) {
 			/* found the block ahead of this one */
 			node_prev = mnode_obj;
 		} else if (dw_next_pa == mnode_obj->dw_pa) {
 			node_next = mnode_obj;
 		}
-		if ((node_prev == NULL) || (node_next == NULL)) {
-			/* next node. */
-			mnode_obj = (struct cmm_mnode *)
-			    lst_next(allocator->free_list_head,
-				     (struct list_head *)mnode_obj);
-		} else {
-			/* got 'em */
+		if ((node_prev != NULL) && (node_next != NULL))
 			break;
-		}
-	}			/* while */
+	}
 	if (node_prev != NULL) {
 		/* combine with previous block */
-		lst_remove_elem(allocator->free_list_head,
-				(struct list_head *)node_prev);
+		list_del(&node_prev->link);
 		/* grow node to hold both */
 		pnode->ul_size += node_prev->ul_size;
 		pnode->dw_pa = node_prev->dw_pa;
 		pnode->dw_va = node_prev->dw_va;
 		/* place node on mgr nodeFreeList */
-		delete_node((struct cmm_object *)allocator->hcmm_mgr,
-			    node_prev);
+		delete_node(allocator->hcmm_mgr, node_prev);
 	}
 	if (node_next != NULL) {
 		/* combine with next block */
-		lst_remove_elem(allocator->free_list_head,
-				(struct list_head *)node_next);
+		list_del(&node_next->link);
 		/* grow da node */
 		pnode->ul_size += node_next->ul_size;
 		/* place node on mgr nodeFreeList */
-		delete_node((struct cmm_object *)allocator->hcmm_mgr,
-			    node_next);
+		delete_node(allocator->hcmm_mgr, node_next);
 	}
 	/* Now, let's add to freelist in increasing size order */
-	mnode_obj = (struct cmm_mnode *)lst_first(allocator->free_list_head);
-	while (mnode_obj) {
-		if (pnode->ul_size <= mnode_obj->ul_size)
-			break;
-
-		/* next node. */
-		mnode_obj =
-		    (struct cmm_mnode *)lst_next(allocator->free_list_head,
-						 (struct list_head *)mnode_obj);
-	}
-	/* if mnode_obj is NULL then add our pnode to the end of the freelist */
-	if (mnode_obj == NULL) {
-		lst_put_tail(allocator->free_list_head,
-			     (struct list_head *)pnode);
-	} else {
-		/* insert our node before the current traversed node */
-		lst_insert_before(allocator->free_list_head,
-				  (struct list_head *)pnode,
-				  (struct list_head *)mnode_obj);
+	list_for_each_entry(mnode_obj, &allocator->free_list, link) {
+		if (pnode->ul_size <= mnode_obj->ul_size) {
+			/* insert our node before the current traversed node  */
+			list_add_tail(&pnode->link, &mnode_obj->link);
+			return;
+		}
 	}
+	/* add our pnode to the end of the freelist */
+	list_add_tail(&pnode->link, &allocator->free_list);
 }
 
 /*
diff --git a/drivers/staging/tidspbridge/pmgr/dev.c b/drivers/staging/tidspbridge/pmgr/dev.c
index 7b30267..99cef4d 100644
--- a/drivers/staging/tidspbridge/pmgr/dev.c
+++ b/drivers/staging/tidspbridge/pmgr/dev.c
@@ -16,6 +16,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 #include <linux/types.h>
+#include <linux/list.h>
 
 /*  ----------------------------------- Host OS */
 #include <dspbridge/host_os.h>
@@ -28,7 +29,6 @@
 
 /*  ----------------------------------- OS Adaptation Layer */
 #include <dspbridge/ldr.h>
-#include <dspbridge/list.h>
 
 /*  ----------------------------------- Platform Manager */
 #include <dspbridge/cod.h>
@@ -59,7 +59,6 @@
 
 /* The Bridge device object: */
 struct dev_object {
-	/* LST requires "link" to be first field! */
 	struct list_head link;	/* Link to next dev_object. */
 	u8 dev_type;		/* Device Type */
 	struct cfg_devnode *dev_node_obj;	/* Platform specific dev id */
@@ -77,7 +76,7 @@ struct dev_object {
 	struct ldr_module *module_obj;	/* Bridge Module handle. */
 	u32 word_size;		/* DSP word size: quick access. */
 	struct drv_object *hdrv_obj;	/* Driver Object */
-	struct lst_list *proc_list;	/* List of Proceeosr attached to
+	struct list_head proc_list;	/* List of Processor attached to
 					 * this device */
 	struct node_mgr *hnode_mgr;
 };
@@ -250,19 +249,12 @@ int dev_create_device(struct dev_object **device_obj,
 		}
 	}
 	/* Add the new DEV_Object to the global list: */
-	if (!status) {
-		lst_init_elem(&dev_obj->link);
+	if (!status)
 		status = drv_insert_dev_object(hdrv_obj, dev_obj);
-	}
+
 	/* Create the Processor List */
-	if (!status) {
-		dev_obj->proc_list = kzalloc(sizeof(struct lst_list),
-							GFP_KERNEL);
-		if (!(dev_obj->proc_list))
-			status = -EPERM;
-		else
-			INIT_LIST_HEAD(&dev_obj->proc_list->head);
-	}
+	if (!status)
+		INIT_LIST_HEAD(&dev_obj->proc_list);
 leave:
 	/*  If all went well, return a handle to the dev object;
 	 *  else, cleanup and return NULL in the OUT parameter. */
@@ -270,7 +262,6 @@ leave:
 		*device_obj = dev_obj;
 	} else {
 		if (dev_obj) {
-			kfree(dev_obj->proc_list);
 			if (dev_obj->cod_mgr)
 				cod_delete(dev_obj->cod_mgr);
 			kfree(dev_obj);
@@ -391,9 +382,6 @@ int dev_destroy_device(struct dev_object *hdev_obj)
 		} else
 			status = -EPERM;
 		if (!status) {
-			kfree(dev_obj->proc_list);
-			dev_obj->proc_list = NULL;
-
 			/* Remove this DEV_Object from the global list: */
 			drv_remove_dev_object(dev_obj->hdrv_obj, dev_obj);
 			/* Free The library * LDR_FreeModule
@@ -748,18 +736,16 @@ bool dev_init(void)
  */
 int dev_notify_clients(struct dev_object *hdev_obj, u32 ret)
 {
-	int status = 0;
-
 	struct dev_object *dev_obj = hdev_obj;
-	void *proc_obj;
+	struct list_head *curr;
 
-	for (proc_obj = (void *)lst_first(dev_obj->proc_list);
-	     proc_obj != NULL;
-	     proc_obj = (void *)lst_next(dev_obj->proc_list,
-					 (struct list_head *)proc_obj))
-		proc_notify_clients(proc_obj, (u32) ret);
+	/* FIXME: this code needs struct proc_object to have a list_head
+	 * at the begining. If not, this can go horribly wrong.
+	 */
+	list_for_each(curr, &dev_obj->proc_list)
+		proc_notify_clients((void *)curr, (u32) ret);
 
-	return status;
+	return 0;
 }
 
 /*
@@ -947,15 +933,17 @@ int dev_insert_proc_object(struct dev_object *hdev_obj,
 	DBC_REQUIRE(refs > 0);
 	DBC_REQUIRE(dev_obj);
 	DBC_REQUIRE(proc_obj != 0);
-	DBC_REQUIRE(dev_obj->proc_list != NULL);
 	DBC_REQUIRE(already_attached != NULL);
-	if (!LST_IS_EMPTY(dev_obj->proc_list))
+	if (!list_empty(&dev_obj->proc_list))
 		*already_attached = true;
 
 	/* Add DevObject to tail. */
-	lst_put_tail(dev_obj->proc_list, (struct list_head *)proc_obj);
+	/* FIXME: this code needs struct proc_object to have a list_head
+	 * at the begining. If not, this can go horribly wrong.
+	 */
+	list_add_tail((struct list_head *)proc_obj, &dev_obj->proc_list);
 
-	DBC_ENSURE(!status && !LST_IS_EMPTY(dev_obj->proc_list));
+	DBC_ENSURE(!status && !list_empty(&dev_obj->proc_list));
 
 	return status;
 }
@@ -986,15 +974,12 @@ int dev_remove_proc_object(struct dev_object *hdev_obj, u32 proc_obj)
 
 	DBC_REQUIRE(dev_obj);
 	DBC_REQUIRE(proc_obj != 0);
-	DBC_REQUIRE(dev_obj->proc_list != NULL);
-	DBC_REQUIRE(!LST_IS_EMPTY(dev_obj->proc_list));
+	DBC_REQUIRE(!list_empty(&dev_obj->proc_list));
 
 	/* Search list for dev_obj: */
-	for (cur_elem = lst_first(dev_obj->proc_list); cur_elem != NULL;
-	     cur_elem = lst_next(dev_obj->proc_list, cur_elem)) {
-		/* If found, remove it. */
+	list_for_each(cur_elem, &dev_obj->proc_list) {
 		if ((u32) cur_elem == proc_obj) {
-			lst_remove_elem(dev_obj->proc_list, cur_elem);
+			list_del(cur_elem);
 			status = 0;
 			break;
 		}
-- 
1.7.2.3


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

* [PATCH v2 08/12] staging: tidspbridge: convert rmgr to list_head
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
                   ` (6 preceding siblings ...)
  2010-11-05 15:13 ` [PATCH v2 07/12] staging: tidspbridge: convert pmgr " Ionut Nicu
@ 2010-11-05 15:13 ` Ionut Nicu
  2010-11-06  0:07   ` Sapiens, Rene
  2010-11-05 15:13 ` [PATCH v2 09/12] staging: tidspbridge: remove custom linked list Ionut Nicu
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

Convert the rmgr module of the tidspbridge driver
to use struct list_head instead of struct lst_list.

Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
---
 drivers/staging/tidspbridge/rmgr/drv.c  |  111 +++++++++----------------------
 drivers/staging/tidspbridge/rmgr/node.c |   52 +++++----------
 drivers/staging/tidspbridge/rmgr/proc.c |    2 -
 drivers/staging/tidspbridge/rmgr/rmm.c  |   74 +++++++--------------
 4 files changed, 72 insertions(+), 167 deletions(-)

diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c
index 91cc1685..18fae55 100644
--- a/drivers/staging/tidspbridge/rmgr/drv.c
+++ b/drivers/staging/tidspbridge/rmgr/drv.c
@@ -16,6 +16,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 #include <linux/types.h>
+#include <linux/list.h>
 
 /*  ----------------------------------- Host OS */
 #include <dspbridge/host_os.h>
@@ -26,9 +27,6 @@
 /*  ----------------------------------- Trace & Debug */
 #include <dspbridge/dbc.h>
 
-/*  ----------------------------------- OS Adaptation Layer */
-#include <dspbridge/list.h>
-
 /*  ----------------------------------- This */
 #include <dspbridge/drv.h>
 #include <dspbridge/dev.h>
@@ -42,8 +40,8 @@
 
 /*  ----------------------------------- Defines, Data Structures, Typedefs */
 struct drv_object {
-	struct lst_list *dev_list;
-	struct lst_list *dev_node_string;
+	struct list_head dev_list;
+	struct list_head dev_node_string;
 };
 
 /*
@@ -305,22 +303,8 @@ int drv_create(struct drv_object **drv_obj)
 	pdrv_object = kzalloc(sizeof(struct drv_object), GFP_KERNEL);
 	if (pdrv_object) {
 		/* Create and Initialize List of device objects */
-		pdrv_object->dev_list = kzalloc(sizeof(struct lst_list),
-							GFP_KERNEL);
-		if (pdrv_object->dev_list) {
-			/* Create and Initialize List of device Extension */
-			pdrv_object->dev_node_string =
-				kzalloc(sizeof(struct lst_list), GFP_KERNEL);
-			if (!(pdrv_object->dev_node_string)) {
-				status = -EPERM;
-			} else {
-				INIT_LIST_HEAD(&pdrv_object->
-					       dev_node_string->head);
-				INIT_LIST_HEAD(&pdrv_object->dev_list->head);
-			}
-		} else {
-			status = -ENOMEM;
-		}
+		INIT_LIST_HEAD(&pdrv_object->dev_list);
+		INIT_LIST_HEAD(&pdrv_object->dev_node_string);
 	} else {
 		status = -ENOMEM;
 	}
@@ -337,8 +321,6 @@ int drv_create(struct drv_object **drv_obj)
 	if (!status) {
 		*drv_obj = pdrv_object;
 	} else {
-		kfree(pdrv_object->dev_list);
-		kfree(pdrv_object->dev_node_string);
 		/* Free the DRV Object */
 		kfree(pdrv_object);
 	}
@@ -375,13 +357,6 @@ int drv_destroy(struct drv_object *driver_obj)
 	DBC_REQUIRE(refs > 0);
 	DBC_REQUIRE(pdrv_object);
 
-	/*
-	 *  Delete the List if it exists.Should not come here
-	 *  as the drv_remove_dev_object and the Last drv_request_resources
-	 *  removes the list if the lists are empty.
-	 */
-	kfree(pdrv_object->dev_list);
-	kfree(pdrv_object->dev_node_string);
 	kfree(pdrv_object);
 	/* Update the DRV Object in the driver data */
 	if (drv_datap) {
@@ -413,7 +388,7 @@ int drv_get_dev_object(u32 index, struct drv_object *hdrv_obj,
 	DBC_REQUIRE(device_obj != NULL);
 	DBC_REQUIRE(index >= 0);
 	DBC_REQUIRE(refs > 0);
-	DBC_ASSERT(!(LST_IS_EMPTY(pdrv_obj->dev_list)));
+	DBC_ASSERT(!(list_empty(&pdrv_obj->dev_list)));
 
 	dev_obj = (struct dev_object *)drv_get_first_dev_object();
 	for (i = 0; i < index; i++) {
@@ -444,9 +419,8 @@ u32 drv_get_first_dev_object(void)
 
 	if (drv_datap && drv_datap->drv_object) {
 		pdrv_obj = drv_datap->drv_object;
-		if ((pdrv_obj->dev_list != NULL) &&
-		    !LST_IS_EMPTY(pdrv_obj->dev_list))
-			dw_dev_object = (u32) lst_first(pdrv_obj->dev_list);
+		if (!list_empty(&pdrv_obj->dev_list))
+			dw_dev_object = (u32) pdrv_obj->dev_list.next;
 	} else {
 		pr_err("%s: Failed to retrieve the object handle\n", __func__);
 	}
@@ -468,10 +442,9 @@ u32 drv_get_first_dev_extension(void)
 
 	if (drv_datap && drv_datap->drv_object) {
 		pdrv_obj = drv_datap->drv_object;
-		if ((pdrv_obj->dev_node_string != NULL) &&
-		    !LST_IS_EMPTY(pdrv_obj->dev_node_string)) {
+		if (!list_empty(&pdrv_obj->dev_node_string)) {
 			dw_dev_extension =
-			    (u32) lst_first(pdrv_obj->dev_node_string);
+			    (u32) pdrv_obj->dev_node_string.next;
 		}
 	} else {
 		pr_err("%s: Failed to retrieve the object handle\n", __func__);
@@ -492,16 +465,17 @@ u32 drv_get_next_dev_object(u32 hdev_obj)
 	u32 dw_next_dev_object = 0;
 	struct drv_object *pdrv_obj;
 	struct drv_data *drv_datap = dev_get_drvdata(bridge);
+	struct list_head *curr;
 
 	DBC_REQUIRE(hdev_obj != 0);
 
 	if (drv_datap && drv_datap->drv_object) {
 		pdrv_obj = drv_datap->drv_object;
-		if ((pdrv_obj->dev_list != NULL) &&
-		    !LST_IS_EMPTY(pdrv_obj->dev_list)) {
-			dw_next_dev_object = (u32) lst_next(pdrv_obj->dev_list,
-							    (struct list_head *)
-							    hdev_obj);
+		if (!list_empty(&pdrv_obj->dev_list)) {
+			curr = (struct list_head *)hdev_obj;
+			if (curr->next == &pdrv_obj->dev_list)
+				return 0;
+			dw_next_dev_object = (u32) curr->next;
 		}
 	} else {
 		pr_err("%s: Failed to retrieve the object handle\n", __func__);
@@ -523,16 +497,17 @@ u32 drv_get_next_dev_extension(u32 dev_extension)
 	u32 dw_dev_extension = 0;
 	struct drv_object *pdrv_obj;
 	struct drv_data *drv_datap = dev_get_drvdata(bridge);
+	struct list_head *curr;
 
 	DBC_REQUIRE(dev_extension != 0);
 
 	if (drv_datap && drv_datap->drv_object) {
 		pdrv_obj = drv_datap->drv_object;
-		if ((pdrv_obj->dev_node_string != NULL) &&
-		    !LST_IS_EMPTY(pdrv_obj->dev_node_string)) {
-			dw_dev_extension =
-			    (u32) lst_next(pdrv_obj->dev_node_string,
-					   (struct list_head *)dev_extension);
+		if (!list_empty(&pdrv_obj->dev_node_string)) {
+			curr = (struct list_head *)dev_extension;
+			if (curr->next == &pdrv_obj->dev_node_string)
+				return 0;
+			dw_dev_extension = (u32) curr->next;
 		}
 	} else {
 		pr_err("%s: Failed to retrieve the object handle\n", __func__);
@@ -573,11 +548,8 @@ int drv_insert_dev_object(struct drv_object *driver_obj,
 	DBC_REQUIRE(refs > 0);
 	DBC_REQUIRE(hdev_obj != NULL);
 	DBC_REQUIRE(pdrv_object);
-	DBC_ASSERT(pdrv_object->dev_list);
-
-	lst_put_tail(pdrv_object->dev_list, (struct list_head *)hdev_obj);
 
-	DBC_ENSURE(!LST_IS_EMPTY(pdrv_object->dev_list));
+	list_add_tail((struct list_head *)hdev_obj, &pdrv_object->dev_list);
 
 	return 0;
 }
@@ -599,26 +571,17 @@ int drv_remove_dev_object(struct drv_object *driver_obj,
 	DBC_REQUIRE(pdrv_object);
 	DBC_REQUIRE(hdev_obj != NULL);
 
-	DBC_REQUIRE(pdrv_object->dev_list != NULL);
-	DBC_REQUIRE(!LST_IS_EMPTY(pdrv_object->dev_list));
+	DBC_REQUIRE(!list_empty(&pdrv_object->dev_list));
 
 	/* Search list for p_proc_object: */
-	for (cur_elem = lst_first(pdrv_object->dev_list); cur_elem != NULL;
-	     cur_elem = lst_next(pdrv_object->dev_list, cur_elem)) {
+	list_for_each(cur_elem, &pdrv_object->dev_list) {
 		/* If found, remove it. */
 		if ((struct dev_object *)cur_elem == hdev_obj) {
-			lst_remove_elem(pdrv_object->dev_list, cur_elem);
+			list_del(cur_elem);
 			status = 0;
 			break;
 		}
 	}
-	/* Remove list if empty. */
-	if (LST_IS_EMPTY(pdrv_object->dev_list)) {
-		kfree(pdrv_object->dev_list);
-		pdrv_object->dev_list = NULL;
-	}
-	DBC_ENSURE((pdrv_object->dev_list == NULL) ||
-		   !LST_IS_EMPTY(pdrv_object->dev_list));
 
 	return status;
 }
@@ -652,14 +615,13 @@ int drv_request_resources(u32 dw_context, u32 *dev_node_strg)
 	if (!status) {
 		pszdev_node = kzalloc(sizeof(struct drv_ext), GFP_KERNEL);
 		if (pszdev_node) {
-			lst_init_elem(&pszdev_node->link);
 			strncpy(pszdev_node->sz_string,
 				(char *)dw_context, MAXREGPATHLENGTH - 1);
 			pszdev_node->sz_string[MAXREGPATHLENGTH - 1] = '\0';
 			/* Update the Driver Object List */
 			*dev_node_strg = (u32) pszdev_node->sz_string;
-			lst_put_tail(pdrv_object->dev_node_string,
-				     (struct list_head *)pszdev_node);
+			list_add_tail(&pszdev_node->link,
+					&pdrv_object->dev_node_string);
 		} else {
 			status = -ENOMEM;
 			*dev_node_strg = 0;
@@ -671,7 +633,7 @@ int drv_request_resources(u32 dw_context, u32 *dev_node_strg)
 	}
 
 	DBC_ENSURE((!status && dev_node_strg != NULL &&
-		    !LST_IS_EMPTY(pdrv_object->dev_node_string)) ||
+		    !list_empty(&pdrv_object->dev_node_string)) ||
 		   (status && *dev_node_strg == 0));
 
 	return status;
@@ -685,7 +647,6 @@ int drv_request_resources(u32 dw_context, u32 *dev_node_strg)
 int drv_release_resources(u32 dw_context, struct drv_object *hdrv_obj)
 {
 	int status = 0;
-	struct drv_object *pdrv_object = (struct drv_object *)hdrv_obj;
 	struct drv_ext *pszdev_node;
 
 	/*
@@ -695,23 +656,13 @@ int drv_release_resources(u32 dw_context, struct drv_object *hdrv_obj)
 	for (pszdev_node = (struct drv_ext *)drv_get_first_dev_extension();
 	     pszdev_node != NULL; pszdev_node = (struct drv_ext *)
 	     drv_get_next_dev_extension((u32) pszdev_node)) {
-		if (!pdrv_object->dev_node_string) {
-			/* When this could happen? */
-			continue;
-		}
 		if ((u32) pszdev_node == dw_context) {
 			/* Found it */
 			/* Delete from the Driver object list */
-			lst_remove_elem(pdrv_object->dev_node_string,
-					(struct list_head *)pszdev_node);
-			kfree((void *)pszdev_node);
+			list_del(&pszdev_node->link);
+			kfree(pszdev_node);
 			break;
 		}
-		/* Delete the List if it is empty */
-		if (LST_IS_EMPTY(pdrv_object->dev_node_string)) {
-			kfree(pdrv_object->dev_node_string);
-			pdrv_object->dev_node_string = NULL;
-		}
 	}
 	return status;
 }
diff --git a/drivers/staging/tidspbridge/rmgr/node.c b/drivers/staging/tidspbridge/rmgr/node.c
index f660d1f..34ae0ad 100644
--- a/drivers/staging/tidspbridge/rmgr/node.c
+++ b/drivers/staging/tidspbridge/rmgr/node.c
@@ -18,6 +18,8 @@
 
 #include <linux/types.h>
 #include <linux/bitmap.h>
+#include <linux/list.h>
+
 /*  ----------------------------------- Host OS */
 #include <dspbridge/host_os.h>
 
@@ -28,7 +30,6 @@
 #include <dspbridge/dbc.h>
 
 /*  ----------------------------------- OS Adaptation Layer */
-#include <dspbridge/list.h>
 #include <dspbridge/memdefs.h>
 #include <dspbridge/proc.h>
 #include <dspbridge/strm.h>
@@ -128,7 +129,7 @@ struct node_mgr {
 	struct bridge_drv_interface *intf_fxns;
 	struct dcd_manager *hdcd_mgr;	/* Proc/Node data manager */
 	struct disp_object *disp_obj;	/* Node dispatcher */
-	struct lst_list *node_list;	/* List of all allocated nodes */
+	struct list_head node_list;	/* List of all allocated nodes */
 	u32 num_nodes;		/* Number of nodes in node_list */
 	u32 num_created;	/* Number of nodes *created* on DSP */
 	DECLARE_BITMAP(pipe_map, MAXPIPES); /* Pipe connection bitmap */
@@ -612,13 +613,12 @@ func_cont:
 	if (!status) {
 		/* Add the node to the node manager's list of allocated
 		 * nodes. */
-		lst_init_elem((struct list_head *)pnode);
 		NODE_SET_STATE(pnode, NODE_ALLOCATED);
 
 		mutex_lock(&hnode_mgr->node_mgr_lock);
 
-		lst_put_tail(hnode_mgr->node_list, (struct list_head *) pnode);
-			++(hnode_mgr->num_nodes);
+		list_add_tail(&pnode->list_elem, &hnode_mgr->node_list);
+		++(hnode_mgr->num_nodes);
 
 		/* Exit critical section */
 		mutex_unlock(&hnode_mgr->node_mgr_lock);
@@ -1274,11 +1274,6 @@ int node_create_mgr(struct node_mgr **node_man,
 		return -ENOMEM;
 
 	node_mgr_obj->hdev_obj = hdev_obj;
-	node_mgr_obj->node_list = kzalloc(sizeof(struct lst_list), GFP_KERNEL);
-	if (!node_mgr_obj->node_list) {
-		status = -ENOMEM;
-		goto out_err;
-	}
 
 	node_mgr_obj->ntfy_obj = kmalloc(sizeof(struct ntfy_object),
 			GFP_KERNEL);
@@ -1288,7 +1283,7 @@ int node_create_mgr(struct node_mgr **node_man,
 	}
 	ntfy_init(node_mgr_obj->ntfy_obj);
 
-	INIT_LIST_HEAD(&node_mgr_obj->node_list->head);
+	INIT_LIST_HEAD(&node_mgr_obj->node_list);
 
 	dev_get_dev_type(hdev_obj, &dev_type);
 
@@ -1500,7 +1495,7 @@ func_cont1:
 	}
 	/* Free host side resources even if a failure occurred */
 	/* Remove node from hnode_mgr->node_list */
-	lst_remove_elem(hnode_mgr->node_list, (struct list_head *)pnode);
+	list_del(&pnode->list_elem);
 	hnode_mgr->num_nodes--;
 	/* Decrement count of nodes created on DSP */
 	if ((state != NODE_ALLOCATED) || ((state == NODE_ALLOCATED) &&
@@ -1571,15 +1566,9 @@ int node_enum_nodes(struct node_mgr *hnode_mgr, void **node_tab,
 		*pu_num_nodes = 0;
 		status = -EINVAL;
 	} else {
-		hnode = (struct node_object *)lst_first(hnode_mgr->
-			node_list);
-		for (i = 0; i < hnode_mgr->num_nodes; i++) {
-			DBC_ASSERT(hnode);
-			node_tab[i] = hnode;
-			hnode = (struct node_object *)lst_next
-				(hnode_mgr->node_list,
-				(struct list_head *)hnode);
-		}
+		i = 0;
+		list_for_each_entry(hnode, &hnode_mgr->node_list, list_elem)
+			node_tab[i++] = hnode;
 		*pu_allocated = *pu_num_nodes = hnode_mgr->num_nodes;
 	}
 	/* end of sync_enter_cs */
@@ -2549,7 +2538,7 @@ func_end:
  */
 static void delete_node_mgr(struct node_mgr *hnode_mgr)
 {
-	struct node_object *hnode;
+	struct node_object *hnode, *tmp;
 
 	if (hnode_mgr) {
 		/* Free resources */
@@ -2557,13 +2546,10 @@ static void delete_node_mgr(struct node_mgr *hnode_mgr)
 			dcd_destroy_manager(hnode_mgr->hdcd_mgr);
 
 		/* Remove any elements remaining in lists */
-		if (hnode_mgr->node_list) {
-			while ((hnode = (struct node_object *)
-				lst_get_head(hnode_mgr->node_list)))
-				delete_node(hnode, NULL);
-
-			DBC_ASSERT(LST_IS_EMPTY(hnode_mgr->node_list));
-			kfree(hnode_mgr->node_list);
+		list_for_each_entry_safe(hnode, tmp, &hnode_mgr->node_list,
+				list_elem) {
+			list_del(&hnode->list_elem);
+			delete_node(hnode, NULL);
 		}
 		mutex_destroy(&hnode_mgr->node_mgr_lock);
 		if (hnode_mgr->ntfy_obj) {
@@ -3103,23 +3089,17 @@ int node_find_addr(struct node_mgr *node_mgr, u32 sym_addr,
 {
 	struct node_object *node_obj;
 	int status = -ENOENT;
-	u32 n;
 
 	pr_debug("%s(0x%x, 0x%x, 0x%x, 0x%x,  %s)\n", __func__,
 			(unsigned int) node_mgr,
 			sym_addr, offset_range,
 			(unsigned int) sym_addr_output, sym_name);
 
-	node_obj = (struct node_object *)(node_mgr->node_list->head.next);
-
-	for (n = 0; n < node_mgr->num_nodes; n++) {
+	list_for_each_entry(node_obj, &node_mgr->node_list, list_elem) {
 		status = nldr_find_addr(node_obj->nldr_node_obj, sym_addr,
 			offset_range, sym_addr_output, sym_name);
-
 		if (!status)
 			break;
-
-		node_obj = (struct node_object *) (node_obj->list_elem.next);
 	}
 
 	return status;
diff --git a/drivers/staging/tidspbridge/rmgr/proc.c b/drivers/staging/tidspbridge/rmgr/proc.c
index 7a15a02..a091a2d 100644
--- a/drivers/staging/tidspbridge/rmgr/proc.c
+++ b/drivers/staging/tidspbridge/rmgr/proc.c
@@ -29,7 +29,6 @@
 #include <dspbridge/dbc.h>
 
 /*  ----------------------------------- OS Adaptation Layer */
-#include <dspbridge/list.h>
 #include <dspbridge/ntfy.h>
 #include <dspbridge/sync.h>
 /*  ----------------------------------- Bridge Driver */
@@ -344,7 +343,6 @@ proc_attach(u32 processor_id,
 		 * Return handle to this Processor Object:
 		 * Find out if the Device is already attached to a
 		 * Processor. If so, return AlreadyAttached status */
-		lst_init_elem(&p_proc_object->link);
 		status = dev_insert_proc_object(p_proc_object->hdev_obj,
 						(u32) p_proc_object,
 						&p_proc_object->
diff --git a/drivers/staging/tidspbridge/rmgr/rmm.c b/drivers/staging/tidspbridge/rmgr/rmm.c
index 761e8f4..93db337 100644
--- a/drivers/staging/tidspbridge/rmgr/rmm.c
+++ b/drivers/staging/tidspbridge/rmgr/rmm.c
@@ -38,6 +38,10 @@
  */
 
 #include <linux/types.h>
+#include <linux/list.h>
+
+/*  ----------------------------------- Host OS */
+#include <dspbridge/host_os.h>
 
 /*  ----------------------------------- DSP/BIOS Bridge */
 #include <dspbridge/dbdefs.h>
@@ -45,9 +49,6 @@
 /*  ----------------------------------- Trace & Debug */
 #include <dspbridge/dbc.h>
 
-/*  ----------------------------------- OS Adaptation Layer */
-#include <dspbridge/list.h>
-
 /*  ----------------------------------- This */
 #include <dspbridge/rmm.h>
 
@@ -79,7 +80,7 @@ struct rmm_target_obj {
 	struct rmm_segment *seg_tab;
 	struct rmm_header **free_list;
 	u32 num_segs;
-	struct lst_list *ovly_list;	/* List of overlay memory in use */
+	struct list_head ovly_list;	/* List of overlay memory in use */
 };
 
 static u32 refs;		/* module reference count */
@@ -95,8 +96,7 @@ static bool free_block(struct rmm_target_obj *target, u32 segid, u32 addr,
 int rmm_alloc(struct rmm_target_obj *target, u32 segid, u32 size,
 		     u32 align, u32 *dsp_address, bool reserve)
 {
-	struct rmm_ovly_sect *sect;
-	struct rmm_ovly_sect *prev_sect = NULL;
+	struct rmm_ovly_sect *sect, *prev_sect = NULL;
 	struct rmm_ovly_sect *new_sect;
 	u32 addr;
 	int status = 0;
@@ -120,10 +120,9 @@ int rmm_alloc(struct rmm_target_obj *target, u32 segid, u32 size,
 	/* An overlay section - See if block is already in use. If not,
 	 * insert into the list in ascending address size. */
 	addr = *dsp_address;
-	sect = (struct rmm_ovly_sect *)lst_first(target->ovly_list);
 	/*  Find place to insert new list element. List is sorted from
 	 *  smallest to largest address. */
-	while (sect != NULL) {
+	list_for_each_entry(sect, &target->ovly_list, list_elem) {
 		if (addr <= sect->addr) {
 			/* Check for overlap with sect */
 			if ((addr + size > sect->addr) || (prev_sect &&
@@ -135,9 +134,6 @@ int rmm_alloc(struct rmm_target_obj *target, u32 segid, u32 size,
 			break;
 		}
 		prev_sect = sect;
-		sect = (struct rmm_ovly_sect *)lst_next(target->ovly_list,
-							(struct list_head *)
-							sect);
 	}
 	if (!status) {
 		/* No overlap - allocate list element for new section. */
@@ -145,20 +141,17 @@ int rmm_alloc(struct rmm_target_obj *target, u32 segid, u32 size,
 		if (new_sect == NULL) {
 			status = -ENOMEM;
 		} else {
-			lst_init_elem((struct list_head *)new_sect);
 			new_sect->addr = addr;
 			new_sect->size = size;
 			new_sect->page = segid;
-			if (sect == NULL) {
+			if (sect == NULL)
 				/* Put new section at the end of the list */
-				lst_put_tail(target->ovly_list,
-					     (struct list_head *)new_sect);
-			} else {
+				list_add_tail(&new_sect->list_elem,
+						&target->ovly_list);
+			else
 				/* Put new section just before sect */
-				lst_insert_before(target->ovly_list,
-						  (struct list_head *)new_sect,
-						  (struct list_head *)sect);
-			}
+				list_add_tail(&new_sect->list_elem,
+						&sect->list_elem);
 		}
 	}
 func_end:
@@ -230,14 +223,8 @@ int rmm_create(struct rmm_target_obj **target_obj,
 	}
 func_cont:
 	/* Initialize overlay memory list */
-	if (!status) {
-		target->ovly_list = kzalloc(sizeof(struct lst_list),
-							GFP_KERNEL);
-		if (target->ovly_list == NULL)
-			status = -ENOMEM;
-		else
-			INIT_LIST_HEAD(&target->ovly_list->head);
-	}
+	if (!status)
+		INIT_LIST_HEAD(&target->ovly_list);
 
 	if (!status) {
 		*target_obj = target;
@@ -259,7 +246,7 @@ func_cont:
  */
 void rmm_delete(struct rmm_target_obj *target)
 {
-	struct rmm_ovly_sect *ovly_section;
+	struct rmm_ovly_sect *sect, *tmp;
 	struct rmm_header *hptr;
 	struct rmm_header *next;
 	u32 i;
@@ -268,13 +255,9 @@ void rmm_delete(struct rmm_target_obj *target)
 
 	kfree(target->seg_tab);
 
-	if (target->ovly_list) {
-		while ((ovly_section = (struct rmm_ovly_sect *)lst_get_head
-			(target->ovly_list))) {
-			kfree(ovly_section);
-		}
-		DBC_ASSERT(LST_IS_EMPTY(target->ovly_list));
-		kfree(target->ovly_list);
+	list_for_each_entry_safe(sect, tmp, &target->ovly_list, list_elem) {
+		list_del(&sect->list_elem);
+		kfree(sect);
 	}
 
 	if (target->free_list != NULL) {
@@ -311,8 +294,8 @@ void rmm_exit(void)
 bool rmm_free(struct rmm_target_obj *target, u32 segid, u32 dsp_addr, u32 size,
 	      bool reserved)
 {
-	struct rmm_ovly_sect *sect;
-	bool ret = true;
+	struct rmm_ovly_sect *sect, *tmp;
+	bool ret = false;
 
 	DBC_REQUIRE(target);
 
@@ -333,24 +316,17 @@ bool rmm_free(struct rmm_target_obj *target, u32 segid, u32 dsp_addr, u32 size,
 
 	} else {
 		/* Unreserve memory */
-		sect = (struct rmm_ovly_sect *)lst_first(target->ovly_list);
-		while (sect != NULL) {
+		list_for_each_entry_safe(sect, tmp, &target->ovly_list,
+				list_elem) {
 			if (dsp_addr == sect->addr) {
 				DBC_ASSERT(size == sect->size);
 				/* Remove from list */
-				lst_remove_elem(target->ovly_list,
-						(struct list_head *)sect);
+				list_del(&sect->list_elem);
 				kfree(sect);
+				ret = true;
 				break;
 			}
-			sect =
-			    (struct rmm_ovly_sect *)lst_next(target->ovly_list,
-							     (struct list_head
-							      *)sect);
 		}
-		if (sect == NULL)
-			ret = false;
-
 	}
 	return ret;
 }
-- 
1.7.2.3


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

* [PATCH v2 09/12] staging: tidspbridge: remove custom linked list
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
                   ` (7 preceding siblings ...)
  2010-11-05 15:13 ` [PATCH v2 08/12] staging: tidspbridge: convert rmgr " Ionut Nicu
@ 2010-11-05 15:13 ` Ionut Nicu
  2010-11-05 15:13 ` [PATCH v2 10/12] staging: tidspbridge: core code cleanup Ionut Nicu
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

Now that all users of lst_list have been converted to the
standard linux list_head API, we can remove the associated
header file.

Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
---
 drivers/staging/tidspbridge/TODO                   |    1 -
 .../staging/tidspbridge/include/dspbridge/list.h   |  225 --------------------
 2 files changed, 0 insertions(+), 226 deletions(-)
 delete mode 100644 drivers/staging/tidspbridge/include/dspbridge/list.h

diff --git a/drivers/staging/tidspbridge/TODO b/drivers/staging/tidspbridge/TODO
index 187363f..1c51e2d 100644
--- a/drivers/staging/tidspbridge/TODO
+++ b/drivers/staging/tidspbridge/TODO
@@ -6,7 +6,6 @@
 * Eliminate general services and libraries - use or extend existing kernel
   libraries instead (e.g. gcf/lcm in nldr.c, global helpers in gen/)
 * Eliminate direct manipulation of OMAP_SYSC_BASE
-* Eliminate list.h : seem like a redundant wrapper to existing kernel lists
 * Eliminate DSP_SUCCEEDED macros and their imposed redundant indentations
   (adopt the kernel way of checking for return values)
 * Audit interfaces exposed to user space
diff --git a/drivers/staging/tidspbridge/include/dspbridge/list.h b/drivers/staging/tidspbridge/include/dspbridge/list.h
deleted file mode 100644
index 6837b61..0000000
--- a/drivers/staging/tidspbridge/include/dspbridge/list.h
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * list.h
- *
- * DSP-BIOS Bridge driver support functions for TI OMAP processors.
- *
- * Declarations of list management control structures and definitions
- * of inline list management functions.
- *
- * Copyright (C) 2008 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.
- */
-
-#ifndef LIST_
-#define LIST_
-
-#include <dspbridge/host_os.h>
-#include <linux/list.h>
-
-#define LST_IS_EMPTY(l)      list_empty(&(l)->head)
-
-struct lst_list {
-	struct list_head head;
-};
-
-/*
- *  ======== lst_first ========
- *  Purpose:
- *      Returns a pointer to the first element of the list, or NULL if the list
- *      is empty.
- *  Parameters:
- *      lst:  Pointer to list control structure.
- *  Returns:
- *      Pointer to first list element, or NULL.
- *  Requires:
- *      - LST initialized.
- *      - lst != NULL.
- *  Ensures:
- */
-static inline struct list_head *lst_first(struct lst_list *lst)
-{
-	if (lst && !list_empty(&lst->head))
-		return lst->head.next;
-	return NULL;
-}
-
-/*
- *  ======== lst_get_head ========
- *  Purpose:
- *      Pops the head off the list and returns a pointer to it.
- *  Details:
- *      If the list is empty, returns NULL.
- *      Else, removes the element at the head of the list, making the next
- *      element the head of the list.
- *      The head is removed by making the tail element of the list point its
- *      "next" pointer at the next element after the head, and by making the
- *      "prev" pointer of the next element after the head point at the tail
- *      element.  So the next element after the head becomes the new head of
- *      the list.
- *  Parameters:
- *      lst:    Pointer to list control structure of list whose head
- *              element is to be removed
- *  Returns:
- *      Pointer to element that was at the head of the list (success)
- *      NULL          No elements in list
- *  Requires:
- *      - LST initialized.
- *      - lst != NULL.
- *  Ensures:
- *  Notes:
- *      Because the tail of the list points forward (its "next" pointer) to
- *      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.
- */
-static inline struct list_head *lst_get_head(struct lst_list *lst)
-{
-	struct list_head *elem_list;
-
-	if (!lst || list_empty(&lst->head))
-		return NULL;
-
-	elem_list = lst->head.next;
-	lst->head.next = elem_list->next;
-	elem_list->next->prev = &lst->head;
-
-	return elem_list;
-}
-
-/*
- *  ======== lst_init_elem ========
- *  Purpose:
- *      Initializes a list element to default (cleared) values
- *  Details:
- *  Parameters:
- *      elem_list:  Pointer to list element to be reset
- *  Returns:
- *  Requires:
- *      LST initialized.
- *  Ensures:
- *  Notes:
- *      This function must not be called to "reset" an element in the middle
- *      of a list chain -- that would break the chain.
- *
- */
-static inline void lst_init_elem(struct list_head *elem_list)
-{
-	if (elem_list) {
-		elem_list->next = NULL;
-		elem_list->prev = NULL;
-	}
-}
-
-/*
- *  ======== lst_insert_before ========
- *  Purpose:
- *     Insert the element before the existing element.
- *  Parameters:
- *      lst:            Pointer to list control structure.
- *      elem_list:          Pointer to element in list to insert.
- *      elem_existing:  Pointer to existing list element.
- *  Returns:
- *  Requires:
- *      - LST initialized.
- *      - lst != NULL.
- *      - elem_list != NULL.
- *      - elem_existing != NULL.
- *  Ensures:
- */
-static inline void lst_insert_before(struct lst_list *lst,
-				     struct list_head *elem_list,
-				     struct list_head *elem_existing)
-{
-	if (lst && elem_list && elem_existing)
-		list_add_tail(elem_list, elem_existing);
-}
-
-/*
- *  ======== 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.
- *  Parameters:
- *      lst:        Pointer to list control structure.
- *      cur_elem:   Pointer to element in list to remove.
- *  Returns:
- *      Pointer to list element, or NULL.
- *  Requires:
- *      - LST initialized.
- *      - lst != NULL.
- *      - cur_elem != NULL.
- *  Ensures:
- */
-static inline struct list_head *lst_next(struct lst_list *lst,
-					 struct list_head *cur_elem)
-{
-	if (lst && !list_empty(&lst->head) && cur_elem &&
-	    (cur_elem->next != &lst->head))
-		return cur_elem->next;
-	return NULL;
-}
-
-/*
- *  ======== lst_put_tail ========
- *  Purpose:
- *      Adds the specified element to the tail of the list
- *  Details:
- *      Sets new element's "prev" pointer to the address previously held by
- *      the head element's prev pointer.  This is the previous tail member of
- *      the list.
- *      Sets the new head's prev pointer to the address of the element.
- *      Sets next pointer of the previous tail member of the list to point to
- *      the new element (rather than the head, which it had been pointing at).
- *      Sets new element's next pointer to the address of the head element.
- *      Sets head's prev pointer to the address of the new element.
- *  Parameters:
- *      lst:    Pointer to list control structure to which *elem_list will be
- *              added
- *      elem_list:  Pointer to list element to be added
- *  Returns:
- *      Void
- *  Requires:
- *      *elem_list and *lst must both exist.
- *      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.
- */
-static inline void lst_put_tail(struct lst_list *lst,
-				struct list_head *elem_list)
-{
-	if (lst && elem_list)
-		list_add_tail(elem_list, &lst->head);
-}
-
-/*
- *  ======== lst_remove_elem ========
- *  Purpose:
- *      Removes (unlinks) the given element from the list, if the list is not
- *      empty.  Does not free the list element.
- *  Parameters:
- *      lst:        Pointer to list control structure.
- *      cur_elem:   Pointer to element in list to remove.
- *  Returns:
- *  Requires:
- *      - LST initialized.
- *      - lst != NULL.
- *      - cur_elem != NULL.
- *  Ensures:
- */
-static inline void lst_remove_elem(struct lst_list *lst,
-				   struct list_head *cur_elem)
-{
-	if (lst && !list_empty(&lst->head) && cur_elem)
-		list_del_init(cur_elem);
-}
-
-#endif /* LIST_ */
-- 
1.7.2.3


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

* [PATCH v2 10/12] staging: tidspbridge: core code cleanup
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
                   ` (8 preceding siblings ...)
  2010-11-05 15:13 ` [PATCH v2 09/12] staging: tidspbridge: remove custom linked list Ionut Nicu
@ 2010-11-05 15:13 ` Ionut Nicu
  2010-11-05 15:13 ` [PATCH v2 11/12] staging: tidspbridge: pmgr " Ionut Nicu
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

Reorganized some code in the core module to increase its
readability. Most of the changes reduce the code
indentation level and simplifiy the code. No functional
changes were done.

Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
---
 drivers/staging/tidspbridge/core/chnl_sm.c |  451 +++++++++++++---------------
 drivers/staging/tidspbridge/core/io_sm.c   |  191 ++++++-------
 drivers/staging/tidspbridge/core/msg_sm.c  |  447 ++++++++++++---------------
 3 files changed, 498 insertions(+), 591 deletions(-)

diff --git a/drivers/staging/tidspbridge/core/chnl_sm.c b/drivers/staging/tidspbridge/core/chnl_sm.c
index 83403bb..ba6313f 100644
--- a/drivers/staging/tidspbridge/core/chnl_sm.c
+++ b/drivers/staging/tidspbridge/core/chnl_sm.c
@@ -105,35 +105,31 @@ int bridge_chnl_add_io_req(struct chnl_object *chnl_obj, void *host_buf,
 	is_eos = (byte_size == 0);
 
 	/* Validate args */
-	if (!host_buf || !pchnl) {
-		status = -EFAULT;
-	} else if (is_eos && CHNL_IS_INPUT(pchnl->chnl_mode)) {
-		status = -EPERM;
-	} else {
-		/*
-		 * Check the channel state: only queue chirp if channel state
-		 * allows it.
-		 */
-		dw_state = pchnl->dw_state;
-		if (dw_state != CHNL_STATEREADY) {
-			if (dw_state & CHNL_STATECANCEL)
-				status = -ECANCELED;
-			else if ((dw_state & CHNL_STATEEOS) &&
-				 CHNL_IS_OUTPUT(pchnl->chnl_mode))
-				status = -EPIPE;
-			else
-				/* No other possible states left */
-				DBC_ASSERT(0);
-		}
+	if (!host_buf || !pchnl)
+		return -EFAULT;
+
+	if (is_eos && CHNL_IS_INPUT(pchnl->chnl_mode))
+		return -EPERM;
+
+	/*
+	 * Check the channel state: only queue chirp if channel state
+	 * allows it.
+	 */
+	dw_state = pchnl->dw_state;
+	if (dw_state != CHNL_STATEREADY) {
+		if (dw_state & CHNL_STATECANCEL)
+			return -ECANCELED;
+		if ((dw_state & CHNL_STATEEOS) &&
+				CHNL_IS_OUTPUT(pchnl->chnl_mode))
+			return -EPIPE;
+		/* No other possible states left */
+		DBC_ASSERT(0);
 	}
 
 	dev_obj = dev_get_first();
 	dev_get_bridge_context(dev_obj, &dev_ctxt);
 	if (!dev_ctxt)
-		status = -EFAULT;
-
-	if (status)
-		goto func_end;
+		return -EFAULT;
 
 	if (pchnl->chnl_type == CHNL_PCPY && pchnl->chnl_id > 1 && host_buf) {
 		if (!(host_buf < (void *)USERMODE_ADDR)) {
@@ -142,18 +138,16 @@ int bridge_chnl_add_io_req(struct chnl_object *chnl_obj, void *host_buf,
 		}
 		/* if addr in user mode, then copy to kernel space */
 		host_sys_buf = kmalloc(buf_size, GFP_KERNEL);
-		if (host_sys_buf == NULL) {
-			status = -ENOMEM;
-			goto func_end;
-		}
+		if (host_sys_buf == NULL)
+			return -ENOMEM;
+
 		if (CHNL_IS_OUTPUT(pchnl->chnl_mode)) {
 			status = copy_from_user(host_sys_buf, host_buf,
-						buf_size);
+					buf_size);
 			if (status) {
 				kfree(host_sys_buf);
 				host_sys_buf = NULL;
-				status = -EFAULT;
-				goto func_end;
+				return -EFAULT;
 			}
 		}
 	}
@@ -167,65 +161,62 @@ func_cont:
 	omap_mbox_disable_irq(dev_ctxt->mbox, IRQ_RX);
 	if (pchnl->chnl_type == CHNL_PCPY) {
 		/* This is a processor-copy channel. */
-		if (!status && CHNL_IS_OUTPUT(pchnl->chnl_mode)) {
+		if (CHNL_IS_OUTPUT(pchnl->chnl_mode)) {
 			/* Check buffer size on output channels for fit. */
-			if (byte_size >
-			    io_buf_size(pchnl->chnl_mgr_obj->hio_mgr))
+			if (byte_size > io_buf_size(
+						pchnl->chnl_mgr_obj->hio_mgr)) {
 				status = -EINVAL;
-
+				goto out;
+			}
 		}
 	}
-	if (!status) {
-		/* Get a free chirp: */
-		if (!list_empty(&pchnl->free_packets_list)) {
-			chnl_packet_obj = list_first_entry(
-					&pchnl->free_packets_list,
-					struct chnl_irp, link);
-			list_del(&chnl_packet_obj->link);
-		} else
-			status = -EIO;
-
-	}
-	if (!status) {
-		/* Enqueue the chirp on the chnl's IORequest queue: */
-		chnl_packet_obj->host_user_buf = chnl_packet_obj->host_sys_buf =
-		    host_buf;
-		if (pchnl->chnl_type == CHNL_PCPY && pchnl->chnl_id > 1)
-			chnl_packet_obj->host_sys_buf = host_sys_buf;
-
-		/*
-		 * Note: for dma chans dw_dsp_addr contains dsp address
-		 * of SM buffer.
-		 */
-		DBC_ASSERT(chnl_mgr_obj->word_size != 0);
-		/* DSP address */
-		chnl_packet_obj->dsp_tx_addr =
-		    dw_dsp_addr / chnl_mgr_obj->word_size;
-		chnl_packet_obj->byte_size = byte_size;
-		chnl_packet_obj->buf_size = buf_size;
-		/* Only valid for output channel */
-		chnl_packet_obj->dw_arg = dw_arg;
-		chnl_packet_obj->status = (is_eos ? CHNL_IOCSTATEOS :
-					   CHNL_IOCSTATCOMPLETE);
-		list_add_tail(&chnl_packet_obj->link, &pchnl->pio_requests);
-		pchnl->cio_reqs++;
-		DBC_ASSERT(pchnl->cio_reqs <= pchnl->chnl_packets);
-		/*
-		 * If end of stream, update the channel state to prevent
-		 * more IOR's.
-		 */
-		if (is_eos)
-			pchnl->dw_state |= CHNL_STATEEOS;
-
-		/* Legacy DSM Processor-Copy */
-		DBC_ASSERT(pchnl->chnl_type == CHNL_PCPY);
-		/* Request IO from the DSP */
-		io_request_chnl(chnl_mgr_obj->hio_mgr, pchnl,
-				(CHNL_IS_INPUT(pchnl->chnl_mode) ? IO_INPUT :
-				 IO_OUTPUT), &mb_val);
-		sched_dpc = true;
 
-	}
+	/* Get a free chirp: */
+	if (list_empty(&pchnl->free_packets_list)) {
+		status = -EIO;
+		goto out;
+	}
+	chnl_packet_obj = list_first_entry(&pchnl->free_packets_list,
+			struct chnl_irp, link);
+	list_del(&chnl_packet_obj->link);
+
+	/* Enqueue the chirp on the chnl's IORequest queue: */
+	chnl_packet_obj->host_user_buf = chnl_packet_obj->host_sys_buf =
+		host_buf;
+	if (pchnl->chnl_type == CHNL_PCPY && pchnl->chnl_id > 1)
+		chnl_packet_obj->host_sys_buf = host_sys_buf;
+
+	/*
+	 * Note: for dma chans dw_dsp_addr contains dsp address
+	 * of SM buffer.
+	 */
+	DBC_ASSERT(chnl_mgr_obj->word_size != 0);
+	/* DSP address */
+	chnl_packet_obj->dsp_tx_addr = dw_dsp_addr / chnl_mgr_obj->word_size;
+	chnl_packet_obj->byte_size = byte_size;
+	chnl_packet_obj->buf_size = buf_size;
+	/* Only valid for output channel */
+	chnl_packet_obj->dw_arg = dw_arg;
+	chnl_packet_obj->status = (is_eos ? CHNL_IOCSTATEOS :
+			CHNL_IOCSTATCOMPLETE);
+	list_add_tail(&chnl_packet_obj->link, &pchnl->pio_requests);
+	pchnl->cio_reqs++;
+	DBC_ASSERT(pchnl->cio_reqs <= pchnl->chnl_packets);
+	/*
+	 * If end of stream, update the channel state to prevent
+	 * more IOR's.
+	 */
+	if (is_eos)
+		pchnl->dw_state |= CHNL_STATEEOS;
+
+	/* Legacy DSM Processor-Copy */
+	DBC_ASSERT(pchnl->chnl_type == CHNL_PCPY);
+	/* Request IO from the DSP */
+	io_request_chnl(chnl_mgr_obj->hio_mgr, pchnl,
+			(CHNL_IS_INPUT(pchnl->chnl_mode) ? IO_INPUT :
+			 IO_OUTPUT), &mb_val);
+	sched_dpc = true;
+out:
 	omap_mbox_enable_irq(dev_ctxt->mbox, IRQ_RX);
 	spin_unlock_bh(&chnl_mgr_obj->chnl_mgr_lock);
 	if (mb_val != 0)
@@ -235,7 +226,6 @@ func_cont:
 	if (sched_dpc)
 		iosm_schedule(chnl_mgr_obj->hio_mgr);
 
-func_end:
 	return status;
 }
 
@@ -250,7 +240,6 @@ func_end:
  */
 int bridge_chnl_cancel_io(struct chnl_object *chnl_obj)
 {
-	int status = 0;
 	struct chnl_object *pchnl = (struct chnl_object *)chnl_obj;
 	u32 chnl_id = -1;
 	s8 chnl_mode;
@@ -258,22 +247,23 @@ int bridge_chnl_cancel_io(struct chnl_object *chnl_obj)
 	struct chnl_mgr *chnl_mgr_obj = NULL;
 
 	/* Check args: */
-	if (pchnl && pchnl->chnl_mgr_obj) {
-		chnl_id = pchnl->chnl_id;
-		chnl_mode = pchnl->chnl_mode;
-		chnl_mgr_obj = pchnl->chnl_mgr_obj;
-	} else {
-		status = -EFAULT;
-	}
-	if (status)
-		goto func_end;
+	if (!pchnl || !pchnl->chnl_mgr_obj)
+		return -EFAULT;
+
+	chnl_id = pchnl->chnl_id;
+	chnl_mode = pchnl->chnl_mode;
+	chnl_mgr_obj = pchnl->chnl_mgr_obj;
 
 	/*  Mark this channel as cancelled, to prevent further IORequests or
 	 *  IORequests or dispatching. */
 	spin_lock_bh(&chnl_mgr_obj->chnl_mgr_lock);
+
 	pchnl->dw_state |= CHNL_STATECANCEL;
-	if (list_empty(&pchnl->pio_requests))
-		goto func_cont;
+
+	if (list_empty(&pchnl->pio_requests)) {
+		spin_unlock_bh(&chnl_mgr_obj->chnl_mgr_lock);
+		return 0;
+	}
 
 	if (pchnl->chnl_type == CHNL_PCPY) {
 		/* Indicate we have no more buffers available for transfer: */
@@ -297,10 +287,10 @@ int bridge_chnl_cancel_io(struct chnl_object *chnl_obj)
 		pchnl->cio_reqs--;
 		DBC_ASSERT(pchnl->cio_reqs >= 0);
 	}
-func_cont:
+
 	spin_unlock_bh(&chnl_mgr_obj->chnl_mgr_lock);
-func_end:
-	return status;
+
+	return 0;
 }
 
 /*
@@ -317,53 +307,47 @@ int bridge_chnl_close(struct chnl_object *chnl_obj)
 	struct chnl_object *pchnl = (struct chnl_object *)chnl_obj;
 
 	/* Check args: */
-	if (!pchnl) {
-		status = -EFAULT;
-		goto func_cont;
-	}
-	{
-		/* Cancel IO: this ensures no further IO requests or
-		 * notifications. */
-		status = bridge_chnl_cancel_io(chnl_obj);
+	if (!pchnl)
+		return -EFAULT;
+	/* Cancel IO: this ensures no further IO requests or
+	 * notifications. */
+	status = bridge_chnl_cancel_io(chnl_obj);
+	if (status)
+		return status;
+	/* Assert I/O on this channel is now cancelled: Protects
+	 * from io_dpc. */
+	DBC_ASSERT((pchnl->dw_state & CHNL_STATECANCEL));
+	/* Invalidate channel object: Protects from
+	 * CHNL_GetIOCompletion(). */
+	/* Free the slot in the channel manager: */
+	pchnl->chnl_mgr_obj->ap_channel[pchnl->chnl_id] = NULL;
+	spin_lock_bh(&pchnl->chnl_mgr_obj->chnl_mgr_lock);
+	pchnl->chnl_mgr_obj->open_channels -= 1;
+	spin_unlock_bh(&pchnl->chnl_mgr_obj->chnl_mgr_lock);
+	if (pchnl->ntfy_obj) {
+		ntfy_delete(pchnl->ntfy_obj);
+		kfree(pchnl->ntfy_obj);
+		pchnl->ntfy_obj = NULL;
+	}
+	/* Reset channel event: (NOTE: user_event freed in user
+	 * context.). */
+	if (pchnl->sync_event) {
+		sync_reset_event(pchnl->sync_event);
+		kfree(pchnl->sync_event);
+		pchnl->sync_event = NULL;
 	}
-func_cont:
-	if (!status) {
-		/* Assert I/O on this channel is now cancelled: Protects
-		 * from io_dpc. */
-		DBC_ASSERT((pchnl->dw_state & CHNL_STATECANCEL));
-		/* Invalidate channel object: Protects from
-		 * CHNL_GetIOCompletion(). */
-		/* Free the slot in the channel manager: */
-		pchnl->chnl_mgr_obj->ap_channel[pchnl->chnl_id] = NULL;
-		spin_lock_bh(&pchnl->chnl_mgr_obj->chnl_mgr_lock);
-		pchnl->chnl_mgr_obj->open_channels -= 1;
-		spin_unlock_bh(&pchnl->chnl_mgr_obj->chnl_mgr_lock);
-		if (pchnl->ntfy_obj) {
-			ntfy_delete(pchnl->ntfy_obj);
-			kfree(pchnl->ntfy_obj);
-			pchnl->ntfy_obj = NULL;
-		}
-		/* Reset channel event: (NOTE: user_event freed in user
-		 * context.). */
-		if (pchnl->sync_event) {
-			sync_reset_event(pchnl->sync_event);
-			kfree(pchnl->sync_event);
-			pchnl->sync_event = NULL;
-		}
-		/* Free I/O request and I/O completion queues: */
-		free_chirp_list(&pchnl->pio_completions);
-		pchnl->cio_cs = 0;
+	/* Free I/O request and I/O completion queues: */
+	free_chirp_list(&pchnl->pio_completions);
+	pchnl->cio_cs = 0;
 
-		free_chirp_list(&pchnl->pio_requests);
-		pchnl->cio_reqs = 0;
+	free_chirp_list(&pchnl->pio_requests);
+	pchnl->cio_reqs = 0;
 
-		free_chirp_list(&pchnl->free_packets_list);
+	free_chirp_list(&pchnl->free_packets_list);
+
+	/* Release channel object. */
+	kfree(pchnl);
 
-		/* Release channel object. */
-		kfree(pchnl);
-		pchnl = NULL;
-	}
-	DBC_ENSURE(status || !pchnl);
 	return status;
 }
 
@@ -696,32 +680,22 @@ func_end:
 int bridge_chnl_get_mgr_info(struct chnl_mgr *hchnl_mgr, u32 ch_id,
 				 struct chnl_mgrinfo *mgr_info)
 {
-	int status = 0;
 	struct chnl_mgr *chnl_mgr_obj = (struct chnl_mgr *)hchnl_mgr;
 
-	if (mgr_info != NULL) {
-		if (ch_id <= CHNL_MAXCHANNELS) {
-			if (hchnl_mgr) {
-				/* Return the requested information: */
-				mgr_info->chnl_obj =
-				    chnl_mgr_obj->ap_channel[ch_id];
-				mgr_info->open_channels =
-				    chnl_mgr_obj->open_channels;
-				mgr_info->dw_type = chnl_mgr_obj->dw_type;
-				/* total # of chnls */
-				mgr_info->max_channels =
-				    chnl_mgr_obj->max_channels;
-			} else {
-				status = -EFAULT;
-			}
-		} else {
-			status = -ECHRNG;
-		}
-	} else {
-		status = -EFAULT;
-	}
+	if (!mgr_info || !hchnl_mgr)
+		return -EFAULT;
 
-	return status;
+	if (ch_id > CHNL_MAXCHANNELS)
+		return -ECHRNG;
+
+	/* Return the requested information: */
+	mgr_info->chnl_obj = chnl_mgr_obj->ap_channel[ch_id];
+	mgr_info->open_channels = chnl_mgr_obj->open_channels;
+	mgr_info->dw_type = chnl_mgr_obj->dw_type;
+	/* total # of chnls */
+	mgr_info->max_channels = chnl_mgr_obj->max_channels;
+
+	return 0;
 }
 
 /*
@@ -771,112 +745,107 @@ int bridge_chnl_open(struct chnl_object **chnl,
 	DBC_REQUIRE(pattrs != NULL);
 	DBC_REQUIRE(hchnl_mgr != NULL);
 	*chnl = NULL;
+
 	/* Validate Args: */
-	if (pattrs->uio_reqs == 0) {
-		status = -EINVAL;
+	if (!pattrs->uio_reqs)
+		return -EINVAL;
+
+	if (!hchnl_mgr)
+		return -EFAULT;
+
+	if (ch_id != CHNL_PICKFREE) {
+		if (ch_id >= chnl_mgr_obj->max_channels)
+			return -ECHRNG;
+		if (chnl_mgr_obj->ap_channel[ch_id] != NULL)
+			return -EALREADY;
 	} else {
-		if (!hchnl_mgr) {
-			status = -EFAULT;
-		} else {
-			if (ch_id != CHNL_PICKFREE) {
-				if (ch_id >= chnl_mgr_obj->max_channels)
-					status = -ECHRNG;
-				else if (chnl_mgr_obj->ap_channel[ch_id] !=
-					 NULL)
-					status = -EALREADY;
-			} else {
-				/* Check for free channel */
-				status =
-				    search_free_channel(chnl_mgr_obj, &ch_id);
-			}
-		}
+		/* Check for free channel */
+		status = search_free_channel(chnl_mgr_obj, &ch_id);
+		if (status)
+			return status;
 	}
-	if (status)
-		goto func_end;
 
 	DBC_ASSERT(ch_id < chnl_mgr_obj->max_channels);
+
 	/* Create channel object: */
 	pchnl = kzalloc(sizeof(struct chnl_object), GFP_KERNEL);
-	if (!pchnl) {
-		status = -ENOMEM;
-		goto func_end;
-	}
+	if (!pchnl)
+		return -ENOMEM;
+
 	/* Protect queues from io_dpc: */
 	pchnl->dw_state = CHNL_STATECANCEL;
+
 	/* Allocate initial IOR and IOC queues: */
-	status = create_chirp_list(&pchnl->free_packets_list,
-			pattrs->uio_reqs);
+	status = create_chirp_list(&pchnl->free_packets_list, pattrs->uio_reqs);
 	if (status)
-		goto func_end;
+		goto out_err;
 
 	status = create_chirp_list(&pchnl->pio_requests, 0);
 	if (status)
-		goto func_end;
+		goto out_err;
 
 	status = create_chirp_list(&pchnl->pio_completions, 0);
 	if (status)
-		goto func_end;
+		goto out_err;
 
 	pchnl->chnl_packets = pattrs->uio_reqs;
 	pchnl->cio_cs = 0;
 	pchnl->cio_reqs = 0;
+
 	sync_event = kzalloc(sizeof(struct sync_object), GFP_KERNEL);
-	if (sync_event)
-		sync_init_event(sync_event);
-	else
+	if (!sync_event) {
 		status = -ENOMEM;
-
-	if (!status) {
-		pchnl->ntfy_obj = kmalloc(sizeof(struct ntfy_object),
-							GFP_KERNEL);
-		if (pchnl->ntfy_obj)
-			ntfy_init(pchnl->ntfy_obj);
-		else
-			status = -ENOMEM;
+		goto out_err;
 	}
+	sync_init_event(sync_event);
 
-	if (!status) {
-		/* Initialize CHNL object fields: */
-		pchnl->chnl_mgr_obj = chnl_mgr_obj;
-		pchnl->chnl_id = ch_id;
-		pchnl->chnl_mode = chnl_mode;
-		pchnl->user_event = sync_event;
-		pchnl->sync_event = sync_event;
-		/* Get the process handle */
-		pchnl->process = current->tgid;
-		pchnl->pcb_arg = 0;
-		pchnl->bytes_moved = 0;
-		/* Default to proc-copy */
-		pchnl->chnl_type = CHNL_PCPY;
-	}
+	pchnl->ntfy_obj = kmalloc(sizeof(struct ntfy_object), GFP_KERNEL);
+	if (!pchnl->ntfy_obj) {
+		status = -ENOMEM;
+		goto out_err;
+	}
+	ntfy_init(pchnl->ntfy_obj);
+
+	/* Initialize CHNL object fields: */
+	pchnl->chnl_mgr_obj = chnl_mgr_obj;
+	pchnl->chnl_id = ch_id;
+	pchnl->chnl_mode = chnl_mode;
+	pchnl->user_event = sync_event;
+	pchnl->sync_event = sync_event;
+	/* Get the process handle */
+	pchnl->process = current->tgid;
+	pchnl->pcb_arg = 0;
+	pchnl->bytes_moved = 0;
+	/* Default to proc-copy */
+	pchnl->chnl_type = CHNL_PCPY;
+
+	/* Insert channel object in channel manager: */
+	chnl_mgr_obj->ap_channel[pchnl->chnl_id] = pchnl;
+	spin_lock_bh(&chnl_mgr_obj->chnl_mgr_lock);
+	chnl_mgr_obj->open_channels++;
+	spin_unlock_bh(&chnl_mgr_obj->chnl_mgr_lock);
+	/* Return result... */
+	pchnl->dw_state = CHNL_STATEREADY;
+	*chnl = pchnl;
 
-	if (status) {
-		/* Free memory */
-		free_chirp_list(&pchnl->pio_completions);
-		pchnl->cio_cs = 0;
-		free_chirp_list(&pchnl->pio_requests);
-		free_chirp_list(&pchnl->free_packets_list);
+	return status;
+
+out_err:
+	/* Free memory */
+	free_chirp_list(&pchnl->pio_completions);
+	free_chirp_list(&pchnl->pio_requests);
+	free_chirp_list(&pchnl->free_packets_list);
+
+	if (sync_event)
 		kfree(sync_event);
-		sync_event = NULL;
 
-		if (pchnl->ntfy_obj) {
-			ntfy_delete(pchnl->ntfy_obj);
-			kfree(pchnl->ntfy_obj);
-			pchnl->ntfy_obj = NULL;
-		}
-		kfree(pchnl);
-	} else {
-		/* Insert channel object in channel manager: */
-		chnl_mgr_obj->ap_channel[pchnl->chnl_id] = pchnl;
-		spin_lock_bh(&chnl_mgr_obj->chnl_mgr_lock);
-		chnl_mgr_obj->open_channels++;
-		spin_unlock_bh(&chnl_mgr_obj->chnl_mgr_lock);
-		/* Return result... */
-		pchnl->dw_state = CHNL_STATEREADY;
-		*chnl = pchnl;
+	if (pchnl->ntfy_obj) {
+		ntfy_delete(pchnl->ntfy_obj);
+		kfree(pchnl->ntfy_obj);
+		pchnl->ntfy_obj = NULL;
 	}
-func_end:
-	DBC_ENSURE((!status && pchnl) || (*chnl == NULL));
+	kfree(pchnl);
+
 	return status;
 }
 
diff --git a/drivers/staging/tidspbridge/core/io_sm.c b/drivers/staging/tidspbridge/core/io_sm.c
index 9851f32..de2cc3b 100644
--- a/drivers/staging/tidspbridge/core/io_sm.c
+++ b/drivers/staging/tidspbridge/core/io_sm.c
@@ -1064,29 +1064,29 @@ static void input_msg(struct io_mgr *pio_mgr, struct msg_mgr *hmsg_mgr)
 	input_empty = msg_ctr_obj->buf_empty;
 	num_msgs = msg_ctr_obj->size;
 	if (input_empty)
-		goto func_end;
+		return;
 
 	msg_input = pio_mgr->msg_input;
 	for (i = 0; i < num_msgs; i++) {
 		/* Read the next message */
 		addr = (u32) &(((struct msg_dspmsg *)msg_input)->msg.dw_cmd);
 		msg.msg.dw_cmd =
-		    read_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr);
+			read_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr);
 		addr = (u32) &(((struct msg_dspmsg *)msg_input)->msg.dw_arg1);
 		msg.msg.dw_arg1 =
-		    read_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr);
+			read_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr);
 		addr = (u32) &(((struct msg_dspmsg *)msg_input)->msg.dw_arg2);
 		msg.msg.dw_arg2 =
-		    read_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr);
+			read_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr);
 		addr = (u32) &(((struct msg_dspmsg *)msg_input)->msgq_id);
 		msg.msgq_id =
-		    read_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr);
+			read_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr);
 		msg_input += sizeof(struct msg_dspmsg);
 
 		/* Determine which queue to put the message in */
 		dev_dbg(bridge,	"input msg: dw_cmd=0x%x dw_arg1=0x%x "
-			"dw_arg2=0x%x msgq_id=0x%x\n", msg.msg.dw_cmd,
-			msg.msg.dw_arg1, msg.msg.dw_arg2, msg.msgq_id);
+				"dw_arg2=0x%x msgq_id=0x%x\n", msg.msg.dw_cmd,
+				msg.msg.dw_arg1, msg.msg.dw_arg2, msg.msgq_id);
 		/*
 		 * Interrupt may occur before shared memory and message
 		 * input locations have been set up. If all nodes were
@@ -1094,47 +1094,43 @@ static void input_msg(struct io_mgr *pio_mgr, struct msg_mgr *hmsg_mgr)
 		 */
 		list_for_each_entry(msg_queue_obj, &hmsg_mgr->queue_list,
 				list_elem) {
-			if (msg.msgq_id == msg_queue_obj->msgq_id) {
-				/* Found it */
-				if (msg.msg.dw_cmd == RMS_EXITACK) {
-					/*
-					 * Call the node exit notification.
-					 * The exit message does not get
-					 * queued.
-					 */
-					(*hmsg_mgr->on_exit) ((void *)
-							msg_queue_obj->arg,
-							msg.msg.dw_arg1);
-					break;
-				}
+			if (msg.msgq_id != msg_queue_obj->msgq_id)
+				continue;
+			/* Found it */
+			if (msg.msg.dw_cmd == RMS_EXITACK) {
 				/*
-				 * Not an exit acknowledgement, queue
-				 * the message.
+				 * Call the node exit notification.
+				 * The exit message does not get
+				 * queued.
 				 */
-				if (!list_empty(&msg_queue_obj->msg_free_list)) {
-					pmsg = list_first_entry(
-						&msg_queue_obj->msg_free_list,
-						struct msg_frame, list_elem);
-					list_del(&pmsg->list_elem);
-					pmsg->msg_data = msg;
-					list_add_tail(&pmsg->list_elem,
-						&msg_queue_obj->msg_used_list);
-					ntfy_notify
-						(msg_queue_obj->ntfy_obj,
-						 DSP_NODEMESSAGEREADY);
-					sync_set_event
-						(msg_queue_obj->sync_event);
-				} else {
-					/*
-					 * No free frame to copy the
-					 * message into.
-					 */
-					pr_err("%s: no free msg frames,"
-							" discarding msg\n",
-							__func__);
-				}
+				(*hmsg_mgr->on_exit)(msg_queue_obj->arg,
+						msg.msg.dw_arg1);
 				break;
 			}
+			/*
+			 * Not an exit acknowledgement, queue
+			 * the message.
+			 */
+			if (list_empty(&msg_queue_obj->msg_free_list)) {
+				/*
+				 * No free frame to copy the
+				 * message into.
+				 */
+				pr_err("%s: no free msg frames,"
+						" discarding msg\n",
+						__func__);
+				break;
+			}
+
+			pmsg = list_first_entry(&msg_queue_obj->msg_free_list,
+					struct msg_frame, list_elem);
+			list_del(&pmsg->list_elem);
+			pmsg->msg_data = msg;
+			list_add_tail(&pmsg->list_elem,
+					&msg_queue_obj->msg_used_list);
+			ntfy_notify(msg_queue_obj->ntfy_obj,
+					DSP_NODEMESSAGEREADY);
+			sync_set_event(msg_queue_obj->sync_event);
 		}
 	}
 	/* Set the post SWI flag */
@@ -1144,8 +1140,6 @@ static void input_msg(struct io_mgr *pio_mgr, struct msg_mgr *hmsg_mgr)
 		msg_ctr_obj->post_swi = true;
 		sm_interrupt_dsp(pio_mgr->hbridge_context, MBX_PCPY_CLASS);
 	}
-func_end:
-	return;
 }
 
 /*
@@ -1276,73 +1270,68 @@ static void output_msg(struct io_mgr *pio_mgr, struct msg_mgr *hmsg_mgr)
 {
 	u32 num_msgs = 0;
 	u32 i;
-	u8 *msg_output;
+	struct msg_dspmsg *msg_output;
 	struct msg_frame *pmsg;
 	struct msg_ctrl *msg_ctr_obj;
-	u32 output_empty;
 	u32 val;
 	u32 addr;
 
 	msg_ctr_obj = pio_mgr->msg_output_ctrl;
 
 	/* Check if output has been cleared */
-	output_empty = msg_ctr_obj->buf_empty;
-	if (output_empty) {
-		num_msgs = (hmsg_mgr->msgs_pending > hmsg_mgr->max_msgs) ?
-		    hmsg_mgr->max_msgs : hmsg_mgr->msgs_pending;
-		msg_output = pio_mgr->msg_output;
-		/* Copy num_msgs messages into shared memory */
-		for (i = 0; i < num_msgs; i++) {
-			if (!list_empty(&hmsg_mgr->msg_used_list)) {
-				pmsg = list_first_entry(
-						&hmsg_mgr->msg_used_list,
-						struct msg_frame, list_elem);
-				list_del(&pmsg->list_elem);
-				val = (pmsg->msg_data).msgq_id;
-				addr = (u32) &(((struct msg_dspmsg *)
-						 msg_output)->msgq_id);
-				write_ext32_bit_dsp_data(
-					pio_mgr->hbridge_context, addr, val);
-				val = (pmsg->msg_data).msg.dw_cmd;
-				addr = (u32) &((((struct msg_dspmsg *)
-						  msg_output)->msg).dw_cmd);
-				write_ext32_bit_dsp_data(
-					pio_mgr->hbridge_context, addr, val);
-				val = (pmsg->msg_data).msg.dw_arg1;
-				addr = (u32) &((((struct msg_dspmsg *)
-						  msg_output)->msg).dw_arg1);
-				write_ext32_bit_dsp_data(
-					pio_mgr->hbridge_context, addr, val);
-				val = (pmsg->msg_data).msg.dw_arg2;
-				addr = (u32) &((((struct msg_dspmsg *)
-						  msg_output)->msg).dw_arg2);
-				write_ext32_bit_dsp_data(
-					pio_mgr->hbridge_context, addr, val);
-				msg_output += sizeof(struct msg_dspmsg);
-				list_add_tail(&pmsg->list_elem,
-						&hmsg_mgr->msg_free_list);
-				sync_set_event(hmsg_mgr->sync_event);
-			}
-		}
+	if (!msg_ctr_obj->buf_empty)
+		return;
+
+	num_msgs = (hmsg_mgr->msgs_pending > hmsg_mgr->max_msgs) ?
+		hmsg_mgr->max_msgs : hmsg_mgr->msgs_pending;
+	msg_output = (struct msg_dspmsg *) pio_mgr->msg_output;
+
+	/* Copy num_msgs messages into shared memory */
+	for (i = 0; i < num_msgs; i++) {
+		if (list_empty(&hmsg_mgr->msg_used_list))
+			continue;
+
+		pmsg = list_first_entry(&hmsg_mgr->msg_used_list,
+				struct msg_frame, list_elem);
+		list_del(&pmsg->list_elem);
+
+		val = (pmsg->msg_data).msgq_id;
+		addr = (u32) &msg_output->msgq_id;
+		write_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr, val);
+
+		val = (pmsg->msg_data).msg.dw_cmd;
+		addr = (u32) &msg_output->msg.dw_cmd;
+		write_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr, val);
+
+		val = (pmsg->msg_data).msg.dw_arg1;
+		addr = (u32) &msg_output->msg.dw_arg1;
+		write_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr, val);
+
+		val = (pmsg->msg_data).msg.dw_arg2;
+		addr = (u32) &msg_output->msg.dw_arg2;
+		write_ext32_bit_dsp_data(pio_mgr->hbridge_context, addr, val);
 
-		if (num_msgs > 0) {
-			hmsg_mgr->msgs_pending -= num_msgs;
+		msg_output++;
+		list_add_tail(&pmsg->list_elem, &hmsg_mgr->msg_free_list);
+		sync_set_event(hmsg_mgr->sync_event);
+	}
+
+	if (num_msgs > 0) {
+		hmsg_mgr->msgs_pending -= num_msgs;
 #if _CHNL_WORDSIZE == 2
-			/*
-			 * Access can be different SM access word size
-			 * (e.g. 16/32 bit words)
-			 */
-			msg_ctr_obj->size = (u16) num_msgs;
+		/*
+		 * Access can be different SM access word size
+		 * (e.g. 16/32 bit words)
+		 */
+		msg_ctr_obj->size = (u16) num_msgs;
 #else
-			msg_ctr_obj->size = num_msgs;
+		msg_ctr_obj->size = num_msgs;
 #endif
-			msg_ctr_obj->buf_empty = false;
-			/* Set the post SWI flag */
-			msg_ctr_obj->post_swi = true;
-			/* Tell the DSP we have written the output. */
-			sm_interrupt_dsp(pio_mgr->hbridge_context,
-						MBX_PCPY_CLASS);
-		}
+		msg_ctr_obj->buf_empty = false;
+		/* Set the post SWI flag */
+		msg_ctr_obj->post_swi = true;
+		/* Tell the DSP we have written the output. */
+		sm_interrupt_dsp(pio_mgr->hbridge_context, MBX_PCPY_CLASS);
 	}
 }
 
diff --git a/drivers/staging/tidspbridge/core/msg_sm.c b/drivers/staging/tidspbridge/core/msg_sm.c
index de2cb83..8666121 100644
--- a/drivers/staging/tidspbridge/core/msg_sm.c
+++ b/drivers/staging/tidspbridge/core/msg_sm.c
@@ -55,49 +55,42 @@ int bridge_msg_create(struct msg_mgr **msg_man,
 	struct io_mgr *hio_mgr;
 	int status = 0;
 
-	if (!msg_man || !msg_callback || !hdev_obj) {
-		status = -EFAULT;
-		goto func_end;
-	}
+	if (!msg_man || !msg_callback || !hdev_obj)
+		return -EFAULT;
+
 	dev_get_io_mgr(hdev_obj, &hio_mgr);
-	if (!hio_mgr) {
-		status = -EFAULT;
-		goto func_end;
-	}
+	if (!hio_mgr)
+		return -EFAULT;
+
 	*msg_man = NULL;
 	/* Allocate msg_ctrl manager object */
 	msg_mgr_obj = kzalloc(sizeof(struct msg_mgr), GFP_KERNEL);
-
-	if (msg_mgr_obj) {
-		msg_mgr_obj->on_exit = msg_callback;
-		msg_mgr_obj->hio_mgr = hio_mgr;
-		/* List of MSG_QUEUEs */
-		INIT_LIST_HEAD(&msg_mgr_obj->queue_list);
-		/*  Queues of message frames for messages to the DSP. Message
-		 * frames will only be added to the free queue when a
-		 * msg_queue object is created. */
-		INIT_LIST_HEAD(&msg_mgr_obj->msg_free_list);
-		INIT_LIST_HEAD(&msg_mgr_obj->msg_used_list);
-		spin_lock_init(&msg_mgr_obj->msg_mgr_lock);
-
-		/*  Create an event to be used by bridge_msg_put() in waiting
-		 *  for an available free frame from the message manager. */
-		msg_mgr_obj->sync_event =
-				kzalloc(sizeof(struct sync_object), GFP_KERNEL);
-		if (!msg_mgr_obj->sync_event)
-			status = -ENOMEM;
-		else
-			sync_init_event(msg_mgr_obj->sync_event);
-
-		if (!status)
-			*msg_man = msg_mgr_obj;
-		else
-			delete_msg_mgr(msg_mgr_obj);
-
-	} else {
-		status = -ENOMEM;
+	if (!msg_mgr_obj)
+		return -ENOMEM;
+
+	msg_mgr_obj->on_exit = msg_callback;
+	msg_mgr_obj->hio_mgr = hio_mgr;
+	/* List of MSG_QUEUEs */
+	INIT_LIST_HEAD(&msg_mgr_obj->queue_list);
+	/*  Queues of message frames for messages to the DSP. Message
+	 * frames will only be added to the free queue when a
+	 * msg_queue object is created. */
+	INIT_LIST_HEAD(&msg_mgr_obj->msg_free_list);
+	INIT_LIST_HEAD(&msg_mgr_obj->msg_used_list);
+	spin_lock_init(&msg_mgr_obj->msg_mgr_lock);
+
+	/*  Create an event to be used by bridge_msg_put() in waiting
+	 *  for an available free frame from the message manager. */
+	msg_mgr_obj->sync_event =
+		kzalloc(sizeof(struct sync_object), GFP_KERNEL);
+	if (!msg_mgr_obj->sync_event) {
+		kfree(msg_mgr_obj);
+		return -ENOMEM;
 	}
-func_end:
+	sync_init_event(msg_mgr_obj->sync_event);
+
+	*msg_man = msg_mgr_obj;
+
 	return status;
 }
 
@@ -106,8 +99,7 @@ func_end:
  *      Create a msg_queue for sending/receiving messages to/from a node
  *      on the DSP.
  */
-int bridge_msg_create_queue(struct msg_mgr *hmsg_mgr,
-				struct msg_queue **msgq,
+int bridge_msg_create_queue(struct msg_mgr *hmsg_mgr, struct msg_queue **msgq,
 				u32 msgq_id, u32 max_msgs, void *arg)
 {
 	u32 i;
@@ -115,18 +107,15 @@ int bridge_msg_create_queue(struct msg_mgr *hmsg_mgr,
 	struct msg_queue *msg_q;
 	int status = 0;
 
-	if (!hmsg_mgr || msgq == NULL) {
-		status = -EFAULT;
-		goto func_end;
-	}
+	if (!hmsg_mgr || msgq == NULL)
+		return -EFAULT;
 
 	*msgq = NULL;
 	/* Allocate msg_queue object */
 	msg_q = kzalloc(sizeof(struct msg_queue), GFP_KERNEL);
-	if (!msg_q) {
-		status = -ENOMEM;
-		goto func_end;
-	}
+	if (!msg_q)
+		return -ENOMEM;
+
 	msg_q->max_msgs = max_msgs;
 	msg_q->hmsg_mgr = hmsg_mgr;
 	msg_q->arg = arg;	/* Node handle */
@@ -137,78 +126,68 @@ int bridge_msg_create_queue(struct msg_mgr *hmsg_mgr,
 
 	/*  Create event that will be signalled when a message from
 	 *  the DSP is available. */
-	if (!status) {
-		msg_q->sync_event = kzalloc(sizeof(struct sync_object),
-							GFP_KERNEL);
-		if (msg_q->sync_event)
-			sync_init_event(msg_q->sync_event);
-		else
-			status = -ENOMEM;
+	msg_q->sync_event = kzalloc(sizeof(struct sync_object), GFP_KERNEL);
+	if (!msg_q->sync_event) {
+		status = -ENOMEM;
+		goto out_err;
+
 	}
+	sync_init_event(msg_q->sync_event);
 
 	/* Create a notification list for message ready notification. */
-	if (!status) {
-		msg_q->ntfy_obj = kmalloc(sizeof(struct ntfy_object),
-							GFP_KERNEL);
-		if (msg_q->ntfy_obj)
-			ntfy_init(msg_q->ntfy_obj);
-		else
-			status = -ENOMEM;
+	msg_q->ntfy_obj = kmalloc(sizeof(struct ntfy_object), GFP_KERNEL);
+	if (!msg_q->ntfy_obj) {
+		status = -ENOMEM;
+		goto out_err;
 	}
+	ntfy_init(msg_q->ntfy_obj);
 
 	/*  Create events that will be used to synchronize cleanup
 	 *  when the object is deleted. sync_done will be set to
 	 *  unblock threads in MSG_Put() or MSG_Get(). sync_done_ack
 	 *  will be set by the unblocked thread to signal that it
 	 *  is unblocked and will no longer reference the object. */
-	if (!status) {
-		msg_q->sync_done = kzalloc(sizeof(struct sync_object),
-							GFP_KERNEL);
-		if (msg_q->sync_done)
-			sync_init_event(msg_q->sync_done);
-		else
-			status = -ENOMEM;
+	msg_q->sync_done = kzalloc(sizeof(struct sync_object), GFP_KERNEL);
+	if (!msg_q->sync_done) {
+		status = -ENOMEM;
+		goto out_err;
 	}
+	sync_init_event(msg_q->sync_done);
 
-	if (!status) {
-		msg_q->sync_done_ack = kzalloc(sizeof(struct sync_object),
-							GFP_KERNEL);
-		if (msg_q->sync_done_ack)
-			sync_init_event(msg_q->sync_done_ack);
-		else
-			status = -ENOMEM;
+	msg_q->sync_done_ack = kzalloc(sizeof(struct sync_object), GFP_KERNEL);
+	if (!msg_q->sync_done_ack) {
+		status = -ENOMEM;
+		goto out_err;
 	}
+	sync_init_event(msg_q->sync_done_ack);
 
-	if (!status) {
-		/* Enter critical section */
-		spin_lock_bh(&hmsg_mgr->msg_mgr_lock);
-		/* Initialize message frames and put in appropriate queues */
-		for (i = 0; i < max_msgs && !status; i++) {
-			status = add_new_msg(&hmsg_mgr->msg_free_list);
-			if (!status) {
-				num_allocated++;
-				status = add_new_msg(&msg_q->msg_free_list);
-			}
-		}
-		if (status) {
-			/*  Stay inside CS to prevent others from taking any
-			 *  of the newly allocated message frames. */
-			delete_msg_queue(msg_q, num_allocated);
-		} else {
-			list_add_tail(&msg_q->list_elem,
-					&hmsg_mgr->queue_list);
-			*msgq = msg_q;
-			/* Signal that free frames are now available */
-			if (!list_empty(&hmsg_mgr->msg_free_list))
-				sync_set_event(hmsg_mgr->sync_event);
-
+	/* Enter critical section */
+	spin_lock_bh(&hmsg_mgr->msg_mgr_lock);
+	/* Initialize message frames and put in appropriate queues */
+	for (i = 0; i < max_msgs && !status; i++) {
+		status = add_new_msg(&hmsg_mgr->msg_free_list);
+		if (!status) {
+			num_allocated++;
+			status = add_new_msg(&msg_q->msg_free_list);
 		}
-		/* Exit critical section */
+	}
+	if (status) {
 		spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
-	} else {
-		delete_msg_queue(msg_q, 0);
+		goto out_err;
 	}
-func_end:
+
+	list_add_tail(&msg_q->list_elem, &hmsg_mgr->queue_list);
+	*msgq = msg_q;
+	/* Signal that free frames are now available */
+	if (!list_empty(&hmsg_mgr->msg_free_list))
+		sync_set_event(hmsg_mgr->sync_event);
+
+	/* Exit critical section */
+	spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
+
+	return 0;
+out_err:
+	delete_msg_queue(msg_q, num_allocated);
 	return status;
 }
 
@@ -232,7 +211,7 @@ void bridge_msg_delete_queue(struct msg_queue *msg_queue_obj)
 	u32 io_msg_pend;
 
 	if (!msg_queue_obj || !msg_queue_obj->hmsg_mgr)
-		goto func_end;
+		return;
 
 	hmsg_mgr = msg_queue_obj->hmsg_mgr;
 	msg_queue_obj->done = true;
@@ -252,10 +231,7 @@ void bridge_msg_delete_queue(struct msg_queue *msg_queue_obj)
 	delete_msg_queue(msg_queue_obj, msg_queue_obj->max_msgs);
 	if (list_empty(&hmsg_mgr->msg_free_list))
 		sync_reset_event(hmsg_mgr->sync_event);
-
 	spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
-func_end:
-	return;
 }
 
 /*
@@ -267,19 +243,15 @@ int bridge_msg_get(struct msg_queue *msg_queue_obj,
 {
 	struct msg_frame *msg_frame_obj;
 	struct msg_mgr *hmsg_mgr;
-	bool got_msg = false;
 	struct sync_object *syncs[2];
 	u32 index;
 	int status = 0;
 
-	if (!msg_queue_obj || pmsg == NULL) {
-		status = -ENOMEM;
-		goto func_end;
-	}
+	if (!msg_queue_obj || pmsg == NULL)
+		return -ENOMEM;
 
 	hmsg_mgr = msg_queue_obj->hmsg_mgr;
 
-	/* Enter critical section */
 	spin_lock_bh(&hmsg_mgr->msg_mgr_lock);
 	/* If a message is already there, get it */
 	if (!list_empty(&msg_queue_obj->msg_used_list)) {
@@ -291,59 +263,51 @@ int bridge_msg_get(struct msg_queue *msg_queue_obj,
 				&msg_queue_obj->msg_free_list);
 		if (list_empty(&msg_queue_obj->msg_used_list))
 			sync_reset_event(msg_queue_obj->sync_event);
+		spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
+		return 0;
+	}
 
-		got_msg = true;
-	} else {
-		if (msg_queue_obj->done)
-			status = -EPERM;
-		else
-			msg_queue_obj->io_msg_pend++;
-
+	if (msg_queue_obj->done) {
+		spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
+		return -EPERM;
 	}
-	/* Exit critical section */
+	msg_queue_obj->io_msg_pend++;
 	spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
-	if (!status && !got_msg) {
-		/*  Wait til message is available, timeout, or done. We don't
-		 *  have to schedule the DPC, since the DSP will send messages
-		 *  when they are available. */
-		syncs[0] = msg_queue_obj->sync_event;
-		syncs[1] = msg_queue_obj->sync_done;
-		status = sync_wait_on_multiple_events(syncs, 2, utimeout,
-						      &index);
-		/* Enter critical section */
-		spin_lock_bh(&hmsg_mgr->msg_mgr_lock);
-		if (msg_queue_obj->done) {
-			msg_queue_obj->io_msg_pend--;
-			/* Exit critical section */
-			spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
-			/*  Signal that we're not going to access msg_queue_obj
-			 *  anymore, so it can be deleted. */
-			(void)sync_set_event(msg_queue_obj->sync_done_ack);
-			status = -EPERM;
-		} else {
-			if (!status && !list_empty(&msg_queue_obj->
-						msg_used_list)) {
-				/* Get msg from used list */
-				msg_frame_obj = list_first_entry(
-						&msg_queue_obj->msg_used_list,
-						struct msg_frame, list_elem);
-				list_del(&msg_frame_obj->list_elem);
-				/* Copy message into pmsg and put frame on the
-				 * free list */
-				*pmsg = msg_frame_obj->msg_data.msg;
-				list_add_tail(&msg_frame_obj->list_elem,
-						&msg_queue_obj->msg_free_list);
-			}
-			msg_queue_obj->io_msg_pend--;
-			/* Reset the event if there are still queued messages */
-			if (!list_empty(&msg_queue_obj->msg_used_list))
-				sync_set_event(msg_queue_obj->sync_event);
-
-			/* Exit critical section */
-			spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
-		}
+
+	/*  Wait til message is available, timeout, or done. We don't
+	 *  have to schedule the DPC, since the DSP will send messages
+	 *  when they are available. */
+	syncs[0] = msg_queue_obj->sync_event;
+	syncs[1] = msg_queue_obj->sync_done;
+	status = sync_wait_on_multiple_events(syncs, 2, utimeout, &index);
+
+	spin_lock_bh(&hmsg_mgr->msg_mgr_lock);
+	if (msg_queue_obj->done) {
+		msg_queue_obj->io_msg_pend--;
+		spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
+		/*  Signal that we're not going to access msg_queue_obj
+		 *  anymore, so it can be deleted. */
+		sync_set_event(msg_queue_obj->sync_done_ack);
+		return -EPERM;
 	}
-func_end:
+	if (!status && !list_empty(&msg_queue_obj->msg_used_list)) {
+		/* Get msg from used list */
+		msg_frame_obj = list_first_entry(&msg_queue_obj->msg_used_list,
+				struct msg_frame, list_elem);
+		list_del(&msg_frame_obj->list_elem);
+		/* Copy message into pmsg and put frame on the
+		 * free list */
+		*pmsg = msg_frame_obj->msg_data.msg;
+		list_add_tail(&msg_frame_obj->list_elem,
+				&msg_queue_obj->msg_free_list);
+	}
+	msg_queue_obj->io_msg_pend--;
+	/* Reset the event if there are still queued messages */
+	if (!list_empty(&msg_queue_obj->msg_used_list))
+		sync_set_event(msg_queue_obj->sync_event);
+
+	spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
+
 	return status;
 }
 
@@ -356,15 +320,13 @@ int bridge_msg_put(struct msg_queue *msg_queue_obj,
 {
 	struct msg_frame *msg_frame_obj;
 	struct msg_mgr *hmsg_mgr;
-	bool put_msg = false;
 	struct sync_object *syncs[2];
 	u32 index;
-	int status = 0;
+	int status;
+
+	if (!msg_queue_obj || !pmsg || !msg_queue_obj->hmsg_mgr)
+		return -EFAULT;
 
-	if (!msg_queue_obj || !pmsg || !msg_queue_obj->hmsg_mgr) {
-		status = -ENOMEM;
-		goto func_end;
-	}
 	hmsg_mgr = msg_queue_obj->hmsg_mgr;
 
 	spin_lock_bh(&hmsg_mgr->msg_mgr_lock);
@@ -380,7 +342,7 @@ int bridge_msg_put(struct msg_queue *msg_queue_obj,
 		list_add_tail(&msg_frame_obj->list_elem,
 				&hmsg_mgr->msg_used_list);
 		hmsg_mgr->msgs_pending++;
-		put_msg = true;
+
 		if (list_empty(&hmsg_mgr->msg_free_list))
 			sync_reset_event(hmsg_mgr->sync_event);
 
@@ -388,70 +350,69 @@ int bridge_msg_put(struct msg_queue *msg_queue_obj,
 		spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
 		/* Schedule a DPC, to do the actual data transfer: */
 		iosm_schedule(hmsg_mgr->hio_mgr);
-	} else {
-		if (msg_queue_obj->done)
-			status = -EPERM;
-		else
-			msg_queue_obj->io_msg_pend++;
+		return 0;
+	}
 
+	if (msg_queue_obj->done) {
 		spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
+		return -EPERM;
 	}
-	if (!status && !put_msg) {
-		/* Wait til a free message frame is available, timeout,
-		 * or done */
-		syncs[0] = hmsg_mgr->sync_event;
-		syncs[1] = msg_queue_obj->sync_done;
-		status = sync_wait_on_multiple_events(syncs, 2, utimeout,
-						      &index);
-		if (status)
-			goto func_end;
-		/* Enter critical section */
-		spin_lock_bh(&hmsg_mgr->msg_mgr_lock);
-		if (msg_queue_obj->done) {
-			msg_queue_obj->io_msg_pend--;
-			/* Exit critical section */
-			spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
-			/*  Signal that we're not going to access msg_queue_obj
-			 *  anymore, so it can be deleted. */
-			(void)sync_set_event(msg_queue_obj->sync_done_ack);
-			status = -EPERM;
-		} else {
-			if (list_empty(&hmsg_mgr->msg_free_list)) {
-				status = -EFAULT;
-				goto func_cont;
-			}
-			/* Get msg from free list */
-			msg_frame_obj = list_first_entry(
-					&hmsg_mgr->msg_free_list,
-					struct msg_frame, list_elem);
-			list_del(&msg_frame_obj->list_elem);
-			/*
-			 * Copy message into pmsg and put frame on the
-			 * used list.
-			 */
-			msg_frame_obj->msg_data.msg = *pmsg;
-			msg_frame_obj->msg_data.msgq_id =
-				msg_queue_obj->msgq_id;
-			list_add_tail(&msg_frame_obj->list_elem,
-					&hmsg_mgr->msg_used_list);
-			hmsg_mgr->msgs_pending++;
-			/*
-			 * Schedule a DPC, to do the actual
-			 * data transfer.
-			 */
-			iosm_schedule(hmsg_mgr->hio_mgr);
-
-			msg_queue_obj->io_msg_pend--;
-			/* Reset event if there are still frames available */
-			if (!list_empty(&hmsg_mgr->msg_free_list))
-				sync_set_event(hmsg_mgr->sync_event);
-func_cont:
-			/* Exit critical section */
-			spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
-		}
+	msg_queue_obj->io_msg_pend++;
+
+	spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
+
+	/* Wait til a free message frame is available, timeout,
+	 * or done */
+	syncs[0] = hmsg_mgr->sync_event;
+	syncs[1] = msg_queue_obj->sync_done;
+	status = sync_wait_on_multiple_events(syncs, 2, utimeout, &index);
+	if (status)
+		return status;
+
+	/* Enter critical section */
+	spin_lock_bh(&hmsg_mgr->msg_mgr_lock);
+	if (msg_queue_obj->done) {
+		msg_queue_obj->io_msg_pend--;
+		/* Exit critical section */
+		spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
+		/*  Signal that we're not going to access msg_queue_obj
+		 *  anymore, so it can be deleted. */
+		sync_set_event(msg_queue_obj->sync_done_ack);
+		return -EPERM;
 	}
-func_end:
-	return status;
+
+	if (list_empty(&hmsg_mgr->msg_free_list)) {
+		spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
+		return -EFAULT;
+	}
+
+	/* Get msg from free list */
+	msg_frame_obj = list_first_entry(&hmsg_mgr->msg_free_list,
+			struct msg_frame, list_elem);
+	/*
+	 * Copy message into pmsg and put frame on the
+	 * used list.
+	 */
+	list_del(&msg_frame_obj->list_elem);
+	msg_frame_obj->msg_data.msg = *pmsg;
+	msg_frame_obj->msg_data.msgq_id = msg_queue_obj->msgq_id;
+	list_add_tail(&msg_frame_obj->list_elem, &hmsg_mgr->msg_used_list);
+	hmsg_mgr->msgs_pending++;
+	/*
+	 * Schedule a DPC, to do the actual
+	 * data transfer.
+	 */
+	iosm_schedule(hmsg_mgr->hio_mgr);
+
+	msg_queue_obj->io_msg_pend--;
+	/* Reset event if there are still frames available */
+	if (!list_empty(&hmsg_mgr->msg_free_list))
+		sync_set_event(hmsg_mgr->sync_event);
+
+	/* Exit critical section */
+	spin_unlock_bh(&hmsg_mgr->msg_mgr_lock);
+
+	return 0;
 }
 
 /*
@@ -518,16 +479,14 @@ void bridge_msg_set_queue_id(struct msg_queue *msg_queue_obj, u32 msgq_id)
 static int add_new_msg(struct list_head *msg_list)
 {
 	struct msg_frame *pmsg;
-	int status = 0;
 
 	pmsg = kzalloc(sizeof(struct msg_frame), GFP_ATOMIC);
-	if (pmsg != NULL) {
-		list_add_tail(&pmsg->list_elem, msg_list);
-	} else {
-		status = -ENOMEM;
-	}
+	if (!pmsg)
+		return -ENOMEM;
 
-	return status;
+	list_add_tail(&pmsg->list_elem, msg_list);
+
+	return 0;
 }
 
 /*
@@ -536,17 +495,13 @@ static int add_new_msg(struct list_head *msg_list)
 static void delete_msg_mgr(struct msg_mgr *hmsg_mgr)
 {
 	if (!hmsg_mgr)
-		goto func_end;
+		return;
 
 	/* FIXME: free elements from queue_list? */
 	free_msg_list(&hmsg_mgr->msg_free_list);
 	free_msg_list(&hmsg_mgr->msg_used_list);
-
 	kfree(hmsg_mgr->sync_event);
-
 	kfree(hmsg_mgr);
-func_end:
-	return;
 }
 
 /*
@@ -559,7 +514,7 @@ static void delete_msg_queue(struct msg_queue *msg_queue_obj, u32 num_to_dsp)
 	u32 i;
 
 	if (!msg_queue_obj || !msg_queue_obj->hmsg_mgr)
-		goto func_end;
+		return;
 
 	hmsg_mgr = msg_queue_obj->hmsg_mgr;
 
@@ -586,9 +541,6 @@ static void delete_msg_queue(struct msg_queue *msg_queue_obj, u32 num_to_dsp)
 	kfree(msg_queue_obj->sync_done_ack);
 
 	kfree(msg_queue_obj);
-func_end:
-	return;
-
 }
 
 /*
@@ -599,13 +551,10 @@ static void free_msg_list(struct list_head *msg_list)
 	struct msg_frame *pmsg, *tmp;
 
 	if (!msg_list)
-		goto func_end;
+		return;
 
 	list_for_each_entry_safe(pmsg, tmp, msg_list, list_elem) {
 		list_del(&pmsg->list_elem);
 		kfree(pmsg);
 	}
-
-func_end:
-	return;
 }
-- 
1.7.2.3


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

* [PATCH v2 11/12] staging: tidspbridge: pmgr code cleanup
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
                   ` (9 preceding siblings ...)
  2010-11-05 15:13 ` [PATCH v2 10/12] staging: tidspbridge: core code cleanup Ionut Nicu
@ 2010-11-05 15:13 ` Ionut Nicu
  2010-11-05 15:13 ` [PATCH v2 12/12] staging: tidspbridge: rmgr " Ionut Nicu
  2010-11-05 15:43 ` [PATCH v2 00/12] staging: tidspbridge: various cleanups Greg KH
  12 siblings, 0 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

Reorganized some code in the pmgr module to increase
its readability. No functional changes were done.

Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
---
 drivers/staging/tidspbridge/pmgr/cmm.c |  354 ++++++++++++++-----------------
 drivers/staging/tidspbridge/pmgr/dev.c |   20 +--
 2 files changed, 166 insertions(+), 208 deletions(-)

diff --git a/drivers/staging/tidspbridge/pmgr/cmm.c b/drivers/staging/tidspbridge/pmgr/cmm.c
index 603ed55..898f3de 100644
--- a/drivers/staging/tidspbridge/pmgr/cmm.c
+++ b/drivers/staging/tidspbridge/pmgr/cmm.c
@@ -250,26 +250,23 @@ int cmm_create(struct cmm_object **ph_cmm_mgr,
 	*ph_cmm_mgr = NULL;
 	/* create, zero, and tag a cmm mgr object */
 	cmm_obj = kzalloc(sizeof(struct cmm_object), GFP_KERNEL);
-	if (cmm_obj != NULL) {
-		if (mgr_attrts == NULL)
-			mgr_attrts = &cmm_dfltmgrattrs;	/* set defaults */
-
-		/* 4 bytes minimum */
-		DBC_ASSERT(mgr_attrts->ul_min_block_size >= 4);
-		/* save away smallest block allocation for this cmm mgr */
-		cmm_obj->ul_min_block_size = mgr_attrts->ul_min_block_size;
-		cmm_obj->dw_page_size = PAGE_SIZE;
-
-		/* Note: DSP SM seg table(aDSPSMSegTab[]) zero'd by
-		 * MEM_ALLOC_OBJECT */
-
-		/* create node free list */
-		INIT_LIST_HEAD(&cmm_obj->node_free_list);
-		mutex_init(&cmm_obj->cmm_lock);
-		*ph_cmm_mgr = cmm_obj;
-	} else {
-		status = -ENOMEM;
-	}
+	if (!cmm_obj)
+		return -ENOMEM;
+
+	if (mgr_attrts == NULL)
+		mgr_attrts = &cmm_dfltmgrattrs;	/* set defaults */
+
+	/* 4 bytes minimum */
+	DBC_ASSERT(mgr_attrts->ul_min_block_size >= 4);
+	/* save away smallest block allocation for this cmm mgr */
+	cmm_obj->ul_min_block_size = mgr_attrts->ul_min_block_size;
+	cmm_obj->dw_page_size = PAGE_SIZE;
+
+	/* create node free list */
+	INIT_LIST_HEAD(&cmm_obj->node_free_list);
+	mutex_init(&cmm_obj->cmm_lock);
+	*ph_cmm_mgr = cmm_obj;
+
 	return status;
 }
 
@@ -346,13 +343,12 @@ void cmm_exit(void)
  *  Purpose:
  *      Free the given buffer.
  */
-int cmm_free_buf(struct cmm_object *hcmm_mgr, void *buf_pa,
-			u32 ul_seg_id)
+int cmm_free_buf(struct cmm_object *hcmm_mgr, void *buf_pa, u32 ul_seg_id)
 {
 	struct cmm_object *cmm_mgr_obj = (struct cmm_object *)hcmm_mgr;
 	int status = -EFAULT;
 	struct cmm_mnode *curr, *tmp;
-	struct cmm_allocator *allocator = NULL;
+	struct cmm_allocator *allocator;
 	struct cmm_attrs *pattrs;
 
 	DBC_REQUIRE(refs > 0);
@@ -366,21 +362,22 @@ int cmm_free_buf(struct cmm_object *hcmm_mgr, void *buf_pa,
 		status = -EFAULT;
 		return status;
 	}
-	/* get the allocator for this segment id */
+
 	allocator = get_allocator(cmm_mgr_obj, ul_seg_id);
-	if (allocator != NULL) {
-		mutex_lock(&cmm_mgr_obj->cmm_lock);
-		list_for_each_entry_safe(curr, tmp, &allocator->in_use_list,
-				link) {
-			if (curr->dw_pa == (u32) buf_pa) {
-				list_del(&curr->link);
-				add_to_free_list(allocator, curr);
-				status = 0;
-				break;
-			}
+	if (!allocator)
+		return status;
+
+	mutex_lock(&cmm_mgr_obj->cmm_lock);
+	list_for_each_entry_safe(curr, tmp, &allocator->in_use_list, link) {
+		if (curr->dw_pa == (u32) buf_pa) {
+			list_del(&curr->link);
+			add_to_free_list(allocator, curr);
+			status = 0;
+			break;
 		}
-		mutex_unlock(&cmm_mgr_obj->cmm_lock);
 	}
+	mutex_unlock(&cmm_mgr_obj->cmm_lock);
+
 	return status;
 }
 
@@ -438,31 +435,30 @@ int cmm_get_info(struct cmm_object *hcmm_mgr,
 	for (ul_seg = 1; ul_seg <= CMM_MAXGPPSEGS; ul_seg++) {
 		/* get the allocator object for this segment id */
 		altr = get_allocator(cmm_mgr_obj, ul_seg);
-		if (altr != NULL) {
-			cmm_info_obj->ul_num_gppsm_segs++;
-			cmm_info_obj->seg_info[ul_seg - 1].dw_seg_base_pa =
-			    altr->shm_base - altr->ul_dsp_size;
-			cmm_info_obj->seg_info[ul_seg - 1].ul_total_seg_size =
-			    altr->ul_dsp_size + altr->ul_sm_size;
-			cmm_info_obj->seg_info[ul_seg - 1].dw_gpp_base_pa =
-			    altr->shm_base;
-			cmm_info_obj->seg_info[ul_seg - 1].ul_gpp_size =
-			    altr->ul_sm_size;
-			cmm_info_obj->seg_info[ul_seg - 1].dw_dsp_base_va =
-			    altr->dw_dsp_base;
-			cmm_info_obj->seg_info[ul_seg - 1].ul_dsp_size =
-			    altr->ul_dsp_size;
-			cmm_info_obj->seg_info[ul_seg - 1].dw_seg_base_va =
-			    altr->dw_vm_base - altr->ul_dsp_size;
-			cmm_info_obj->seg_info[ul_seg - 1].ul_in_use_cnt = 0;
-			/* Count inUse blocks */
-			list_for_each_entry(curr, &altr->in_use_list, link) {
-				cmm_info_obj->ul_total_in_use_cnt++;
-				cmm_info_obj->seg_info[ul_seg -
-						       1].ul_in_use_cnt++;
-			}
+		if (!altr)
+			continue;
+		cmm_info_obj->ul_num_gppsm_segs++;
+		cmm_info_obj->seg_info[ul_seg - 1].dw_seg_base_pa =
+			altr->shm_base - altr->ul_dsp_size;
+		cmm_info_obj->seg_info[ul_seg - 1].ul_total_seg_size =
+			altr->ul_dsp_size + altr->ul_sm_size;
+		cmm_info_obj->seg_info[ul_seg - 1].dw_gpp_base_pa =
+			altr->shm_base;
+		cmm_info_obj->seg_info[ul_seg - 1].ul_gpp_size =
+			altr->ul_sm_size;
+		cmm_info_obj->seg_info[ul_seg - 1].dw_dsp_base_va =
+			altr->dw_dsp_base;
+		cmm_info_obj->seg_info[ul_seg - 1].ul_dsp_size =
+			altr->ul_dsp_size;
+		cmm_info_obj->seg_info[ul_seg - 1].dw_seg_base_va =
+			altr->dw_vm_base - altr->ul_dsp_size;
+		cmm_info_obj->seg_info[ul_seg - 1].ul_in_use_cnt = 0;
+
+		list_for_each_entry(curr, &altr->in_use_list, link) {
+			cmm_info_obj->ul_total_in_use_cnt++;
+			cmm_info_obj->seg_info[ul_seg - 1].ul_in_use_cnt++;
 		}
-	}			/* end for */
+	}
 	mutex_unlock(&cmm_mgr_obj->cmm_lock);
 	return status;
 }
@@ -508,23 +504,25 @@ int cmm_register_gppsm_seg(struct cmm_object *hcmm_mgr,
 	DBC_REQUIRE(dw_gpp_base_pa != 0);
 	DBC_REQUIRE(gpp_base_va != 0);
 	DBC_REQUIRE((c_factor <= CMM_ADDTODSPPA) &&
-		    (c_factor >= CMM_SUBFROMDSPPA));
+			(c_factor >= CMM_SUBFROMDSPPA));
+
 	dev_dbg(bridge, "%s: dw_gpp_base_pa %x ul_size %x dsp_addr_offset %x "
-		"dw_dsp_base %x ul_dsp_size %x gpp_base_va %x\n", __func__,
-		dw_gpp_base_pa, ul_size, dsp_addr_offset, dw_dsp_base,
-		ul_dsp_size, gpp_base_va);
-	if (!hcmm_mgr) {
-		status = -EFAULT;
-		return status;
-	}
+			"dw_dsp_base %x ul_dsp_size %x gpp_base_va %x\n",
+			__func__, dw_gpp_base_pa, ul_size, dsp_addr_offset,
+			dw_dsp_base, ul_dsp_size, gpp_base_va);
+
+	if (!hcmm_mgr)
+		return -EFAULT;
+
 	/* make sure we have room for another allocator */
 	mutex_lock(&cmm_mgr_obj->cmm_lock);
+
 	slot_seg = get_slot(cmm_mgr_obj);
 	if (slot_seg < 0) {
-		/* get a slot number */
 		status = -EPERM;
 		goto func_end;
 	}
+
 	/* Check if input ul_size is big enough to alloc at least one block */
 	if (ul_size < cmm_mgr_obj->ul_min_block_size) {
 		status = -EINVAL;
@@ -533,37 +531,35 @@ int cmm_register_gppsm_seg(struct cmm_object *hcmm_mgr,
 
 	/* create, zero, and tag an SM allocator object */
 	psma = kzalloc(sizeof(struct cmm_allocator), GFP_KERNEL);
-	if (psma != NULL) {
-		psma->hcmm_mgr = hcmm_mgr;	/* ref to parent */
-		psma->shm_base = dw_gpp_base_pa;	/* SM Base phys */
-		psma->ul_sm_size = ul_size;	/* SM segment size in bytes */
-		psma->dw_vm_base = gpp_base_va;
-		psma->dw_dsp_phys_addr_offset = dsp_addr_offset;
-		psma->c_factor = c_factor;
-		psma->dw_dsp_base = dw_dsp_base;
-		psma->ul_dsp_size = ul_dsp_size;
-		if (psma->dw_vm_base == 0) {
-			status = -EPERM;
-			goto func_end;
-		}
-		/* return the actual segment identifier */
-		*sgmt_id = (u32) slot_seg + 1;
-		/* create memory free list */
-		INIT_LIST_HEAD(&psma->free_list);
-
-		/* create memory in-use list */
-		INIT_LIST_HEAD(&psma->in_use_list);
-
-		/* Get a mem node for this hunk-o-memory */
-		new_node = get_node(cmm_mgr_obj, dw_gpp_base_pa,
-				    psma->dw_vm_base, ul_size);
-		/* Place node on the SM allocator's free list */
-		if (new_node) {
-			list_add_tail(&new_node->link, &psma->free_list);
-		} else {
-			status = -ENOMEM;
-			goto func_end;
-		}
+	if (!psma) {
+		status = -ENOMEM;
+		goto func_end;
+	}
+
+	psma->hcmm_mgr = hcmm_mgr;	/* ref to parent */
+	psma->shm_base = dw_gpp_base_pa;	/* SM Base phys */
+	psma->ul_sm_size = ul_size;	/* SM segment size in bytes */
+	psma->dw_vm_base = gpp_base_va;
+	psma->dw_dsp_phys_addr_offset = dsp_addr_offset;
+	psma->c_factor = c_factor;
+	psma->dw_dsp_base = dw_dsp_base;
+	psma->ul_dsp_size = ul_dsp_size;
+	if (psma->dw_vm_base == 0) {
+		status = -EPERM;
+		goto func_end;
+	}
+	/* return the actual segment identifier */
+	*sgmt_id = (u32) slot_seg + 1;
+
+	INIT_LIST_HEAD(&psma->free_list);
+	INIT_LIST_HEAD(&psma->in_use_list);
+
+	/* Get a mem node for this hunk-o-memory */
+	new_node = get_node(cmm_mgr_obj, dw_gpp_base_pa,
+			psma->dw_vm_base, ul_size);
+	/* Place node on the SM allocator's free list */
+	if (new_node) {
+		list_add_tail(&new_node->link, &psma->free_list);
 	} else {
 		status = -ENOMEM;
 		goto func_end;
@@ -572,12 +568,11 @@ int cmm_register_gppsm_seg(struct cmm_object *hcmm_mgr,
 	cmm_mgr_obj->pa_gppsm_seg_tab[slot_seg] = psma;
 
 func_end:
-	if (status && psma) {
-		/* Cleanup allocator */
+	/* Cleanup allocator */
+	if (status && psma)
 		un_register_gppsm_seg(psma);
-	}
-
 	mutex_unlock(&cmm_mgr_obj->cmm_lock);
+
 	return status;
 }
 
@@ -595,36 +590,36 @@ int cmm_un_register_gppsm_seg(struct cmm_object *hcmm_mgr,
 	u32 ul_id = ul_seg_id;
 
 	DBC_REQUIRE(ul_seg_id > 0);
-	if (hcmm_mgr) {
-		if (ul_seg_id == CMM_ALLSEGMENTS)
-			ul_id = 1;
-
-		if ((ul_id > 0) && (ul_id <= CMM_MAXGPPSEGS)) {
-			while (ul_id <= CMM_MAXGPPSEGS) {
-				mutex_lock(&cmm_mgr_obj->cmm_lock);
-				/* slot = seg_id-1 */
-				psma = cmm_mgr_obj->pa_gppsm_seg_tab[ul_id - 1];
-				if (psma != NULL) {
-					un_register_gppsm_seg(psma);
-					/* Set alctr ptr to NULL for future
-					 * reuse */
-					cmm_mgr_obj->pa_gppsm_seg_tab[ul_id -
-								      1] = NULL;
-				} else if (ul_seg_id != CMM_ALLSEGMENTS) {
-					status = -EPERM;
-				}
-				mutex_unlock(&cmm_mgr_obj->cmm_lock);
-				if (ul_seg_id != CMM_ALLSEGMENTS)
-					break;
-
-				ul_id++;
-			}	/* end while */
-		} else {
-			status = -EINVAL;
+	if (!hcmm_mgr)
+		return -EFAULT;
+
+	if (ul_seg_id == CMM_ALLSEGMENTS)
+		ul_id = 1;
+
+	if ((ul_id <= 0) || (ul_id > CMM_MAXGPPSEGS))
+		return -EINVAL;
+
+	/* FIXME: CMM_MAXGPPSEGS == 1. why use a while cycle? Seems to me like
+	 * the ul_seg_id is not needed here. It must be always 1
+	 */
+	while (ul_id <= CMM_MAXGPPSEGS) {
+		mutex_lock(&cmm_mgr_obj->cmm_lock);
+		/* slot = seg_id-1 */
+		psma = cmm_mgr_obj->pa_gppsm_seg_tab[ul_id - 1];
+		if (psma != NULL) {
+			un_register_gppsm_seg(psma);
+			/* Set alctr ptr to NULL for future
+			 * reuse */
+			cmm_mgr_obj->pa_gppsm_seg_tab[ul_id - 1] = NULL;
+		} else if (ul_seg_id != CMM_ALLSEGMENTS) {
+			status = -EPERM;
 		}
-	} else {
-		status = -EFAULT;
-	}
+		mutex_unlock(&cmm_mgr_obj->cmm_lock);
+		if (ul_seg_id != CMM_ALLSEGMENTS)
+			break;
+
+		ul_id++;
+	}	/* end while */
 	return status;
 }
 
@@ -690,26 +685,29 @@ static s32 get_slot(struct cmm_object *cmm_mgr_obj)
 static struct cmm_mnode *get_node(struct cmm_object *cmm_mgr_obj, u32 dw_pa,
 				  u32 dw_va, u32 ul_size)
 {
-	struct cmm_mnode *pnode = NULL;
+	struct cmm_mnode *pnode;
 
 	DBC_REQUIRE(cmm_mgr_obj != NULL);
 	DBC_REQUIRE(dw_pa != 0);
 	DBC_REQUIRE(dw_va != 0);
 	DBC_REQUIRE(ul_size != 0);
+
 	/* Check cmm mgr's node freelist */
 	if (list_empty(&cmm_mgr_obj->node_free_list)) {
 		pnode = kzalloc(sizeof(struct cmm_mnode), GFP_KERNEL);
+		if (!pnode)
+			return NULL;
 	} else {
 		/* surely a valid element */
 		pnode = list_first_entry(&cmm_mgr_obj->node_free_list,
 				struct cmm_mnode, link);
-		list_del(&pnode->link);
-	}
-	if (pnode) {
-		pnode->dw_pa = dw_pa;	/* Physical addr of start of block */
-		pnode->dw_va = dw_va;	/* Virtual   "            " */
-		pnode->ul_size = ul_size;	/* Size of block */
+		list_del_init(&pnode->link);
 	}
+
+	pnode->dw_pa = dw_pa;
+	pnode->dw_va = dw_va;
+	pnode->ul_size = ul_size;
+
 	return pnode;
 }
 
@@ -740,11 +738,10 @@ static struct cmm_mnode *get_free_block(struct cmm_allocator *allocator,
 		return NULL;
 
 	list_for_each_entry_safe(node, tmp, &allocator->free_list, link) {
-		if (usize <= (u32) node->ul_size) {
+		if (usize <= node->ul_size) {
 			list_del(&node->link);
 			return node;
 		}
-
 	}
 
 	return NULL;
@@ -756,56 +753,34 @@ static struct cmm_mnode *get_free_block(struct cmm_allocator *allocator,
  *      Coalesce node into the freelist in ascending size order.
  */
 static void add_to_free_list(struct cmm_allocator *allocator,
-			     struct cmm_mnode *pnode)
+			     struct cmm_mnode *node)
 {
-	struct cmm_mnode *node_prev = NULL;
-	struct cmm_mnode *node_next = NULL;
-	struct cmm_mnode *mnode_obj;
-	u32 dw_this_pa;
-	u32 dw_next_pa;
+	struct cmm_mnode *curr;
 
-	DBC_REQUIRE(pnode != NULL);
+	DBC_REQUIRE(node != NULL);
 	DBC_REQUIRE(allocator != NULL);
-	dw_this_pa = pnode->dw_pa;
-	dw_next_pa = NEXT_PA(pnode);
-	list_for_each_entry(mnode_obj, &allocator->free_list, link) {
-		if (dw_this_pa == NEXT_PA(mnode_obj)) {
-			/* found the block ahead of this one */
-			node_prev = mnode_obj;
-		} else if (dw_next_pa == mnode_obj->dw_pa) {
-			node_next = mnode_obj;
+
+	list_for_each_entry(curr, &allocator->free_list, link) {
+		if (NEXT_PA(curr) == node->dw_pa) {
+			curr->ul_size += node->ul_size;
+			delete_node(allocator->hcmm_mgr, node);
+			return;
+		}
+		if (curr->dw_pa == NEXT_PA(node)) {
+			curr->dw_pa = node->dw_pa;
+			curr->dw_va = node->dw_va;
+			curr->ul_size += node->ul_size;
+			delete_node(allocator->hcmm_mgr, node);
+			return;
 		}
-		if ((node_prev != NULL) && (node_next != NULL))
-			break;
-	}
-	if (node_prev != NULL) {
-		/* combine with previous block */
-		list_del(&node_prev->link);
-		/* grow node to hold both */
-		pnode->ul_size += node_prev->ul_size;
-		pnode->dw_pa = node_prev->dw_pa;
-		pnode->dw_va = node_prev->dw_va;
-		/* place node on mgr nodeFreeList */
-		delete_node(allocator->hcmm_mgr, node_prev);
-	}
-	if (node_next != NULL) {
-		/* combine with next block */
-		list_del(&node_next->link);
-		/* grow da node */
-		pnode->ul_size += node_next->ul_size;
-		/* place node on mgr nodeFreeList */
-		delete_node(allocator->hcmm_mgr, node_next);
 	}
-	/* Now, let's add to freelist in increasing size order */
-	list_for_each_entry(mnode_obj, &allocator->free_list, link) {
-		if (pnode->ul_size <= mnode_obj->ul_size) {
-			/* insert our node before the current traversed node  */
-			list_add_tail(&pnode->link, &mnode_obj->link);
+	list_for_each_entry(curr, &allocator->free_list, link) {
+		if (curr->ul_size >= node->ul_size) {
+			list_add_tail(&node->link, &curr->link);
 			return;
 		}
 	}
-	/* add our pnode to the end of the freelist */
-	list_add_tail(&pnode->link, &allocator->free_list);
+	list_add_tail(&node->link, &allocator->free_list);
 }
 
 /*
@@ -817,19 +792,10 @@ static void add_to_free_list(struct cmm_allocator *allocator,
 static struct cmm_allocator *get_allocator(struct cmm_object *cmm_mgr_obj,
 					   u32 ul_seg_id)
 {
-	struct cmm_allocator *allocator = NULL;
-
 	DBC_REQUIRE(cmm_mgr_obj != NULL);
 	DBC_REQUIRE((ul_seg_id > 0) && (ul_seg_id <= CMM_MAXGPPSEGS));
-	allocator = cmm_mgr_obj->pa_gppsm_seg_tab[ul_seg_id - 1];
-	if (allocator != NULL) {
-		/* make sure it's for real */
-		if (!allocator) {
-			allocator = NULL;
-			DBC_ASSERT(false);
-		}
-	}
-	return allocator;
+
+	return cmm_mgr_obj->pa_gppsm_seg_tab[ul_seg_id - 1];
 }
 
 /*
diff --git a/drivers/staging/tidspbridge/pmgr/dev.c b/drivers/staging/tidspbridge/pmgr/dev.c
index 99cef4d..060e962 100644
--- a/drivers/staging/tidspbridge/pmgr/dev.c
+++ b/drivers/staging/tidspbridge/pmgr/dev.c
@@ -76,7 +76,7 @@ struct dev_object {
 	struct ldr_module *module_obj;	/* Bridge Module handle. */
 	u32 word_size;		/* DSP word size: quick access. */
 	struct drv_object *hdrv_obj;	/* Driver Object */
-	struct list_head proc_list;	/* List of Processor attached to
+	struct list_head proc_list;	/* List of Processors attached to
 					 * this device */
 	struct node_mgr *hnode_mgr;
 };
@@ -734,16 +734,15 @@ bool dev_init(void)
  *  Purpose:
  *      Notify all clients of this device of a change in device status.
  */
-int dev_notify_clients(struct dev_object *hdev_obj, u32 ret)
+int dev_notify_clients(struct dev_object *dev_obj, u32 ret)
 {
-	struct dev_object *dev_obj = hdev_obj;
 	struct list_head *curr;
 
 	/* FIXME: this code needs struct proc_object to have a list_head
 	 * at the begining. If not, this can go horribly wrong.
 	 */
 	list_for_each(curr, &dev_obj->proc_list)
-		proc_notify_clients((void *)curr, (u32) ret);
+		proc_notify_clients((void *)curr, ret);
 
 	return 0;
 }
@@ -927,7 +926,6 @@ static int init_cod_mgr(struct dev_object *dev_obj)
 int dev_insert_proc_object(struct dev_object *hdev_obj,
 				  u32 proc_obj, bool *already_attached)
 {
-	int status = 0;
 	struct dev_object *dev_obj = (struct dev_object *)hdev_obj;
 
 	DBC_REQUIRE(refs > 0);
@@ -943,9 +941,7 @@ int dev_insert_proc_object(struct dev_object *hdev_obj,
 	 */
 	list_add_tail((struct list_head *)proc_obj, &dev_obj->proc_list);
 
-	DBC_ENSURE(!status && !list_empty(&dev_obj->proc_list));
-
-	return status;
+	return 0;
 }
 
 /*
@@ -988,14 +984,10 @@ int dev_remove_proc_object(struct dev_object *hdev_obj, u32 proc_obj)
 	return status;
 }
 
-int dev_get_dev_type(struct dev_object *device_obj, u8 *dev_type)
+int dev_get_dev_type(struct dev_object *dev_obj, u8 *dev_type)
 {
-	int status = 0;
-	struct dev_object *dev_obj = (struct dev_object *)device_obj;
-
 	*dev_type = dev_obj->dev_type;
-
-	return status;
+	return 0;
 }
 
 /*
-- 
1.7.2.3


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

* [PATCH v2 12/12] staging: tidspbridge: rmgr code cleanup
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
                   ` (10 preceding siblings ...)
  2010-11-05 15:13 ` [PATCH v2 11/12] staging: tidspbridge: pmgr " Ionut Nicu
@ 2010-11-05 15:13 ` Ionut Nicu
  2010-11-05 15:43 ` [PATCH v2 00/12] staging: tidspbridge: various cleanups Greg KH
  12 siblings, 0 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 15:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Omar Ramirez Luna
  Cc: Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	Sapiens Rene, linux-omap, Ionut Nicu

Reorganized some code in the rmgr module to increase
its readability. No functional changes were done.

Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
---
 drivers/staging/tidspbridge/rmgr/drv.c  |  171 +++++++++-----------
 drivers/staging/tidspbridge/rmgr/node.c |   82 +++++-----
 drivers/staging/tidspbridge/rmgr/rmm.c  |  267 +++++++++++++------------------
 3 files changed, 229 insertions(+), 291 deletions(-)

diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c
index 18fae55..4eff419 100644
--- a/drivers/staging/tidspbridge/rmgr/drv.c
+++ b/drivers/staging/tidspbridge/rmgr/drv.c
@@ -293,40 +293,28 @@ int drv_proc_update_strm_res(u32 num_bufs, void *strm_resources)
  */
 int drv_create(struct drv_object **drv_obj)
 {
-	int status = 0;
 	struct drv_object *pdrv_object = NULL;
 	struct drv_data *drv_datap = dev_get_drvdata(bridge);
 
 	DBC_REQUIRE(drv_obj != NULL);
 	DBC_REQUIRE(refs > 0);
 
+	if (!drv_datap)
+		return -EFAULT;
+
 	pdrv_object = kzalloc(sizeof(struct drv_object), GFP_KERNEL);
-	if (pdrv_object) {
-		/* Create and Initialize List of device objects */
-		INIT_LIST_HEAD(&pdrv_object->dev_list);
-		INIT_LIST_HEAD(&pdrv_object->dev_node_string);
-	} else {
-		status = -ENOMEM;
-	}
-	/* Store the DRV Object in the driver data */
-	if (!status) {
-		if (drv_datap) {
-			drv_datap->drv_object = (void *)pdrv_object;
-		} else {
-			status = -EPERM;
-			pr_err("%s: Failed to store DRV object\n", __func__);
-		}
-	}
+	if (!pdrv_object)
+		return -ENOMEM;
 
-	if (!status) {
-		*drv_obj = pdrv_object;
-	} else {
-		/* Free the DRV Object */
-		kfree(pdrv_object);
-	}
+	/* Create and Initialize List of device objects */
+	INIT_LIST_HEAD(&pdrv_object->dev_list);
+	INIT_LIST_HEAD(&pdrv_object->dev_node_string);
 
-	DBC_ENSURE(status || pdrv_object);
-	return status;
+	/* Store the DRV Object in the driver data */
+	drv_datap->drv_object = (void *)pdrv_object;
+	*drv_obj = pdrv_object;
+
+	return 0;
 }
 
 /*
@@ -413,19 +401,19 @@ int drv_get_dev_object(u32 index, struct drv_object *hdrv_obj,
  */
 u32 drv_get_first_dev_object(void)
 {
-	u32 dw_dev_object = 0;
 	struct drv_object *pdrv_obj;
 	struct drv_data *drv_datap = dev_get_drvdata(bridge);
 
-	if (drv_datap && drv_datap->drv_object) {
-		pdrv_obj = drv_datap->drv_object;
-		if (!list_empty(&pdrv_obj->dev_list))
-			dw_dev_object = (u32) pdrv_obj->dev_list.next;
-	} else {
+	if (!drv_datap || !drv_datap->drv_object) {
 		pr_err("%s: Failed to retrieve the object handle\n", __func__);
+		return 0;
 	}
 
-	return dw_dev_object;
+	pdrv_obj = drv_datap->drv_object;
+	if (list_empty(&pdrv_obj->dev_list))
+		return 0;
+
+	return (u32) pdrv_obj->dev_list.next;
 }
 
 /*
@@ -436,21 +424,19 @@ u32 drv_get_first_dev_object(void)
  */
 u32 drv_get_first_dev_extension(void)
 {
-	u32 dw_dev_extension = 0;
 	struct drv_object *pdrv_obj;
 	struct drv_data *drv_datap = dev_get_drvdata(bridge);
 
-	if (drv_datap && drv_datap->drv_object) {
-		pdrv_obj = drv_datap->drv_object;
-		if (!list_empty(&pdrv_obj->dev_node_string)) {
-			dw_dev_extension =
-			    (u32) pdrv_obj->dev_node_string.next;
-		}
-	} else {
+	if (!drv_datap || !drv_datap->drv_object) {
 		pr_err("%s: Failed to retrieve the object handle\n", __func__);
+		return 0;
 	}
 
-	return dw_dev_extension;
+	pdrv_obj = drv_datap->drv_object;
+	if (list_empty(&pdrv_obj->dev_node_string))
+		return 0;
+
+	return (u32) pdrv_obj->dev_node_string.next;
 }
 
 /*
@@ -462,26 +448,27 @@ u32 drv_get_first_dev_extension(void)
  */
 u32 drv_get_next_dev_object(u32 hdev_obj)
 {
-	u32 dw_next_dev_object = 0;
 	struct drv_object *pdrv_obj;
 	struct drv_data *drv_datap = dev_get_drvdata(bridge);
 	struct list_head *curr;
 
 	DBC_REQUIRE(hdev_obj != 0);
 
-	if (drv_datap && drv_datap->drv_object) {
-		pdrv_obj = drv_datap->drv_object;
-		if (!list_empty(&pdrv_obj->dev_list)) {
-			curr = (struct list_head *)hdev_obj;
-			if (curr->next == &pdrv_obj->dev_list)
-				return 0;
-			dw_next_dev_object = (u32) curr->next;
-		}
-	} else {
+	if (!drv_datap || !drv_datap->drv_object) {
 		pr_err("%s: Failed to retrieve the object handle\n", __func__);
+		return 0;
 	}
 
-	return dw_next_dev_object;
+	pdrv_obj = drv_datap->drv_object;
+	if (list_empty(&pdrv_obj->dev_list))
+		return 0;
+
+	curr = (struct list_head *)hdev_obj;
+
+	if (curr->next == &pdrv_obj->dev_list)
+		return 0;
+
+	return (u32)curr->next;
 }
 
 /*
@@ -494,26 +481,27 @@ u32 drv_get_next_dev_object(u32 hdev_obj)
  */
 u32 drv_get_next_dev_extension(u32 dev_extension)
 {
-	u32 dw_dev_extension = 0;
 	struct drv_object *pdrv_obj;
 	struct drv_data *drv_datap = dev_get_drvdata(bridge);
 	struct list_head *curr;
 
 	DBC_REQUIRE(dev_extension != 0);
 
-	if (drv_datap && drv_datap->drv_object) {
-		pdrv_obj = drv_datap->drv_object;
-		if (!list_empty(&pdrv_obj->dev_node_string)) {
-			curr = (struct list_head *)dev_extension;
-			if (curr->next == &pdrv_obj->dev_node_string)
-				return 0;
-			dw_dev_extension = (u32) curr->next;
-		}
-	} else {
+	if (!drv_datap || !drv_datap->drv_object) {
 		pr_err("%s: Failed to retrieve the object handle\n", __func__);
+		return 0;
 	}
 
-	return dw_dev_extension;
+	pdrv_obj = drv_datap->drv_object;
+	if (list_empty(&pdrv_obj->dev_node_string))
+		return 0;
+
+	curr = (struct list_head *)dev_extension;
+
+	if (curr->next == &pdrv_obj->dev_node_string)
+		return 0;
+
+	return (u32) curr->next;
 }
 
 /*
@@ -601,40 +589,28 @@ int drv_request_resources(u32 dw_context, u32 *dev_node_strg)
 	DBC_REQUIRE(dw_context != 0);
 	DBC_REQUIRE(dev_node_strg != NULL);
 
-	/*
-	 *  Allocate memory to hold the string. This will live untill
-	 *  it is freed in the Release resources. Update the driver object
-	 *  list.
-	 */
-
 	if (!drv_datap || !drv_datap->drv_object)
-		status = -ENODATA;
-	else
-		pdrv_object = drv_datap->drv_object;
-
-	if (!status) {
-		pszdev_node = kzalloc(sizeof(struct drv_ext), GFP_KERNEL);
-		if (pszdev_node) {
-			strncpy(pszdev_node->sz_string,
-				(char *)dw_context, MAXREGPATHLENGTH - 1);
-			pszdev_node->sz_string[MAXREGPATHLENGTH - 1] = '\0';
-			/* Update the Driver Object List */
-			*dev_node_strg = (u32) pszdev_node->sz_string;
-			list_add_tail(&pszdev_node->link,
-					&pdrv_object->dev_node_string);
-		} else {
-			status = -ENOMEM;
-			*dev_node_strg = 0;
-		}
-	} else {
-		dev_dbg(bridge, "%s: Failed to get Driver Object from Registry",
-			__func__);
-		*dev_node_strg = 0;
-	}
+		return -ENODATA;
+
+	pdrv_object = drv_datap->drv_object;
+	*dev_node_strg = 0;
+
+	pszdev_node = kzalloc(sizeof(struct drv_ext), GFP_KERNEL);
+	if (!pszdev_node)
+		return -ENOMEM;
+
+	strncpy(pszdev_node->sz_string, (char *)dw_context,
+			MAXREGPATHLENGTH - 1);
+	pszdev_node->sz_string[MAXREGPATHLENGTH - 1] = '\0';
+	*dev_node_strg = (u32) pszdev_node->sz_string;
+
+	/* Update the Driver Object List */
+	list_add_tail((struct list_head *)pszdev_node,
+			&pdrv_object->dev_node_string);
 
 	DBC_ENSURE((!status && dev_node_strg != NULL &&
-		    !list_empty(&pdrv_object->dev_node_string)) ||
-		   (status && *dev_node_strg == 0));
+				!list_empty(&pdrv_object->dev_node_string)) ||
+			(status && *dev_node_strg == 0));
 
 	return status;
 }
@@ -646,7 +622,6 @@ int drv_request_resources(u32 dw_context, u32 *dev_node_strg)
  */
 int drv_release_resources(u32 dw_context, struct drv_object *hdrv_obj)
 {
-	int status = 0;
 	struct drv_ext *pszdev_node;
 
 	/*
@@ -659,12 +634,12 @@ int drv_release_resources(u32 dw_context, struct drv_object *hdrv_obj)
 		if ((u32) pszdev_node == dw_context) {
 			/* Found it */
 			/* Delete from the Driver object list */
-			list_del(&pszdev_node->link);
-			kfree(pszdev_node);
+			list_del((struct list_head *)pszdev_node);
+			kfree((void *)pszdev_node);
 			break;
 		}
 	}
-	return status;
+	return 0;
 }
 
 /*
diff --git a/drivers/staging/tidspbridge/rmgr/node.c b/drivers/staging/tidspbridge/rmgr/node.c
index 34ae0ad..23775fd 100644
--- a/drivers/staging/tidspbridge/rmgr/node.c
+++ b/drivers/staging/tidspbridge/rmgr/node.c
@@ -1554,27 +1554,26 @@ int node_enum_nodes(struct node_mgr *hnode_mgr, void **node_tab,
 	DBC_REQUIRE(pu_num_nodes != NULL);
 	DBC_REQUIRE(pu_allocated != NULL);
 
-	if (!hnode_mgr) {
-		status = -EFAULT;
-		goto func_end;
-	}
-	/* Enter critical section */
+	if (!hnode_mgr)
+		return -EFAULT;
+
 	mutex_lock(&hnode_mgr->node_mgr_lock);
 
 	if (hnode_mgr->num_nodes > node_tab_size) {
 		*pu_allocated = hnode_mgr->num_nodes;
 		*pu_num_nodes = 0;
 		status = -EINVAL;
-	} else {
-		i = 0;
-		list_for_each_entry(hnode, &hnode_mgr->node_list, list_elem)
-			node_tab[i++] = hnode;
-		*pu_allocated = *pu_num_nodes = hnode_mgr->num_nodes;
+		goto out_unlock;
 	}
-	/* end of sync_enter_cs */
-	/* Exit critical section */
+
+	i = 0;
+	list_for_each_entry(hnode, &hnode_mgr->node_list, list_elem) {
+		DBC_ASSERT(hnode);
+		node_tab[i++] = hnode;
+	}
+	*pu_allocated = *pu_num_nodes = hnode_mgr->num_nodes;
+out_unlock:
 	mutex_unlock(&hnode_mgr->node_mgr_lock);
-func_end:
 	return status;
 }
 
@@ -1657,8 +1656,7 @@ int node_get_attr(struct node_object *hnode,
 	mutex_lock(&hnode_mgr->node_mgr_lock);
 	pattr->cb_struct = sizeof(struct dsp_nodeattr);
 	/* dsp_nodeattrin */
-	pattr->in_node_attr_in.cb_struct =
-		sizeof(struct dsp_nodeattrin);
+	pattr->in_node_attr_in.cb_struct = sizeof(struct dsp_nodeattrin);
 	pattr->in_node_attr_in.prio = hnode->prio;
 	pattr->in_node_attr_in.utimeout = hnode->utimeout;
 	pattr->in_node_attr_in.heap_size =
@@ -2540,38 +2538,40 @@ static void delete_node_mgr(struct node_mgr *hnode_mgr)
 {
 	struct node_object *hnode, *tmp;
 
-	if (hnode_mgr) {
-		/* Free resources */
-		if (hnode_mgr->hdcd_mgr)
-			dcd_destroy_manager(hnode_mgr->hdcd_mgr);
+	if (!hnode_mgr)
+		return;
 
-		/* Remove any elements remaining in lists */
-		list_for_each_entry_safe(hnode, tmp, &hnode_mgr->node_list,
-				list_elem) {
-			list_del(&hnode->list_elem);
-			delete_node(hnode, NULL);
-		}
-		mutex_destroy(&hnode_mgr->node_mgr_lock);
-		if (hnode_mgr->ntfy_obj) {
-			ntfy_delete(hnode_mgr->ntfy_obj);
-			kfree(hnode_mgr->ntfy_obj);
-		}
+	/* Free resources */
+	if (hnode_mgr->hdcd_mgr)
+		dcd_destroy_manager(hnode_mgr->hdcd_mgr);
 
-		if (hnode_mgr->disp_obj)
-			disp_delete(hnode_mgr->disp_obj);
+	/* Remove any elements remaining in lists */
+	list_for_each_entry_safe(hnode, tmp, &hnode_mgr->node_list, list_elem) {
+		list_del(&hnode->list_elem);
+		delete_node(hnode, NULL);
+	}
 
-		if (hnode_mgr->strm_mgr_obj)
-			strm_delete(hnode_mgr->strm_mgr_obj);
+	mutex_destroy(&hnode_mgr->node_mgr_lock);
 
-		/* Delete the loader */
-		if (hnode_mgr->nldr_obj)
-			hnode_mgr->nldr_fxns.pfn_delete(hnode_mgr->nldr_obj);
+	if (hnode_mgr->ntfy_obj) {
+		ntfy_delete(hnode_mgr->ntfy_obj);
+		kfree(hnode_mgr->ntfy_obj);
+	}
 
-		if (hnode_mgr->loader_init)
-			hnode_mgr->nldr_fxns.pfn_exit();
+	if (hnode_mgr->disp_obj)
+		disp_delete(hnode_mgr->disp_obj);
 
-		kfree(hnode_mgr);
-	}
+	if (hnode_mgr->strm_mgr_obj)
+		strm_delete(hnode_mgr->strm_mgr_obj);
+
+	/* Delete the loader */
+	if (hnode_mgr->nldr_obj)
+		hnode_mgr->nldr_fxns.pfn_delete(hnode_mgr->nldr_obj);
+
+	if (hnode_mgr->loader_init)
+		hnode_mgr->nldr_fxns.pfn_exit();
+
+	kfree(hnode_mgr);
 }
 
 /*
diff --git a/drivers/staging/tidspbridge/rmgr/rmm.c b/drivers/staging/tidspbridge/rmgr/rmm.c
index 93db337..9d673f5 100644
--- a/drivers/staging/tidspbridge/rmgr/rmm.c
+++ b/drivers/staging/tidspbridge/rmgr/rmm.c
@@ -96,10 +96,9 @@ static bool free_block(struct rmm_target_obj *target, u32 segid, u32 addr,
 int rmm_alloc(struct rmm_target_obj *target, u32 segid, u32 size,
 		     u32 align, u32 *dsp_address, bool reserve)
 {
-	struct rmm_ovly_sect *sect, *prev_sect = NULL;
+	struct rmm_ovly_sect *sect, *prev = NULL;
 	struct rmm_ovly_sect *new_sect;
 	u32 addr;
-	int status = 0;
 
 	DBC_REQUIRE(target);
 	DBC_REQUIRE(dsp_address != NULL);
@@ -108,54 +107,38 @@ int rmm_alloc(struct rmm_target_obj *target, u32 segid, u32 size,
 	DBC_REQUIRE(refs > 0);
 
 	if (!reserve) {
-		if (!alloc_block(target, segid, size, align, dsp_address)) {
-			status = -ENOMEM;
-		} else {
-			/* Increment the number of allocated blocks in this
-			 * segment */
-			target->seg_tab[segid].number++;
-		}
-		goto func_end;
+		if (!alloc_block(target, segid, size, align, dsp_address))
+			return -ENOMEM;
+		/* Increment the number of allocated blocks in this segment */
+		target->seg_tab[segid].number++;
+		return 0;
 	}
+
+	new_sect = kzalloc(sizeof(struct rmm_ovly_sect), GFP_KERNEL);
+	if (!new_sect)
+		return -ENOMEM;
+
+	addr = *dsp_address;
+	new_sect->addr = addr;
+	new_sect->size = size;
+	new_sect->page = segid;
+
 	/* An overlay section - See if block is already in use. If not,
 	 * insert into the list in ascending address size. */
-	addr = *dsp_address;
-	/*  Find place to insert new list element. List is sorted from
-	 *  smallest to largest address. */
 	list_for_each_entry(sect, &target->ovly_list, list_elem) {
 		if (addr <= sect->addr) {
-			/* Check for overlap with sect */
-			if ((addr + size > sect->addr) || (prev_sect &&
-							   (prev_sect->addr +
-							    prev_sect->size >
-							    addr))) {
-				status = -ENXIO;
+			if (prev && (prev->addr + prev->size >  addr)) {
+				kfree(new_sect);
+				return -ENXIO;
 			}
-			break;
-		}
-		prev_sect = sect;
-	}
-	if (!status) {
-		/* No overlap - allocate list element for new section. */
-		new_sect = kzalloc(sizeof(struct rmm_ovly_sect), GFP_KERNEL);
-		if (new_sect == NULL) {
-			status = -ENOMEM;
-		} else {
-			new_sect->addr = addr;
-			new_sect->size = size;
-			new_sect->page = segid;
-			if (sect == NULL)
-				/* Put new section at the end of the list */
-				list_add_tail(&new_sect->list_elem,
-						&target->ovly_list);
-			else
-				/* Put new section just before sect */
-				list_add_tail(&new_sect->list_elem,
-						&sect->list_elem);
+			list_add_tail(&new_sect->list_elem, &sect->list_elem);
+			return 0;
 		}
+		prev = sect;
 	}
-func_end:
-	return status;
+	list_add_tail(&new_sect->list_elem, &target->ovly_list);
+
+	return 0;
 }
 
 /*
@@ -173,71 +156,57 @@ int rmm_create(struct rmm_target_obj **target_obj,
 	DBC_REQUIRE(target_obj != NULL);
 	DBC_REQUIRE(num_segs == 0 || seg_tab != NULL);
 
+	if (num_segs <= 0)
+		return -EINVAL;
+
 	/* Allocate DBL target object */
 	target = kzalloc(sizeof(struct rmm_target_obj), GFP_KERNEL);
-
-	if (target == NULL)
-		status = -ENOMEM;
-
-	if (status)
-		goto func_cont;
+	if (!target)
+		return -ENOMEM;
 
 	target->num_segs = num_segs;
-	if (!(num_segs > 0))
-		goto func_cont;
-
+	INIT_LIST_HEAD(&target->ovly_list);
 	/* Allocate the memory for freelist from host's memory */
-	target->free_list = kzalloc(num_segs * sizeof(struct rmm_header *),
-							GFP_KERNEL);
-	if (target->free_list == NULL) {
+	target->free_list = kzalloc(num_segs *
+			sizeof(struct rmm_header *), GFP_KERNEL);
+	if (!target->free_list) {
 		status = -ENOMEM;
-	} else {
-		/* Allocate headers for each element on the free list */
-		for (i = 0; i < (s32) num_segs; i++) {
-			target->free_list[i] =
-				kzalloc(sizeof(struct rmm_header), GFP_KERNEL);
-			if (target->free_list[i] == NULL) {
-				status = -ENOMEM;
-				break;
-			}
-		}
-		/* Allocate memory for initial segment table */
-		target->seg_tab = kzalloc(num_segs * sizeof(struct rmm_segment),
-								GFP_KERNEL);
-		if (target->seg_tab == NULL) {
+		goto out_err;
+	}
+	/* Allocate headers for each element on the free list */
+	for (i = 0; i < num_segs; i++) {
+		target->free_list[i] =
+			kzalloc(sizeof(struct rmm_header), GFP_KERNEL);
+		if (!target->free_list[i]) {
 			status = -ENOMEM;
-		} else {
-			/* Initialize segment table and free list */
-			sptr = target->seg_tab;
-			for (i = 0, tmp = seg_tab; num_segs > 0;
-			     num_segs--, i++) {
-				*sptr = *tmp;
-				hptr = target->free_list[i];
-				hptr->addr = tmp->base;
-				hptr->size = tmp->length;
-				hptr->next = NULL;
-				tmp++;
-				sptr++;
-			}
+			goto out_err;
 		}
 	}
-func_cont:
-	/* Initialize overlay memory list */
-	if (!status)
-		INIT_LIST_HEAD(&target->ovly_list);
-
-	if (!status) {
-		*target_obj = target;
-	} else {
-		*target_obj = NULL;
-		if (target)
-			rmm_delete(target);
-
+	/* Allocate memory for initial segment table */
+	target->seg_tab = kzalloc(num_segs * sizeof(struct rmm_segment),
+			GFP_KERNEL);
+	if (!target->seg_tab) {
+		status = -ENOMEM;
+		goto out_err;
+	}
+	/* Initialize segment table and free list */
+	sptr = target->seg_tab;
+	for (i = 0, tmp = seg_tab; num_segs > 0; num_segs--, i++) {
+		*sptr = *tmp;
+		hptr = target->free_list[i];
+		hptr->addr = tmp->base;
+		hptr->size = tmp->length;
+		hptr->next = NULL;
+		tmp++;
+		sptr++;
 	}
 
-	DBC_ENSURE((!status && *target_obj)
-		   || (status && *target_obj == NULL));
+	*target_obj = target;
 
+	return 0;
+out_err:
+	*target_obj = NULL;
+	rmm_delete(target);
 	return status;
 }
 
@@ -298,14 +267,12 @@ bool rmm_free(struct rmm_target_obj *target, u32 segid, u32 dsp_addr, u32 size,
 	bool ret = false;
 
 	DBC_REQUIRE(target);
-
 	DBC_REQUIRE(reserved || segid < target->num_segs);
 	DBC_REQUIRE(reserved || (dsp_addr >= target->seg_tab[segid].base &&
-				 (dsp_addr + size) <= (target->seg_tab[segid].
-						   base +
-						   target->seg_tab[segid].
-						   length)));
-
+				(dsp_addr + size) <= (target->seg_tab[segid].
+					base +
+					target->seg_tab[segid].
+					length)));
 	/*
 	 *  Free or unreserve memory.
 	 */
@@ -313,21 +280,20 @@ bool rmm_free(struct rmm_target_obj *target, u32 segid, u32 dsp_addr, u32 size,
 		ret = free_block(target, segid, dsp_addr, size);
 		if (ret)
 			target->seg_tab[segid].number--;
+		return ret;
+	}
 
-	} else {
-		/* Unreserve memory */
-		list_for_each_entry_safe(sect, tmp, &target->ovly_list,
-				list_elem) {
-			if (dsp_addr == sect->addr) {
-				DBC_ASSERT(size == sect->size);
-				/* Remove from list */
-				list_del(&sect->list_elem);
-				kfree(sect);
-				ret = true;
-				break;
-			}
+	/* Unreserve memory */
+	list_for_each_entry_safe(sect, tmp, &target->ovly_list, list_elem) {
+		if (sect->addr == dsp_addr) {
+			DBC_ASSERT(size == sect->size);
+			/* Remove from list */
+			list_del(&sect->list_elem);
+			kfree(sect);
+			break;
 		}
 	}
+
 	return ret;
 }
 
@@ -463,51 +429,48 @@ static bool free_block(struct rmm_target_obj *target, u32 segid, u32 addr,
 	struct rmm_header *head;
 	struct rmm_header *thead;
 	struct rmm_header *rhead;
-	bool ret = true;
 
 	/* Create a memory header to hold the newly free'd block. */
 	rhead = kzalloc(sizeof(struct rmm_header), GFP_KERNEL);
-	if (rhead == NULL) {
-		ret = false;
-	} else {
-		/* search down the free list to find the right place for addr */
-		head = target->free_list[segid];
+	if (!rhead)
+		return false;
 
-		if (addr >= head->addr) {
-			while (head->next != NULL && addr > head->next->addr)
-				head = head->next;
-
-			thead = head->next;
-
-			head->next = rhead;
-			rhead->next = thead;
-			rhead->addr = addr;
-			rhead->size = size;
-		} else {
-			*rhead = *head;
-			head->next = rhead;
-			head->addr = addr;
-			head->size = size;
-			thead = rhead->next;
-		}
+	/* search down the free list to find the right place for addr */
+	head = target->free_list[segid];
 
-		/* join with upper block, if possible */
-		if (thead != NULL && (rhead->addr + rhead->size) ==
-		    thead->addr) {
-			head->next = rhead->next;
-			thead->size = size + thead->size;
-			thead->addr = addr;
-			kfree(rhead);
-			rhead = thead;
-		}
+	if (addr >= head->addr) {
+		while (head->next != NULL && addr > head->next->addr)
+			head = head->next;
 
-		/* join with the lower block, if possible */
-		if ((head->addr + head->size) == rhead->addr) {
-			head->next = rhead->next;
-			head->size = head->size + rhead->size;
-			kfree(rhead);
-		}
+		thead = head->next;
+		head->next = rhead;
+		rhead->next = thead;
+		rhead->addr = addr;
+		rhead->size = size;
+	} else {
+		*rhead = *head;
+		head->next = rhead;
+		head->addr = addr;
+		head->size = size;
+		thead = rhead->next;
 	}
 
-	return ret;
+	/* join with upper block, if possible */
+	if (thead != NULL && (rhead->addr + rhead->size) ==
+			thead->addr) {
+		head->next = rhead->next;
+		thead->size = size + thead->size;
+		thead->addr = addr;
+		kfree(rhead);
+		rhead = thead;
+	}
+
+	/* join with the lower block, if possible */
+	if ((head->addr + head->size) == rhead->addr) {
+		head->next = rhead->next;
+		head->size = head->size + rhead->size;
+		kfree(rhead);
+	}
+
+	return true;
 }
-- 
1.7.2.3


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

* Re: [PATCH v2 00/12] staging: tidspbridge: various cleanups
  2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
                   ` (11 preceding siblings ...)
  2010-11-05 15:13 ` [PATCH v2 12/12] staging: tidspbridge: rmgr " Ionut Nicu
@ 2010-11-05 15:43 ` Greg KH
  2010-11-05 16:02   ` Ionut Nicu
  12 siblings, 1 reply; 31+ messages in thread
From: Greg KH @ 2010-11-05 15:43 UTC (permalink / raw)
  To: Ionut Nicu
  Cc: Omar Ramirez Luna, Fernando Guzman Lugo, Felipe Contreras,
	Andy Shevchenko, Sapiens Rene, linux-omap, Ionut Nicu

On Fri, Nov 05, 2010 at 05:13:04PM +0200, Ionut Nicu wrote:
> This set of patches replaces some of the redundant components of
> the tidspbridge driver, such as:
> 
> * wrapper functions for kmalloc/kfree
> * custom bitmap implementation
> * custom linked list implementation (list_head wrapper)
> 
> with the standard linux kernel interfaces.
> 
> The patches also do some code reorganization for increasing readability.
> Most of the changes reduce the code indentation level and simplify the code.
> No functional changes were done.
> 
> There are many places in this driver that need this kind of cleanup, but
> these patches only fix the functions that were touched while converting
> the code to use linux bitmap and list_head.

This is for .38, right?

thanks,

greg k-h

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

* Re: [PATCH v2 00/12] staging: tidspbridge: various cleanups
  2010-11-05 15:43 ` [PATCH v2 00/12] staging: tidspbridge: various cleanups Greg KH
@ 2010-11-05 16:02   ` Ionut Nicu
  0 siblings, 0 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-05 16:02 UTC (permalink / raw)
  To: Greg KH
  Cc: Ionut Nicu, Omar Ramirez Luna, Fernando Guzman Lugo,
	Felipe Contreras, Andy Shevchenko, Sapiens Rene, linux-omap

Hi,

On Fri, 2010-11-05 at 08:43 -0700, Greg KH wrote:
> On Fri, Nov 05, 2010 at 05:13:04PM +0200, Ionut Nicu wrote:
> > This set of patches replaces some of the redundant components of
> > the tidspbridge driver, such as:
> > 
> > * wrapper functions for kmalloc/kfree
> > * custom bitmap implementation
> > * custom linked list implementation (list_head wrapper)
> > 
> > with the standard linux kernel interfaces.
> > 
> > The patches also do some code reorganization for increasing readability.
> > Most of the changes reduce the code indentation level and simplify the code.
> > No functional changes were done.
> > 
> > There are many places in this driver that need this kind of cleanup, but
> > these patches only fix the functions that were touched while converting
> > the code to use linux bitmap and list_head.
> 
> This is for .38, right?
> 

Yes, the diff stat is quite big, so if they pass code review, they
should be considered for .38.

Thanks,
Ionut



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

* Re: [PATCH v2 06/12] staging: tidspbridge: convert core to list_head
  2010-11-05 15:13 ` [PATCH v2 06/12] staging: tidspbridge: convert core to list_head Ionut Nicu
@ 2010-11-05 21:07   ` Sapiens, Rene
  2010-11-06 17:21     ` Ionut Nicu
  2010-11-05 22:12   ` Sapiens, Rene
  1 sibling, 1 reply; 31+ messages in thread
From: Sapiens, Rene @ 2010-11-05 21:07 UTC (permalink / raw)
  To: Ionut Nicu
  Cc: Greg Kroah-Hartman, Omar Ramirez Luna, Fernando Guzman Lugo,
	Felipe Contreras, Andy Shevchenko, linux-omap, Ionut Nicu

Hi Ionut,

On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
> Convert the core module of the tidspbridge driver
> to use struct list_head instead of struct lst_list.
>

<snip>

>        if (!status) {
>                /* Get a free chirp: */
> -               chnl_packet_obj =
> -                   (struct chnl_irp *)lst_get_head(pchnl->free_packets_list);
> -               if (chnl_packet_obj == NULL)
> +               if (!list_empty(&pchnl->free_packets_list)) {
> +                       chnl_packet_obj = list_first_entry(
> +                                       &pchnl->free_packets_list,
> +                                       struct chnl_irp, link);
> +                       list_del(&chnl_packet_obj->link);
> +               } else
>                        status = -EIO;

What do you think if we close the braces, since the first conditional
has more than one statement?

<snip>

> @@ -286,18 +286,16 @@ int bridge_chnl_cancel_io(struct chnl_object *chnl_obj)
>                }
>        }
>        /* Move all IOR's to IOC queue: */
> -       while (!LST_IS_EMPTY(pchnl->pio_requests)) {
> -               chnl_packet_obj =
> -                   (struct chnl_irp *)lst_get_head(pchnl->pio_requests);
> -               if (chnl_packet_obj) {
> -                       chnl_packet_obj->byte_size = 0;
> -                       chnl_packet_obj->status |= CHNL_IOCSTATCANCEL;
> -                       lst_put_tail(pchnl->pio_completions,
> -                                    (struct list_head *)chnl_packet_obj);
> -                       pchnl->cio_cs++;
> -                       pchnl->cio_reqs--;
> -                       DBC_ASSERT(pchnl->cio_reqs >= 0);
> -               }
> +       while (!list_empty(&pchnl->pio_requests)) {
> +               chnl_packet_obj = list_first_entry(&pchnl->pio_requests,
> +                               struct chnl_irp, link);
> +               list_del(&chnl_packet_obj->link);
> +               chnl_packet_obj->byte_size = 0;
> +               chnl_packet_obj->status |= CHNL_IOCSTATCANCEL;
> +               list_add_tail(&chnl_packet_obj->link, &pchnl->pio_completions);
> +               pchnl->cio_cs++;
> +               pchnl->cio_reqs--;
> +               DBC_ASSERT(pchnl->cio_reqs >= 0);

Why don't we use list_for_each_entry_safe() instead?

>        }
>  func_cont:
>        spin_unlock_bh(&chnl_mgr_obj->chnl_mgr_lock);

<snip>

> @@ -818,9 +804,19 @@ int bridge_chnl_open(struct chnl_object **chnl,
>        /* Protect queues from io_dpc: */
>        pchnl->dw_state = CHNL_STATECANCEL;
>        /* Allocate initial IOR and IOC queues: */
> -       pchnl->free_packets_list = create_chirp_list(pattrs->uio_reqs);
> -       pchnl->pio_requests = create_chirp_list(0);
> -       pchnl->pio_completions = create_chirp_list(0);
> +       status = create_chirp_list(&pchnl->free_packets_list,
> +                       pattrs->uio_reqs);
> +       if (status)
> +               goto func_end;
> +
> +       status = create_chirp_list(&pchnl->pio_requests, 0);
> +       if (status)
> +               goto func_end;
> +
> +       status = create_chirp_list(&pchnl->pio_completions, 0);
> +       if (status)
> +               goto func_end;
> +

With these goto you are not freeing the memory allocated for pchnl, please free
it at func_end.

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

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

* Re: [PATCH v2 06/12] staging: tidspbridge: convert core to list_head
  2010-11-05 15:13 ` [PATCH v2 06/12] staging: tidspbridge: convert core to list_head Ionut Nicu
  2010-11-05 21:07   ` Sapiens, Rene
@ 2010-11-05 22:12   ` Sapiens, Rene
  2010-11-06 17:31     ` Ionut Nicu
  1 sibling, 1 reply; 31+ messages in thread
From: Sapiens, Rene @ 2010-11-05 22:12 UTC (permalink / raw)
  To: Ionut Nicu
  Cc: Greg Kroah-Hartman, Omar Ramirez Luna, Fernando Guzman Lugo,
	Felipe Contreras, Andy Shevchenko, linux-omap, Ionut Nicu

Hi Ionut,

On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
> Convert the core module of the tidspbridge driver
> to use struct list_head instead of struct lst_list.
>
> Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>

<snip>

> diff --git a/drivers/staging/tidspbridge/core/io_sm.c b/drivers/staging/tidspbridge/core/io_sm.c
> index 194bada..9851f32 100644
> --- a/drivers/staging/tidspbridge/core/io_sm.c
> +++ b/drivers/staging/tidspbridge/core/io_sm.c

<snip>

> @@ -1106,47 +1103,38 @@ static void input_msg(struct io_mgr *pio_mgr, struct msg_mgr *hmsg_mgr)
>                                         * queued.
>                                         */
>                                        (*hmsg_mgr->on_exit) ((void *)
> -                                                          msg_queue_obj->arg,
> -                                                          msg.msg.dw_arg1);
> +                                                       msg_queue_obj->arg,
> +                                                       msg.msg.dw_arg1);
> +                                       break;
> +                               }
> +                               /*
> +                                * Not an exit acknowledgement, queue
> +                                * the message.
> +                                */
> +                               if (!list_empty(&msg_queue_obj->msg_free_list)) {

You are going beyond the 80 chars.

Regards,
Rene

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

* Re: [PATCH v2 07/12] staging: tidspbridge: convert pmgr to list_head
  2010-11-05 15:13 ` [PATCH v2 07/12] staging: tidspbridge: convert pmgr " Ionut Nicu
@ 2010-11-05 22:41   ` Sapiens, Rene
  2010-11-07 13:39     ` Ionut Nicu
  0 siblings, 1 reply; 31+ messages in thread
From: Sapiens, Rene @ 2010-11-05 22:41 UTC (permalink / raw)
  To: Ionut Nicu
  Cc: Greg Kroah-Hartman, Omar Ramirez Luna, Fernando Guzman Lugo,
	Felipe Contreras, Andy Shevchenko, linux-omap, Ionut Nicu

Hi Ionut,

On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
> Convert the pmgr module of the tidspbridge driver
> to use struct list_head instead of struct lst_list.

<snip>

> + * Memory is coalesced back to the appropriate heap when a buffer is

What is being fixed here?

>  * freed.
>  *
>  * Notes:

<snip>

> @@ -833,67 +768,44 @@ static void add_to_free_list(struct cmm_allocator *allocator,
>        DBC_REQUIRE(allocator != NULL);
>        dw_this_pa = pnode->dw_pa;
>        dw_next_pa = NEXT_PA(pnode);

i think it would be good to return with error if !allocator or !pnode
and remove the	resulting duplicated DBC_REQUIRE.

> -       mnode_obj = (struct cmm_mnode *)lst_first(allocator->free_list_head);
> -       while (mnode_obj) {
> +       list_for_each_entry(mnode_obj, &allocator->free_list, link) {
>                if (dw_this_pa == NEXT_PA(mnode_obj)) {

<snip>

> @@ -748,18 +736,16 @@ bool dev_init(void)
>  */
>  int dev_notify_clients(struct dev_object *hdev_obj, u32 ret)
>  {
> -       int status = 0;
> -
>        struct dev_object *dev_obj = hdev_obj;
> -       void *proc_obj;
> +       struct list_head *curr;

can we add a check for !dev_obj and !dev_obj->proc_list just to be
sure that we get always the correct pointer?

<snip>

> @@ -947,15 +933,17 @@ int dev_insert_proc_object(struct dev_object *hdev_obj,
>        DBC_REQUIRE(refs > 0);
>        DBC_REQUIRE(dev_obj);
>        DBC_REQUIRE(proc_obj != 0);
> -       DBC_REQUIRE(dev_obj->proc_list != NULL);
>        DBC_REQUIRE(already_attached != NULL);

can we check for !hdev_obj, !already_attached even if we have the
DBC_REQUIRE?, maybe we can actually remove the DBC_REQUIRE that could
be redundant after applying this.

> -       if (!LST_IS_EMPTY(dev_obj->proc_list))
> +       if (!list_empty(&dev_obj->proc_list))
>                *already_attached = true;

<snip>

> @@ -986,15 +974,12 @@ int dev_remove_proc_object(struct dev_object *hdev_obj, u32 proc_obj)
>
>        DBC_REQUIRE(dev_obj);
>        DBC_REQUIRE(proc_obj != 0);
> -       DBC_REQUIRE(dev_obj->proc_list != NULL);
> -       DBC_REQUIRE(!LST_IS_EMPTY(dev_obj->proc_list));
> +       DBC_REQUIRE(!list_empty(&dev_obj->proc_list));
>

 The same comment as above.

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

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

* Re: [PATCH v2 08/12] staging: tidspbridge: convert rmgr to list_head
  2010-11-05 15:13 ` [PATCH v2 08/12] staging: tidspbridge: convert rmgr " Ionut Nicu
@ 2010-11-06  0:07   ` Sapiens, Rene
  2010-11-06 18:18     ` Ionut Nicu
  0 siblings, 1 reply; 31+ messages in thread
From: Sapiens, Rene @ 2010-11-06  0:07 UTC (permalink / raw)
  To: Ionut Nicu
  Cc: Greg Kroah-Hartman, Omar Ramirez Luna, Fernando Guzman Lugo,
	Felipe Contreras, Andy Shevchenko, linux-omap, Ionut Nicu

Hi Ionut,

On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
> Convert the rmgr module of the tidspbridge driver
> to use struct list_head instead of struct lst_list.
>
> Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>

<snip>

> diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c

<snip>

> @@ -492,16 +465,17 @@ u32 drv_get_next_dev_object(u32 hdev_obj)
>        u32 dw_next_dev_object = 0;
>        struct drv_object *pdrv_obj;
>        struct drv_data *drv_datap = dev_get_drvdata(bridge);
> +       struct list_head *curr;
>
>        DBC_REQUIRE(hdev_obj != 0);

can we remove the DBC_REQUIRE and always check for !hdev_obj?

>
>        if (drv_datap && drv_datap->drv_object) {
>                pdrv_obj = drv_datap->drv_object;
> -               if ((pdrv_obj->dev_list != NULL) &&
> -                   !LST_IS_EMPTY(pdrv_obj->dev_list)) {
> -                       dw_next_dev_object = (u32) lst_next(pdrv_obj->dev_list,
> -                                                           (struct list_head *)
> -                                                           hdev_obj);
> +               if (!list_empty(&pdrv_obj->dev_list)) {
> +                       curr = (struct list_head *)hdev_obj;
> +                       if (curr->next == &pdrv_obj->dev_list)

Can we use list_is_last() instead?

> +                               return 0;
> +                       dw_next_dev_object = (u32) curr->next;

<snip>

> @@ -573,11 +548,8 @@ int drv_insert_dev_object(struct drv_object *driver_obj,
>        DBC_REQUIRE(refs > 0);
>        DBC_REQUIRE(hdev_obj != NULL);
>        DBC_REQUIRE(pdrv_object);
> -       DBC_ASSERT(pdrv_object->dev_list);
> -

As a comment for all the functions that are manipulating lists, can we
check the parameters that they receive?, this applies for some other
functions in these patches, old lst_* functions were internally validating
the having of a valid pointer, now i think that we have to add this to each
function.

> -       lst_put_tail(pdrv_object->dev_list, (struct list_head *)hdev_obj);
>
> -       DBC_ENSURE(!LST_IS_EMPTY(pdrv_object->dev_list));
> +       list_add_tail((struct list_head *)hdev_obj, &pdrv_object->dev_list);

<snip>

> @@ -1571,15 +1566,9 @@ int node_enum_nodes(struct node_mgr *hnode_mgr, void **node_tab,
>                *pu_num_nodes = 0;
>                status = -EINVAL;
>        } else {
> -               hnode = (struct node_object *)lst_first(hnode_mgr->
> -                       node_list);
> -               for (i = 0; i < hnode_mgr->num_nodes; i++) {
> -                       DBC_ASSERT(hnode);
> -                       node_tab[i] = hnode;
> -                       hnode = (struct node_object *)lst_next
> -                               (hnode_mgr->node_list,
> -                               (struct list_head *)hnode);
> -               }
> +               i = 0;

just a comment, what if we initialize this "i" when declared and
remove this line.

> +               list_for_each_entry(hnode, &hnode_mgr->node_list, list_elem)
> +                       node_tab[i++] = hnode;
>                *pu_allocated = *pu_num_nodes = hnode_mgr->num_nodes;
>        }

<snip>

> diff --git a/drivers/staging/tidspbridge/rmgr/rmm.c b/drivers/staging/tidspbridge/rmgr/rmm.c

<snip>

> @@ -145,20 +141,17 @@ int rmm_alloc(struct rmm_target_obj *target, u32 segid, u32 size,
>                if (new_sect == NULL) {
>                        status = -ENOMEM;
>                } else {
> -                       lst_init_elem((struct list_head *)new_sect);
>                        new_sect->addr = addr;
>                        new_sect->size = size;
>                        new_sect->page = segid;
> -                       if (sect == NULL) {
> +                       if (sect == NULL)

I think that "sect" can't be NULL at this point... can be?
can we use: if (list_is_last(&sect->list_elem, target->ovly_list)) instead?

>                                /* Put new section at the end of the list */
> -                               lst_put_tail(target->ovly_list,
> -                                            (struct list_head *)new_sect);
> -                       } else {
> +                               list_add_tail(&new_sect->list_elem,
> +                                               &target->ovly_list);
> +                       else

<snip>

> @@ -333,24 +316,17 @@ bool rmm_free(struct rmm_target_obj *target, u32 segid, u32 dsp_addr, u32 size,
>
>        } else {
>                /* Unreserve memory */
> -               sect = (struct rmm_ovly_sect *)lst_first(target->ovly_list);
> -               while (sect != NULL) {
> +               list_for_each_entry_safe(sect, tmp, &target->ovly_list,
> +                               list_elem) {
>                        if (dsp_addr == sect->addr) {
>                                DBC_ASSERT(size == sect->size);
>                                /* Remove from list */
> -                               lst_remove_elem(target->ovly_list,
> -                                               (struct list_head *)sect);
> +                               list_del(&sect->list_elem);
>                                kfree(sect);
> +                               ret = true;
>                                break;

can we just return true and do not break?

>                        }

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

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

* Re: [PATCH v2 06/12] staging: tidspbridge: convert core to list_head
  2010-11-05 21:07   ` Sapiens, Rene
@ 2010-11-06 17:21     ` Ionut Nicu
  2010-11-08 19:15       ` Sapiens, Rene
  0 siblings, 1 reply; 31+ messages in thread
From: Ionut Nicu @ 2010-11-06 17:21 UTC (permalink / raw)
  To: Sapiens, Rene
  Cc: Ionut Nicu, Greg Kroah-Hartman, Omar Ramirez Luna,
	Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	linux-omap

Hi Rene,

On Fri, 2010-11-05 at 15:07 -0600, Sapiens, Rene wrote:
> Hi Ionut,
> 
> On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
> > Convert the core module of the tidspbridge driver
> > to use struct list_head instead of struct lst_list.
> >
> 
> <snip>
> 
> >        if (!status) {
> >                /* Get a free chirp: */
> > -               chnl_packet_obj =
> > -                   (struct chnl_irp *)lst_get_head(pchnl->free_packets_list);
> > -               if (chnl_packet_obj == NULL)
> > +               if (!list_empty(&pchnl->free_packets_list)) {
> > +                       chnl_packet_obj = list_first_entry(
> > +                                       &pchnl->free_packets_list,
> > +                                       struct chnl_irp, link);
> > +                       list_del(&chnl_packet_obj->link);
> > +               } else
> >                        status = -EIO;
> 
> What do you think if we close the braces, since the first conditional
> has more than one statement?
> 

Can you clarify? I don't think I understand which brace we need to close
here.

> <snip>
> 
> > @@ -286,18 +286,16 @@ int bridge_chnl_cancel_io(struct chnl_object *chnl_obj)
> >                }
> >        }
> >        /* Move all IOR's to IOC queue: */
> > -       while (!LST_IS_EMPTY(pchnl->pio_requests)) {
> > -               chnl_packet_obj =
> > -                   (struct chnl_irp *)lst_get_head(pchnl->pio_requests);
> > -               if (chnl_packet_obj) {
> > -                       chnl_packet_obj->byte_size = 0;
> > -                       chnl_packet_obj->status |= CHNL_IOCSTATCANCEL;
> > -                       lst_put_tail(pchnl->pio_completions,
> > -                                    (struct list_head *)chnl_packet_obj);
> > -                       pchnl->cio_cs++;
> > -                       pchnl->cio_reqs--;
> > -                       DBC_ASSERT(pchnl->cio_reqs >= 0);
> > -               }
> > +       while (!list_empty(&pchnl->pio_requests)) {
> > +               chnl_packet_obj = list_first_entry(&pchnl->pio_requests,
> > +                               struct chnl_irp, link);
> > +               list_del(&chnl_packet_obj->link);
> > +               chnl_packet_obj->byte_size = 0;
> > +               chnl_packet_obj->status |= CHNL_IOCSTATCANCEL;
> > +               list_add_tail(&chnl_packet_obj->link, &pchnl->pio_completions);
> > +               pchnl->cio_cs++;
> > +               pchnl->cio_reqs--;
> > +               DBC_ASSERT(pchnl->cio_reqs >= 0);
> 
> Why don't we use list_for_each_entry_safe() instead?
> 

Agreed, it will look better.


> >        }
> >  func_cont:
> >        spin_unlock_bh(&chnl_mgr_obj->chnl_mgr_lock);
> 
> <snip>
> 
> > @@ -818,9 +804,19 @@ int bridge_chnl_open(struct chnl_object **chnl,
> >        /* Protect queues from io_dpc: */
> >        pchnl->dw_state = CHNL_STATECANCEL;
> >        /* Allocate initial IOR and IOC queues: */
> > -       pchnl->free_packets_list = create_chirp_list(pattrs->uio_reqs);
> > -       pchnl->pio_requests = create_chirp_list(0);
> > -       pchnl->pio_completions = create_chirp_list(0);
> > +       status = create_chirp_list(&pchnl->free_packets_list,
> > +                       pattrs->uio_reqs);
> > +       if (status)
> > +               goto func_end;
> > +
> > +       status = create_chirp_list(&pchnl->pio_requests, 0);
> > +       if (status)
> > +               goto func_end;
> > +
> > +       status = create_chirp_list(&pchnl->pio_completions, 0);
> > +       if (status)
> > +               goto func_end;
> > +
> 
> With these goto you are not freeing the memory allocated for pchnl, please free
> it at func_end.
> 

Thanks for catching this. Freeing it at func_end is not a very good
idea, because it's also freed above. 

What do you think if I replace the last two calls for
create_chirp_list() with just INIT_LIST_HEAD()? This way we'll have only
one error check where we'll also kfree(pchnl) and we'll have 2 less
un-necessary function calls / error checks.

Regards,
Ionut.


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

* Re: [PATCH v2 06/12] staging: tidspbridge: convert core to list_head
  2010-11-05 22:12   ` Sapiens, Rene
@ 2010-11-06 17:31     ` Ionut Nicu
  2010-11-08 19:16       ` Sapiens, Rene
  0 siblings, 1 reply; 31+ messages in thread
From: Ionut Nicu @ 2010-11-06 17:31 UTC (permalink / raw)
  To: Sapiens, Rene
  Cc: Ionut Nicu, Greg Kroah-Hartman, Omar Ramirez Luna,
	Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	linux-omap

Hi Rene,

On Fri, 2010-11-05 at 16:12 -0600, Sapiens, Rene wrote:
> Hi Ionut,
> 
> On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
> > Convert the core module of the tidspbridge driver
> > to use struct list_head instead of struct lst_list.
> >
> > Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
> 
> <snip>
> 
> > diff --git a/drivers/staging/tidspbridge/core/io_sm.c b/drivers/staging/tidspbridge/core/io_sm.c
> > index 194bada..9851f32 100644
> > --- a/drivers/staging/tidspbridge/core/io_sm.c
> > +++ b/drivers/staging/tidspbridge/core/io_sm.c
> 
> <snip>
> 
> > @@ -1106,47 +1103,38 @@ static void input_msg(struct io_mgr *pio_mgr, struct msg_mgr *hmsg_mgr)
> >                                         * queued.
> >                                         */
> >                                        (*hmsg_mgr->on_exit) ((void *)
> > -                                                          msg_queue_obj->arg,
> > -                                                          msg.msg.dw_arg1);
> > +                                                       msg_queue_obj->arg,
> > +                                                       msg.msg.dw_arg1);
> > +                                       break;
> > +                               }
> > +                               /*
> > +                                * Not an exit acknowledgement, queue
> > +                                * the message.
> > +                                */
> > +                               if (!list_empty(&msg_queue_obj->msg_free_list)) {
> 
> You are going beyond the 80 chars.
> 

I thought about it too when using scripts/checkpatch.pl on this patch.
The thing is that it's 81 chars and breaking it into two lines makes it
look uglier. Also, this gets fixed in patch 10/12 (core code cleanup).

Regards,
Ionut.


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

* Re: [PATCH v2 08/12] staging: tidspbridge: convert rmgr to list_head
  2010-11-06  0:07   ` Sapiens, Rene
@ 2010-11-06 18:18     ` Ionut Nicu
  2010-11-06 18:26       ` Greg KH
  2010-11-08 19:18       ` Sapiens, Rene
  0 siblings, 2 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-06 18:18 UTC (permalink / raw)
  To: Sapiens, Rene
  Cc: Ionut Nicu, Greg Kroah-Hartman, Omar Ramirez Luna,
	Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	linux-omap

Hi Rene,

On Fri, 2010-11-05 at 18:07 -0600, Sapiens, Rene wrote:
> Hi Ionut,
> 
> On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
> > Convert the rmgr module of the tidspbridge driver
> > to use struct list_head instead of struct lst_list.
> >
> > Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
> 
> <snip>
> 
> > diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c
> 
> <snip>
> 
> > @@ -492,16 +465,17 @@ u32 drv_get_next_dev_object(u32 hdev_obj)
> >        u32 dw_next_dev_object = 0;
> >        struct drv_object *pdrv_obj;
> >        struct drv_data *drv_datap = dev_get_drvdata(bridge);
> > +       struct list_head *curr;
> >
> >        DBC_REQUIRE(hdev_obj != 0);
> 
> can we remove the DBC_REQUIRE and always check for !hdev_obj?
> 

Sounds ok to me.

As a general remark, I personally think that the DBC_* macros should be
replaced with BUG_ON, WARN_ON, but that's a subject for other patches.
What do you think? 

> >
> >        if (drv_datap && drv_datap->drv_object) {
> >                pdrv_obj = drv_datap->drv_object;
> > -               if ((pdrv_obj->dev_list != NULL) &&
> > -                   !LST_IS_EMPTY(pdrv_obj->dev_list)) {
> > -                       dw_next_dev_object = (u32) lst_next(pdrv_obj->dev_list,
> > -                                                           (struct list_head *)
> > -                                                           hdev_obj);
> > +               if (!list_empty(&pdrv_obj->dev_list)) {
> > +                       curr = (struct list_head *)hdev_obj;
> > +                       if (curr->next == &pdrv_obj->dev_list)
> 
> Can we use list_is_last() instead?
> 

Good point. I'll fix this.

> > +                               return 0;
> > +                       dw_next_dev_object = (u32) curr->next;
> 
> <snip>
> 
> > @@ -573,11 +548,8 @@ int drv_insert_dev_object(struct drv_object *driver_obj,
> >        DBC_REQUIRE(refs > 0);
> >        DBC_REQUIRE(hdev_obj != NULL);
> >        DBC_REQUIRE(pdrv_object);
> > -       DBC_ASSERT(pdrv_object->dev_list);
> > -
> 
> As a comment for all the functions that are manipulating lists, can we
> check the parameters that they receive?, this applies for some other
> functions in these patches, old lst_* functions were internally validating
> the having of a valid pointer, now i think that we have to add this to each
> function.
> 

I don't think we need to put extra checks. The list head pointer will
never be null and I don't see any use cases where the list_head
container structure can be null...

> > -       lst_put_tail(pdrv_object->dev_list, (struct list_head *)hdev_obj);
> >
> > -       DBC_ENSURE(!LST_IS_EMPTY(pdrv_object->dev_list));
> > +       list_add_tail((struct list_head *)hdev_obj, &pdrv_object->dev_list);
> 
> <snip>
> 
> > @@ -1571,15 +1566,9 @@ int node_enum_nodes(struct node_mgr *hnode_mgr, void **node_tab,
> >                *pu_num_nodes = 0;
> >                status = -EINVAL;
> >        } else {
> > -               hnode = (struct node_object *)lst_first(hnode_mgr->
> > -                       node_list);
> > -               for (i = 0; i < hnode_mgr->num_nodes; i++) {
> > -                       DBC_ASSERT(hnode);
> > -                       node_tab[i] = hnode;
> > -                       hnode = (struct node_object *)lst_next
> > -                               (hnode_mgr->node_list,
> > -                               (struct list_head *)hnode);
> > -               }
> > +               i = 0;
> 
> just a comment, what if we initialize this "i" when declared and
> remove this line.
> 

Ok, will do.


> > +               list_for_each_entry(hnode, &hnode_mgr->node_list, list_elem)
> > +                       node_tab[i++] = hnode;
> >                *pu_allocated = *pu_num_nodes = hnode_mgr->num_nodes;
> >        }
> 
> <snip>
> 
> > diff --git a/drivers/staging/tidspbridge/rmgr/rmm.c b/drivers/staging/tidspbridge/rmgr/rmm.c
> 
> <snip>
> 
> > @@ -145,20 +141,17 @@ int rmm_alloc(struct rmm_target_obj *target, u32 segid, u32 size,
> >                if (new_sect == NULL) {
> >                        status = -ENOMEM;
> >                } else {
> > -                       lst_init_elem((struct list_head *)new_sect);
> >                        new_sect->addr = addr;
> >                        new_sect->size = size;
> >                        new_sect->page = segid;
> > -                       if (sect == NULL) {
> > +                       if (sect == NULL)
> 
> I think that "sect" can't be NULL at this point... can be?
> can we use: if (list_is_last(&sect->list_elem, target->ovly_list)) instead?
> 

Yes, you are right.


> >                                /* Put new section at the end of the list */
> > -                               lst_put_tail(target->ovly_list,
> > -                                            (struct list_head *)new_sect);
> > -                       } else {
> > +                               list_add_tail(&new_sect->list_elem,
> > +                                               &target->ovly_list);
> > +                       else
> 
> <snip>
> 
> > @@ -333,24 +316,17 @@ bool rmm_free(struct rmm_target_obj *target, u32 segid, u32 dsp_addr, u32 size,
> >
> >        } else {
> >                /* Unreserve memory */
> > -               sect = (struct rmm_ovly_sect *)lst_first(target->ovly_list);
> > -               while (sect != NULL) {
> > +               list_for_each_entry_safe(sect, tmp, &target->ovly_list,
> > +                               list_elem) {
> >                        if (dsp_addr == sect->addr) {
> >                                DBC_ASSERT(size == sect->size);
> >                                /* Remove from list */
> > -                               lst_remove_elem(target->ovly_list,
> > -                                               (struct list_head *)sect);
> > +                               list_del(&sect->list_elem);
> >                                kfree(sect);
> > +                               ret = true;
> >                                break;
> 
> can we just return true and do not break?

Sure, I will change this.

Regards,
Ionut.



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

* Re: [PATCH v2 08/12] staging: tidspbridge: convert rmgr to list_head
  2010-11-06 18:18     ` Ionut Nicu
@ 2010-11-06 18:26       ` Greg KH
  2010-11-07 12:11         ` Ionut Nicu
  2010-11-08 19:18       ` Sapiens, Rene
  1 sibling, 1 reply; 31+ messages in thread
From: Greg KH @ 2010-11-06 18:26 UTC (permalink / raw)
  To: Ionut Nicu
  Cc: Sapiens, Rene, Ionut Nicu, Omar Ramirez Luna,
	Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	linux-omap

On Sat, Nov 06, 2010 at 08:18:27PM +0200, Ionut Nicu wrote:
> Hi Rene,
> 
> On Fri, 2010-11-05 at 18:07 -0600, Sapiens, Rene wrote:
> > Hi Ionut,
> > 
> > On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
> > > Convert the rmgr module of the tidspbridge driver
> > > to use struct list_head instead of struct lst_list.
> > >
> > > Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
> > 
> > <snip>
> > 
> > > diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c
> > 
> > <snip>
> > 
> > > @@ -492,16 +465,17 @@ u32 drv_get_next_dev_object(u32 hdev_obj)
> > >        u32 dw_next_dev_object = 0;
> > >        struct drv_object *pdrv_obj;
> > >        struct drv_data *drv_datap = dev_get_drvdata(bridge);
> > > +       struct list_head *curr;
> > >
> > >        DBC_REQUIRE(hdev_obj != 0);
> > 
> > can we remove the DBC_REQUIRE and always check for !hdev_obj?
> > 
> 
> Sounds ok to me.
> 
> As a general remark, I personally think that the DBC_* macros should be
> replaced with BUG_ON, WARN_ON, but that's a subject for other patches.
> What do you think? 

They should probably be deleted, I will not add any BUG_ON to a driver,
nor should anyone else.  That's just rude behavior to crash the system,
don't you think?

thanks,

greg k-h

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

* Re: [PATCH v2 08/12] staging: tidspbridge: convert rmgr to list_head
  2010-11-06 18:26       ` Greg KH
@ 2010-11-07 12:11         ` Ionut Nicu
  2010-11-07 14:24           ` Nishanth Menon
  2010-11-07 15:59           ` Greg KH
  0 siblings, 2 replies; 31+ messages in thread
From: Ionut Nicu @ 2010-11-07 12:11 UTC (permalink / raw)
  To: Greg KH
  Cc: Sapiens, Rene, Ionut Nicu, Omar Ramirez Luna,
	Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	linux-omap

Hi Greg,

On Sat, 2010-11-06 at 11:26 -0700, Greg KH wrote:
> On Sat, Nov 06, 2010 at 08:18:27PM +0200, Ionut Nicu wrote:
> > Hi Rene,
> > 
> > On Fri, 2010-11-05 at 18:07 -0600, Sapiens, Rene wrote:
> > > Hi Ionut,
> > > 
> > > On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
> > > > Convert the rmgr module of the tidspbridge driver
> > > > to use struct list_head instead of struct lst_list.
> > > >
> > > > Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
> > > 
> > > <snip>
> > > 
> > > > diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c
> > > 
> > > <snip>
> > > 
> > > > @@ -492,16 +465,17 @@ u32 drv_get_next_dev_object(u32 hdev_obj)
> > > >        u32 dw_next_dev_object = 0;
> > > >        struct drv_object *pdrv_obj;
> > > >        struct drv_data *drv_datap = dev_get_drvdata(bridge);
> > > > +       struct list_head *curr;
> > > >
> > > >        DBC_REQUIRE(hdev_obj != 0);
> > > 
> > > can we remove the DBC_REQUIRE and always check for !hdev_obj?
> > > 
> > 
> > Sounds ok to me.
> > 
> > As a general remark, I personally think that the DBC_* macros should be
> > replaced with BUG_ON, WARN_ON, but that's a subject for other patches.
> > What do you think? 
> 
> They should probably be deleted, I will not add any BUG_ON to a driver,
> nor should anyone else.  That's just rude behavior to crash the system,
> don't you think?
> 

You're right. Removing them sounds like a better plan. There over 1000
DBC_* lines in this driver, so I guess it will clean it up a little bit.

Just out of curiosity, in what cases is it acceptable to use
BUG_ON/WARN_ON?

Thanks,
Ionut.


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

* Re: [PATCH v2 07/12] staging: tidspbridge: convert pmgr to list_head
  2010-11-05 22:41   ` Sapiens, Rene
@ 2010-11-07 13:39     ` Ionut Nicu
  2010-11-08 19:17       ` Sapiens, Rene
  0 siblings, 1 reply; 31+ messages in thread
From: Ionut Nicu @ 2010-11-07 13:39 UTC (permalink / raw)
  To: Sapiens, Rene
  Cc: Ionut Nicu, Greg Kroah-Hartman, Omar Ramirez Luna,
	Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	linux-omap

Hi Rene,

On Fri, 2010-11-05 at 16:41 -0600, Sapiens, Rene wrote:
> Hi Ionut,
> 
> On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
> > Convert the pmgr module of the tidspbridge driver
> > to use struct list_head instead of struct lst_list.
> 
> <snip>
> 
> > + * Memory is coalesced back to the appropriate heap when a buffer is
> 
> What is being fixed here?
> 

It was a typo (s/coelesced/coalesced/).

> >  * freed.
> >  *
> >  * Notes:
> 
> <snip>
> 
> > @@ -833,67 +768,44 @@ static void add_to_free_list(struct cmm_allocator *allocator,
> >        DBC_REQUIRE(allocator != NULL);
> >        dw_this_pa = pnode->dw_pa;
> >        dw_next_pa = NEXT_PA(pnode);
> 
> i think it would be good to return with error if !allocator or !pnode
> and remove the	resulting duplicated DBC_REQUIRE.
> 

Yeah I think pnode should be checked for null. Can allocator ever be
null?

> > -       mnode_obj = (struct cmm_mnode *)lst_first(allocator->free_list_head);
> > -       while (mnode_obj) {
> > +       list_for_each_entry(mnode_obj, &allocator->free_list, link) {
> >                if (dw_this_pa == NEXT_PA(mnode_obj)) {
> 
> <snip>
> 
> > @@ -748,18 +736,16 @@ bool dev_init(void)
> >  */
> >  int dev_notify_clients(struct dev_object *hdev_obj, u32 ret)
> >  {
> > -       int status = 0;
> > -
> >        struct dev_object *dev_obj = hdev_obj;
> > -       void *proc_obj;
> > +       struct list_head *curr;
> 
> can we add a check for !dev_obj and !dev_obj->proc_list just to be
> sure that we get always the correct pointer?
> 

proc_list isn't a pointer. Can dev_obj ever be null?

> <snip>
> 
> > @@ -947,15 +933,17 @@ int dev_insert_proc_object(struct dev_object *hdev_obj,
> >        DBC_REQUIRE(refs > 0);
> >        DBC_REQUIRE(dev_obj);
> >        DBC_REQUIRE(proc_obj != 0);
> > -       DBC_REQUIRE(dev_obj->proc_list != NULL);
> >        DBC_REQUIRE(already_attached != NULL);
> 
> can we check for !hdev_obj, !already_attached even if we have the
> DBC_REQUIRE?, maybe we can actually remove the DBC_REQUIRE that could
> be redundant after applying this.
> 

Same question here.

> > -       if (!LST_IS_EMPTY(dev_obj->proc_list))
> > +       if (!list_empty(&dev_obj->proc_list))
> >                *already_attached = true;
> 
> <snip>
> 
> > @@ -986,15 +974,12 @@ int dev_remove_proc_object(struct dev_object *hdev_obj, u32 proc_obj)
> >
> >        DBC_REQUIRE(dev_obj);
> >        DBC_REQUIRE(proc_obj != 0);
> > -       DBC_REQUIRE(dev_obj->proc_list != NULL);
> > -       DBC_REQUIRE(!LST_IS_EMPTY(dev_obj->proc_list));
> > +       DBC_REQUIRE(!list_empty(&dev_obj->proc_list));
> >
> 
>  The same comment as above.
> 

Regards,
Ionut.


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

* Re: [PATCH v2 08/12] staging: tidspbridge: convert rmgr to list_head
  2010-11-07 12:11         ` Ionut Nicu
@ 2010-11-07 14:24           ` Nishanth Menon
  2010-11-07 15:59           ` Greg KH
  1 sibling, 0 replies; 31+ messages in thread
From: Nishanth Menon @ 2010-11-07 14:24 UTC (permalink / raw)
  To: Ionut Nicu
  Cc: Greg KH, Sapiens, Rene, Ionut Nicu, Omar Ramirez Luna,
	Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	linux-omap

Ionut Nicu wrote, on 11/07/2010 06:11 AM:

> Just out of curiosity, in what cases is it acceptable to use
> BUG_ON/WARN_ON?
here is my rule for BUG_ON Vs WARN_ON:

imagine this code to be running on your Phone while you are doing 
sometime important, and this case gets hit - choose:
a) you stop the entire phone - BUG_ON
b) provide a cryptic info - WARN_ON - just the func name with not much 
additional data
c) provide detailed info : in the order of my personal preference:
	dev_dbg/dev_info/dev_err/... -> if there is anychange of getting to the 
struct device * representing the device
	pr_err/pr_info/pr_warning -> if there is no other alternative

keep in mind - few months from now, code would change, function line 
numbers change etc.. - I'd usually NOT TOUCH BUG_ON, NOT use WARN_ON 
unless I am threatened by maintainer, and choose one of (c) based on the 
location in the code I am at..

I know that some folks think that when a case is reached, they'd like to 
do a BUG_ON so that the issue is caught and fixed immediately - SORRY, I 
disagree as I see the code running in a endproduct - and BUG_ONs cause 
system hang and reboots in an end product - which as a personal user of 
a great Linux phone like N900 is definitely not my personal preference.

-- 
Regards,
Nishanth Menon

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

* Re: [PATCH v2 08/12] staging: tidspbridge: convert rmgr to list_head
  2010-11-07 12:11         ` Ionut Nicu
  2010-11-07 14:24           ` Nishanth Menon
@ 2010-11-07 15:59           ` Greg KH
  1 sibling, 0 replies; 31+ messages in thread
From: Greg KH @ 2010-11-07 15:59 UTC (permalink / raw)
  To: Ionut Nicu
  Cc: Sapiens, Rene, Ionut Nicu, Omar Ramirez Luna,
	Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	linux-omap

On Sun, Nov 07, 2010 at 02:11:24PM +0200, Ionut Nicu wrote:
> Hi Greg,
> 
> On Sat, 2010-11-06 at 11:26 -0700, Greg KH wrote:
> > On Sat, Nov 06, 2010 at 08:18:27PM +0200, Ionut Nicu wrote:
> > > Hi Rene,
> > > 
> > > On Fri, 2010-11-05 at 18:07 -0600, Sapiens, Rene wrote:
> > > > Hi Ionut,
> > > > 
> > > > On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
> > > > > Convert the rmgr module of the tidspbridge driver
> > > > > to use struct list_head instead of struct lst_list.
> > > > >
> > > > > Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
> > > > 
> > > > <snip>
> > > > 
> > > > > diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c
> > > > 
> > > > <snip>
> > > > 
> > > > > @@ -492,16 +465,17 @@ u32 drv_get_next_dev_object(u32 hdev_obj)
> > > > >        u32 dw_next_dev_object = 0;
> > > > >        struct drv_object *pdrv_obj;
> > > > >        struct drv_data *drv_datap = dev_get_drvdata(bridge);
> > > > > +       struct list_head *curr;
> > > > >
> > > > >        DBC_REQUIRE(hdev_obj != 0);
> > > > 
> > > > can we remove the DBC_REQUIRE and always check for !hdev_obj?
> > > > 
> > > 
> > > Sounds ok to me.
> > > 
> > > As a general remark, I personally think that the DBC_* macros should be
> > > replaced with BUG_ON, WARN_ON, but that's a subject for other patches.
> > > What do you think? 
> > 
> > They should probably be deleted, I will not add any BUG_ON to a driver,
> > nor should anyone else.  That's just rude behavior to crash the system,
> > don't you think?
> > 
> 
> You're right. Removing them sounds like a better plan. There over 1000
> DBC_* lines in this driver, so I guess it will clean it up a little bit.
> 
> Just out of curiosity, in what cases is it acceptable to use
> BUG_ON/WARN_ON?

In a driver, almost never.  Use dev_err() and friends instead.

thanks,

greg k-h

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

* Re: [PATCH v2 06/12] staging: tidspbridge: convert core to list_head
  2010-11-06 17:21     ` Ionut Nicu
@ 2010-11-08 19:15       ` Sapiens, Rene
  0 siblings, 0 replies; 31+ messages in thread
From: Sapiens, Rene @ 2010-11-08 19:15 UTC (permalink / raw)
  To: Ionut Nicu
  Cc: Ionut Nicu, Greg Kroah-Hartman, Omar Ramirez Luna,
	Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	linux-omap

Hi Ionut,

On Sat, Nov 6, 2010 at 11:21 AM, Ionut Nicu <ionut.nicu@mindbit.ro> wrote:
> Hi Rene,
>
> On Fri, 2010-11-05 at 15:07 -0600, Sapiens, Rene wrote:
>> Hi Ionut,
>>
>> On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
>> > Convert the core module of the tidspbridge driver
>> > to use struct list_head instead of struct lst_list.
>> >
>>
>> <snip>
>>
>> >        if (!status) {
>> >                /* Get a free chirp: */
>> > -               chnl_packet_obj =
>> > -                   (struct chnl_irp *)lst_get_head(pchnl->free_packets_list);
>> > -               if (chnl_packet_obj == NULL)
>> > +               if (!list_empty(&pchnl->free_packets_list)) {
>> > +                       chnl_packet_obj = list_first_entry(
>> > +                                       &pchnl->free_packets_list,
>> > +                                       struct chnl_irp, link);
>> > +                       list_del(&chnl_packet_obj->link);
>> > +               } else
>> >                        status = -EIO;
>>
>> What do you think if we close the braces, since the first conditional
>> has more than one statement?
>>
>
> Can you clarify? I don't think I understand which brace we need to close
> here.

I mean open and close the braces for the added 'else', I'm just mentioning
what the coding style says for placing braces when one of the branches
has more than one statement.

>
>> <snip>
>>
>> > @@ -286,18 +286,16 @@ int bridge_chnl_cancel_io(struct chnl_object *chnl_obj)
>> >                }
>> >        }
>> >        /* Move all IOR's to IOC queue: */
>> > -       while (!LST_IS_EMPTY(pchnl->pio_requests)) {
>> > -               chnl_packet_obj =
>> > -                   (struct chnl_irp *)lst_get_head(pchnl->pio_requests);
>> > -               if (chnl_packet_obj) {
>> > -                       chnl_packet_obj->byte_size = 0;
>> > -                       chnl_packet_obj->status |= CHNL_IOCSTATCANCEL;
>> > -                       lst_put_tail(pchnl->pio_completions,
>> > -                                    (struct list_head *)chnl_packet_obj);
>> > -                       pchnl->cio_cs++;
>> > -                       pchnl->cio_reqs--;
>> > -                       DBC_ASSERT(pchnl->cio_reqs >= 0);
>> > -               }
>> > +       while (!list_empty(&pchnl->pio_requests)) {
>> > +               chnl_packet_obj = list_first_entry(&pchnl->pio_requests,
>> > +                               struct chnl_irp, link);
>> > +               list_del(&chnl_packet_obj->link);
>> > +               chnl_packet_obj->byte_size = 0;
>> > +               chnl_packet_obj->status |= CHNL_IOCSTATCANCEL;
>> > +               list_add_tail(&chnl_packet_obj->link, &pchnl->pio_completions);
>> > +               pchnl->cio_cs++;
>> > +               pchnl->cio_reqs--;
>> > +               DBC_ASSERT(pchnl->cio_reqs >= 0);
>>
>> Why don't we use list_for_each_entry_safe() instead?
>>
>
> Agreed, it will look better.
>
>
>> >        }
>> >  func_cont:
>> >        spin_unlock_bh(&chnl_mgr_obj->chnl_mgr_lock);
>>
>> <snip>
>>
>> > @@ -818,9 +804,19 @@ int bridge_chnl_open(struct chnl_object **chnl,
>> >        /* Protect queues from io_dpc: */
>> >        pchnl->dw_state = CHNL_STATECANCEL;
>> >        /* Allocate initial IOR and IOC queues: */
>> > -       pchnl->free_packets_list = create_chirp_list(pattrs->uio_reqs);
>> > -       pchnl->pio_requests = create_chirp_list(0);
>> > -       pchnl->pio_completions = create_chirp_list(0);
>> > +       status = create_chirp_list(&pchnl->free_packets_list,
>> > +                       pattrs->uio_reqs);
>> > +       if (status)
>> > +               goto func_end;
>> > +
>> > +       status = create_chirp_list(&pchnl->pio_requests, 0);
>> > +       if (status)
>> > +               goto func_end;
>> > +
>> > +       status = create_chirp_list(&pchnl->pio_completions, 0);
>> > +       if (status)
>> > +               goto func_end;
>> > +
>>
>> With these goto you are not freeing the memory allocated for pchnl, please free
>> it at func_end.
>>
>
> Thanks for catching this. Freeing it at func_end is not a very good
> idea, because it's also freed above.
>
> What do you think if I replace the last two calls for
> create_chirp_list() with just INIT_LIST_HEAD()? This way we'll have only
> one error check where we'll also kfree(pchnl) and we'll have 2 less
> un-necessary function calls / error checks.
>

Agreed,  this looks good.

>

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

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

* Re: [PATCH v2 06/12] staging: tidspbridge: convert core to list_head
  2010-11-06 17:31     ` Ionut Nicu
@ 2010-11-08 19:16       ` Sapiens, Rene
  0 siblings, 0 replies; 31+ messages in thread
From: Sapiens, Rene @ 2010-11-08 19:16 UTC (permalink / raw)
  To: Ionut Nicu
  Cc: Ionut Nicu, Greg Kroah-Hartman, Omar Ramirez Luna,
	Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	linux-omap

Hi Ionut,

On Sat, Nov 6, 2010 at 11:31 AM, Ionut Nicu <ionut.nicu@mindbit.ro> wrote:
> Hi Rene,
>
> On Fri, 2010-11-05 at 16:12 -0600, Sapiens, Rene wrote:
>> Hi Ionut,
>>
>> On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
>> > Convert the core module of the tidspbridge driver
>> > to use struct list_head instead of struct lst_list.
>> >
>> > Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
>>
>> <snip>
>>
>> > diff --git a/drivers/staging/tidspbridge/core/io_sm.c b/drivers/staging/tidspbridge/core/io_sm.c
>> > index 194bada..9851f32 100644
>> > --- a/drivers/staging/tidspbridge/core/io_sm.c
>> > +++ b/drivers/staging/tidspbridge/core/io_sm.c
>>
>> <snip>
>>
>> > @@ -1106,47 +1103,38 @@ static void input_msg(struct io_mgr *pio_mgr, struct msg_mgr *hmsg_mgr)
>> >                                         * queued.
>> >                                         */
>> >                                        (*hmsg_mgr->on_exit) ((void *)
>> > -                                                          msg_queue_obj->arg,
>> > -                                                          msg.msg.dw_arg1);
>> > +                                                       msg_queue_obj->arg,
>> > +                                                       msg.msg.dw_arg1);
>> > +                                       break;
>> > +                               }
>> > +                               /*
>> > +                                * Not an exit acknowledgement, queue
>> > +                                * the message.
>> > +                                */
>> > +                               if (!list_empty(&msg_queue_obj->msg_free_list)) {
>>
>> You are going beyond the 80 chars.
>>
>
> I thought about it too when using scripts/checkpatch.pl on this patch.
> The thing is that it's 81 chars and breaking it into two lines makes it
> look uglier. Also, this gets fixed in patch 10/12 (core code cleanup).

I think that it would be better to see every patch as a single element which
would accomplish with all the standards, what if the patch 10/12 doesn't get
merged?...

Probably we can keep this line uglier in this patch and make it prettier in the
10/12 one or even better, make it prettier in this patch.

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

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

* Re: [PATCH v2 07/12] staging: tidspbridge: convert pmgr to list_head
  2010-11-07 13:39     ` Ionut Nicu
@ 2010-11-08 19:17       ` Sapiens, Rene
  0 siblings, 0 replies; 31+ messages in thread
From: Sapiens, Rene @ 2010-11-08 19:17 UTC (permalink / raw)
  To: Ionut Nicu
  Cc: Ionut Nicu, Greg Kroah-Hartman, Omar Ramirez Luna,
	Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	linux-omap

Hi Ionut,

On Sun, Nov 7, 2010 at 7:39 AM, Ionut Nicu <ionut.nicu@mindbit.ro> wrote:
> Hi Rene,
>
> On Fri, 2010-11-05 at 16:41 -0600, Sapiens, Rene wrote:
>> Hi Ionut,
>>
>> On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
>> > Convert the pmgr module of the tidspbridge driver
>> > to use struct list_head instead of struct lst_list.
>>
>> <snip>
>>
>> > + * Memory is coalesced back to the appropriate heap when a buffer is
>>
>> What is being fixed here?
>>
>
> It was a typo (s/coelesced/coalesced/).

Ok, thanks

>
>> >  * freed.
>> >  *
>> >  * Notes:
>>
>> <snip>
>>
>> > @@ -833,67 +768,44 @@ static void add_to_free_list(struct cmm_allocator *allocator,
>> >        DBC_REQUIRE(allocator != NULL);
>> >        dw_this_pa = pnode->dw_pa;
>> >        dw_next_pa = NEXT_PA(pnode);
>>
>> i think it would be good to return with error if !allocator or !pnode
>> and remove the        resulting duplicated DBC_REQUIRE.
>>
>
> Yeah I think pnode should be checked for null. Can allocator ever be
> null?

It seems that it can actually be NULL, by a possible bug that i just
saw (will send the patch), but taking a deeper look it seems that if
allocator is NULL this function would never be called.

>
>> > -       mnode_obj = (struct cmm_mnode *)lst_first(allocator->free_list_head);
>> > -       while (mnode_obj) {
>> > +       list_for_each_entry(mnode_obj, &allocator->free_list, link) {
>> >                if (dw_this_pa == NEXT_PA(mnode_obj)) {
>>
>> <snip>
>>
>> > @@ -748,18 +736,16 @@ bool dev_init(void)
>> >  */
>> >  int dev_notify_clients(struct dev_object *hdev_obj, u32 ret)
>> >  {
>> > -       int status = 0;
>> > -
>> >        struct dev_object *dev_obj = hdev_obj;
>> > -       void *proc_obj;
>> > +       struct list_head *curr;
>>
>> can we add a check for !dev_obj and !dev_obj->proc_list just to be
>> sure that we get always the correct pointer?
>>
>
> proc_list isn't a pointer. Can dev_obj ever be null?

I suppose that adding an extra check in all functions for the received
parameter would be redundant when those parameters come only from
our driver and were previously checked, also performance would be
affected; so relying on the having of the correct parameters in the path
that calls this function it seems that dev_notify_clients() is not called
with dev_obj with a NULL value.

>
>> <snip>
>>
>> > @@ -947,15 +933,17 @@ int dev_insert_proc_object(struct dev_object *hdev_obj,
>> >        DBC_REQUIRE(refs > 0);
>> >        DBC_REQUIRE(dev_obj);
>> >        DBC_REQUIRE(proc_obj != 0);
>> > -       DBC_REQUIRE(dev_obj->proc_list != NULL);
>> >        DBC_REQUIRE(already_attached != NULL);
>>
>> can we check for !hdev_obj, !already_attached even if we have the
>> DBC_REQUIRE?, maybe we can actually remove the DBC_REQUIRE that could
>> be redundant after applying this.
>>
>
> Same question here.

The same comment.

>
>> > -       if (!LST_IS_EMPTY(dev_obj->proc_list))
>> > +       if (!list_empty(&dev_obj->proc_list))
>> >                *already_attached = true;
>>
>> <snip>
>>
>> > @@ -986,15 +974,12 @@ int dev_remove_proc_object(struct dev_object *hdev_obj, u32 proc_obj)
>> >
>> >        DBC_REQUIRE(dev_obj);
>> >        DBC_REQUIRE(proc_obj != 0);
>> > -       DBC_REQUIRE(dev_obj->proc_list != NULL);
>> > -       DBC_REQUIRE(!LST_IS_EMPTY(dev_obj->proc_list));
>> > +       DBC_REQUIRE(!list_empty(&dev_obj->proc_list));
>> >
>>
>>  The same comment as above.
>>
>
> Regards,
> Ionut.
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2 08/12] staging: tidspbridge: convert rmgr to list_head
  2010-11-06 18:18     ` Ionut Nicu
  2010-11-06 18:26       ` Greg KH
@ 2010-11-08 19:18       ` Sapiens, Rene
  1 sibling, 0 replies; 31+ messages in thread
From: Sapiens, Rene @ 2010-11-08 19:18 UTC (permalink / raw)
  To: Ionut Nicu
  Cc: Ionut Nicu, Greg Kroah-Hartman, Omar Ramirez Luna,
	Fernando Guzman Lugo, Felipe Contreras, Andy Shevchenko,
	linux-omap

Hi Ionut,

On Sat, Nov 6, 2010 at 12:18 PM, Ionut Nicu <ionut.nicu@mindbit.ro> wrote:
> Hi Rene,
>
> On Fri, 2010-11-05 at 18:07 -0600, Sapiens, Rene wrote:
>> Hi Ionut,
>>
>> On Fri, Nov 5, 2010 at 9:13 AM, Ionut Nicu <ionut.nicu@gmail.com> wrote:
>> > Convert the rmgr module of the tidspbridge driver
>> > to use struct list_head instead of struct lst_list.
>> >
>> > Signed-off-by: Ionut Nicu <ionut.nicu@mindbit.ro>
>>
>> <snip>
>>
>> > diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c
>>
>> <snip>
>>
>> > @@ -492,16 +465,17 @@ u32 drv_get_next_dev_object(u32 hdev_obj)
>> >        u32 dw_next_dev_object = 0;
>> >        struct drv_object *pdrv_obj;
>> >        struct drv_data *drv_datap = dev_get_drvdata(bridge);
>> > +       struct list_head *curr;
>> >
>> >        DBC_REQUIRE(hdev_obj != 0);
>>
>> can we remove the DBC_REQUIRE and always check for !hdev_obj?
>>
>
> Sounds ok to me.
>
> As a general remark, I personally think that the DBC_* macros should be
> replaced with BUG_ON, WARN_ON, but that's a subject for other patches.
> What do you think?
>

I think that the idea is to remove all DBC_REQUIRE/DBC_ASSERT and
use a real check of values when needed, or in the case use the Greg's
and Nishanth Menon's advices.

>> >
>> >        if (drv_datap && drv_datap->drv_object) {
>> >                pdrv_obj = drv_datap->drv_object;
>> > -               if ((pdrv_obj->dev_list != NULL) &&
>> > -                   !LST_IS_EMPTY(pdrv_obj->dev_list)) {
>> > -                       dw_next_dev_object = (u32) lst_next(pdrv_obj->dev_list,
>> > -                                                           (struct list_head *)
>> > -                                                           hdev_obj);
>> > +               if (!list_empty(&pdrv_obj->dev_list)) {
>> > +                       curr = (struct list_head *)hdev_obj;
>> > +                       if (curr->next == &pdrv_obj->dev_list)
>>
>> Can we use list_is_last() instead?
>>
>
> Good point. I'll fix this.
>
>> > +                               return 0;
>> > +                       dw_next_dev_object = (u32) curr->next;
>>
>> <snip>
>>
>> > @@ -573,11 +548,8 @@ int drv_insert_dev_object(struct drv_object *driver_obj,
>> >        DBC_REQUIRE(refs > 0);
>> >        DBC_REQUIRE(hdev_obj != NULL);
>> >        DBC_REQUIRE(pdrv_object);
>> > -       DBC_ASSERT(pdrv_object->dev_list);
>> > -
>>
>> As a comment for all the functions that are manipulating lists, can we
>> check the parameters that they receive?, this applies for some other
>> functions in these patches, old lst_* functions were internally validating
>> the having of a valid pointer, now i think that we have to add this to each
>> function.
>>
>
> I don't think we need to put extra checks. The list head pointer will
> never be null and I don't see any use cases where the list_head
> container structure can be null...
>

I mean use the 'checks' only where needed, for this case you are right
it seems that callers of this function ensure that the pointers
are not null.

I'm just worried about a hidden scenario where there could be a call to one
of this functions with a NULL pointer, i.e. lst_put_tail was checking first for
the having of a valid pointer and then it was accessing its element, now
we don' have this, so, care should be taken to do not dereference a NULL
pointer.


>> > -       lst_put_tail(pdrv_object->dev_list, (struct list_head *)hdev_obj);
>> >
>> > -       DBC_ENSURE(!LST_IS_EMPTY(pdrv_object->dev_list));
>> > +       list_add_tail((struct list_head *)hdev_obj, &pdrv_object->dev_list);
>>
>> <snip>
>>
>> > @@ -1571,15 +1566,9 @@ int node_enum_nodes(struct node_mgr *hnode_mgr, void **node_tab,
>> >                *pu_num_nodes = 0;
>> >                status = -EINVAL;
>> >        } else {
>> > -               hnode = (struct node_object *)lst_first(hnode_mgr->
>> > -                       node_list);
>> > -               for (i = 0; i < hnode_mgr->num_nodes; i++) {
>> > -                       DBC_ASSERT(hnode);
>> > -                       node_tab[i] = hnode;
>> > -                       hnode = (struct node_object *)lst_next
>> > -                               (hnode_mgr->node_list,
>> > -                               (struct list_head *)hnode);
>> > -               }
>> > +               i = 0;
>>
>> just a comment, what if we initialize this "i" when declared and
>> remove this line.
>>
>
> Ok, will do.
>
>
>> > +               list_for_each_entry(hnode, &hnode_mgr->node_list, list_elem)
>> > +                       node_tab[i++] = hnode;
>> >                *pu_allocated = *pu_num_nodes = hnode_mgr->num_nodes;
>> >        }
>>
>> <snip>
>>
>> > diff --git a/drivers/staging/tidspbridge/rmgr/rmm.c b/drivers/staging/tidspbridge/rmgr/rmm.c
>>
>> <snip>
>>
>> > @@ -145,20 +141,17 @@ int rmm_alloc(struct rmm_target_obj *target, u32 segid, u32 size,
>> >                if (new_sect == NULL) {
>> >                        status = -ENOMEM;
>> >                } else {
>> > -                       lst_init_elem((struct list_head *)new_sect);
>> >                        new_sect->addr = addr;
>> >                        new_sect->size = size;
>> >                        new_sect->page = segid;
>> > -                       if (sect == NULL) {
>> > +                       if (sect == NULL)
>>
>> I think that "sect" can't be NULL at this point... can be?
>> can we use: if (list_is_last(&sect->list_elem, target->ovly_list)) instead?
>>
>
> Yes, you are right.
>
>
>> >                                /* Put new section at the end of the list */
>> > -                               lst_put_tail(target->ovly_list,
>> > -                                            (struct list_head *)new_sect);
>> > -                       } else {
>> > +                               list_add_tail(&new_sect->list_elem,
>> > +                                               &target->ovly_list);
>> > +                       else
>>
>> <snip>
>>
>> > @@ -333,24 +316,17 @@ bool rmm_free(struct rmm_target_obj *target, u32 segid, u32 dsp_addr, u32 size,
>> >
>> >        } else {
>> >                /* Unreserve memory */
>> > -               sect = (struct rmm_ovly_sect *)lst_first(target->ovly_list);
>> > -               while (sect != NULL) {
>> > +               list_for_each_entry_safe(sect, tmp, &target->ovly_list,
>> > +                               list_elem) {
>> >                        if (dsp_addr == sect->addr) {
>> >                                DBC_ASSERT(size == sect->size);
>> >                                /* Remove from list */
>> > -                               lst_remove_elem(target->ovly_list,
>> > -                                               (struct list_head *)sect);
>> > +                               list_del(&sect->list_elem);
>> >                                kfree(sect);
>> > +                               ret = true;
>> >                                break;
>>
>> can we just return true and do not break?
>
> Sure, I will change this.
>
> Regards,
> Ionut.
>
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2010-11-08 19:18 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-05 15:13 [PATCH v2 00/12] staging: tidspbridge: various cleanups Ionut Nicu
2010-11-05 15:13 ` [PATCH v2 01/12] staging: tidspbridge: remove gs memory allocator Ionut Nicu
2010-11-05 15:13 ` [PATCH v2 02/12] staging: tidspbridge: remove utildefs Ionut Nicu
2010-11-05 15:13 ` [PATCH v2 03/12] staging: tidspbridge: switch to linux bitmap API Ionut Nicu
2010-11-05 15:13 ` [PATCH v2 04/12] staging: tidspbridge: remove gb bitmap implementation Ionut Nicu
2010-11-05 15:13 ` [PATCH v2 05/12] staging: tidspbridge: rmgr/node.c code cleanup Ionut Nicu
2010-11-05 15:13 ` [PATCH v2 06/12] staging: tidspbridge: convert core to list_head Ionut Nicu
2010-11-05 21:07   ` Sapiens, Rene
2010-11-06 17:21     ` Ionut Nicu
2010-11-08 19:15       ` Sapiens, Rene
2010-11-05 22:12   ` Sapiens, Rene
2010-11-06 17:31     ` Ionut Nicu
2010-11-08 19:16       ` Sapiens, Rene
2010-11-05 15:13 ` [PATCH v2 07/12] staging: tidspbridge: convert pmgr " Ionut Nicu
2010-11-05 22:41   ` Sapiens, Rene
2010-11-07 13:39     ` Ionut Nicu
2010-11-08 19:17       ` Sapiens, Rene
2010-11-05 15:13 ` [PATCH v2 08/12] staging: tidspbridge: convert rmgr " Ionut Nicu
2010-11-06  0:07   ` Sapiens, Rene
2010-11-06 18:18     ` Ionut Nicu
2010-11-06 18:26       ` Greg KH
2010-11-07 12:11         ` Ionut Nicu
2010-11-07 14:24           ` Nishanth Menon
2010-11-07 15:59           ` Greg KH
2010-11-08 19:18       ` Sapiens, Rene
2010-11-05 15:13 ` [PATCH v2 09/12] staging: tidspbridge: remove custom linked list Ionut Nicu
2010-11-05 15:13 ` [PATCH v2 10/12] staging: tidspbridge: core code cleanup Ionut Nicu
2010-11-05 15:13 ` [PATCH v2 11/12] staging: tidspbridge: pmgr " Ionut Nicu
2010-11-05 15:13 ` [PATCH v2 12/12] staging: tidspbridge: rmgr " Ionut Nicu
2010-11-05 15:43 ` [PATCH v2 00/12] staging: tidspbridge: various cleanups Greg KH
2010-11-05 16:02   ` Ionut Nicu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.