Skip to contentSkip to conversation

use idr kernel library instead of handles

PATCH New Ernesto Ramos 1 participant 6 messages Jul 28, 2010 Staging

lore
Share & tools
lore
#0 lore raw

cover use idr kernel library instead of handles

From: Rene Sapiens <[email protected]>

Use idr kernel library to send/receive node and stream ids to the user instead of kernel address.
This id will be use to access the node and stream handles at the kernel side, if id does not match to any handle
error -EFAULT is returned.

For processor handle, dspbridge driver will make sure the handle is valid by using the handle stored in process context.

Ernesto Ramos (5):
staging:ti dspbridge: use node id instead of kernel address staging:ti dspbridge: avoid errors if node handle is zero staging:ti dspbridge: use processor handle from context instead of
user's
staging:ti dspbridge: use stream id instead of kernel address staging:ti dspbridge: avoid errors if stream id is zero

 .../staging/tidspbridge/include/dspbridge/drv.h    |   11 +-
 .../staging/tidspbridge/include/dspbridge/node.h   |   14 +-
 .../include/dspbridge/resourcecleanup.h            |   12 -
 .../staging/tidspbridge/include/dspbridge/strm.h   |   22 +-
 drivers/staging/tidspbridge/pmgr/dspapi.c          |  329 ++++++++++++++++----
 drivers/staging/tidspbridge/rmgr/drv.c             |  303 ++++++-------------
 drivers/staging/tidspbridge/rmgr/drv_interface.c   |   18 +-
 drivers/staging/tidspbridge/rmgr/node.c            |  109 ++++---
 drivers/staging/tidspbridge/rmgr/strm.c            |   54 ++--
 9 files changed, 485 insertions(+), 387 deletions(-)
#1 lore raw

PATCH 1/1 staging:ti dspbridge: use node id instead of kernel address

Use idr kernel library to send/receive node ids to the user instead of kernel address.
This id will be use to access the node handles at the kernel side, if id does not match to any handle error -EFAULT is returned.

---
 .../staging/tidspbridge/include/dspbridge/drv.h    |    6 +-
 .../staging/tidspbridge/include/dspbridge/node.h   |   14 +-
 .../include/dspbridge/resourcecleanup.h            |    6 -
 drivers/staging/tidspbridge/pmgr/dspapi.c          |  158 +++++++++++++++++---
 drivers/staging/tidspbridge/rmgr/drv.c             |  151 ++++++-------------
 drivers/staging/tidspbridge/rmgr/drv_interface.c   |    7 +-
 drivers/staging/tidspbridge/rmgr/node.c            |  109 +++++++-------
 7 files changed, 256 insertions(+), 195 deletions(-)
drivers/staging/tidspbridge/include/dspbridge/drv.h +3 -3
index 28541f7..0b36a11 100644
@@ -24,6 +24,7 @@
 #include <dspbridge/devdefs.h>
 
 #include <dspbridge/drvdefs.h>
+#include <linux/idr.h>
 
 #define DRV_ASSIGN     1
 #define DRV_RELEASE    0
@@ -81,7 +82,7 @@ struct node_res_object {
 	s32 node_allocated;	/* Node status */
 	s32 heap_allocated;	/* Heap status */
 	s32 streams_allocated;	/* Streams status */
-	struct node_res_object *next;
+	int id;
 };
 
 /* used to cache dma mapping information */
@@ -158,8 +159,7 @@ struct process_context {
 	void *hprocessor;
 
 	/* DSP Node resources */
-	struct node_res_object *node_list;
-	struct mutex node_mutex;
+	struct idr *node_id;
 
 	/* DMM mapped memory resources */
 	struct list_head dmm_map_list;
drivers/staging/tidspbridge/include/dspbridge/node.h +8 -6
index 61d2d9b..49ed5c1 100644
@@ -36,7 +36,7 @@
  *      pargs:              Optional arguments to be passed to the node.
  *      attr_in:            Optional pointer to node attributes (priority,
  *                          timeout...)
- *      ph_node:             Location to store node handle on output.
+ *      noderes:             Location to store node resource info.
  *  Returns:
  *      0:            Success.
  *      -ENOMEM:        Insufficient memory on GPP.
@@ -50,17 +50,17 @@
  *      node_init(void) called.
  *      hprocessor != NULL.
  *      node_uuid != NULL.
- *      ph_node != NULL.
+ *      noderes != NULL.
  *  Ensures:
  *      0:            IsValidNode(*ph_node).
- *      error:              *ph_node == NULL.
+ *      error:              *noderes == NULL.
  */
 extern int node_allocate(struct proc_object *hprocessor,
 				const struct dsp_uuid *node_uuid,
 				const struct dsp_cbdata
 				*pargs, const struct dsp_nodeattrin
 				*attr_in,
-				struct node_object **ph_node,
+				struct node_res_object **noderes,
 				struct process_context *pr_ctxt);
 
 /*
@@ -242,7 +242,9 @@ extern int node_create_mgr(struct node_mgr **node_man,
  *      delete function. Loads the node's delete function if necessary.
  *      GPP side resources are freed after node's delete function returns.
  *  Parameters:
- *      hnode:              Node handle returned from node_allocate().
+ *      noderes:              Node resource info handle returned from
+ *                                 node_allocate().
+ *      pr_ctxt:                Poninter to process context data.
  *  Returns:
  *      0:            Success.
  *      -EFAULT:        Invalid hnode.
@@ -254,7 +256,7 @@ extern int node_create_mgr(struct node_mgr **node_man,
  *  Ensures:
  *      0:            hnode is invalid.
  */
-extern int node_delete(struct node_object *hnode,
+extern int node_delete(struct node_res_object *noderes,
 			      struct process_context *pr_ctxt);
 
 /*
drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h +0 -6
index 4e1b8a2..d17c7fb 100644
@@ -34,17 +34,11 @@ extern int drv_remove_all_resources(void *process_ctxt);
 extern int drv_remove_proc_context(struct drv_object *driver_obj,
 					  void *pr_ctxt);
 
-extern int drv_get_node_res_element(void *hnode, void *node_resource,
-					   void *process_ctx);
-
 extern int drv_insert_node_res_element(void *hnode, void *node_resource,
 					      void *process_ctxt);
 
 extern void drv_proc_node_update_heap_status(void *node_resource, s32 status);
 
-extern int drv_remove_node_res_element(void *node_resource,
-						void *process_ctxt);
-
 extern void drv_proc_node_update_status(void *node_resource, s32 status);
 
 extern int drv_proc_update_strm_res(u32 num_bufs, void *strm_resources);
drivers/staging/tidspbridge/pmgr/dspapi.c +139 -19

308 lines not on this page · raw message

drivers/staging/tidspbridge/rmgr/drv.c +44 -109

189 lines not on this page · raw message

drivers/staging/tidspbridge/rmgr/drv_interface.c +6 -1
index aec7cf7..900cdd3 100644
@@ -511,8 +511,13 @@ static int bridge_open(struct inode *ip, struct file *filp)
 		INIT_LIST_HEAD(&pr_ctxt->dmm_map_list);
 		spin_lock_init(&pr_ctxt->dmm_rsv_lock);
 		INIT_LIST_HEAD(&pr_ctxt->dmm_rsv_list);
-		mutex_init(&pr_ctxt->node_mutex);
 		mutex_init(&pr_ctxt->strm_mutex);
+
+		pr_ctxt->node_id = kzalloc(sizeof(struct idr), GFP_KERNEL);
+		if (pr_ctxt->node_id)
+			idr_init(pr_ctxt->node_id);
+		else
+			status = -ENOMEM;
 	} else {
 		status = -ENOMEM;
 	}
drivers/staging/tidspbridge/rmgr/node.c +57 -52

242 lines not on this page · raw message

Signature · 1 line
1.5.4.5
#2 lore raw

PATCH 1/1 staging:ti dspbridge: avoid errors if node handle is zero

As 'zero' can be a perfectly good id, it can be picked up as a NULL from userspace, avoid issues in API and user apps if node handle is zero.

---
 drivers/staging/tidspbridge/pmgr/dspapi.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/staging/tidspbridge/pmgr/dspapi.c +4 -2
index 6eda7c5..f46aaf6 100644
@@ -1059,7 +1059,7 @@ inline void find_node_handle(struct node_res_object **noderes,
 {
 	rcu_read_lock();
 	*noderes = idr_find(((struct process_context *)pr_ctxt)->node_id,
-								(int)hnode);
+								(int)hnode - 1);
 	rcu_read_unlock();
 	return;
 }
@@ -1077,6 +1077,7 @@ u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)
 	u8 *pargs = NULL;
 	struct dsp_nodeattrin proc_attr_in, *attr_in = NULL;
 	struct node_res_object *node_res;
+	int nodeid;
 
 	/* Optional argument */
 	if (psize) {
@@ -1112,7 +1113,8 @@ u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)
 				       attr_in, &node_res, pr_ctxt);
 	}
 	if (!status) {
-		CP_TO_USR(args->args_node_allocate.ph_node, &node_res->id,
+		nodeid = node_res->id + 1;
+		CP_TO_USR(args->args_node_allocate.ph_node, &nodeid,
 			status, 1);
 		if (status) {
 			status = -EFAULT;
Signature · 1 line
1.5.4.5
#3 lore raw

PATCH 1/1 staging:ti dspbridge: use processor handle from context instead of user's

Make sure dspbridge driver uses a valid processor handle by using the handle stored in process context.

---
 drivers/staging/tidspbridge/pmgr/dspapi.c |   50 +++++++++++++++++------------
 1 files changed, 29 insertions(+), 21 deletions(-)
drivers/staging/tidspbridge/pmgr/dspapi.c +29 -21
index f46aaf6..d7613eb 100644
@@ -616,6 +616,7 @@ u32 procwrap_ctrl(union trapped_args *args, void *pr_ctxt)
 	    args->args_proc_ctrl.pargs;
 	u8 *pargs = NULL;
 	int status = 0;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
 	if (psize) {
 		if (get_user(cb_data_size, psize)) {
@@ -633,7 +634,7 @@ u32 procwrap_ctrl(union trapped_args *args, void *pr_ctxt)
 			  cb_data_size);
 	}
 	if (!status) {
-		status = proc_ctrl(args->args_proc_ctrl.hprocessor,
+		status = proc_ctrl(hprocessor,
 				   args->args_proc_ctrl.dw_cmd,
 				   (struct dsp_cbdata *)pargs);
 	}
@@ -663,11 +664,12 @@ u32 procwrap_enum_node_info(union trapped_args *args, void *pr_ctxt)
 	void *node_tab[MAX_NODES];
 	u32 num_nodes;
 	u32 alloc_cnt;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
 	if (!args->args_proc_enumnode_info.node_tab_size)
 		return -EINVAL;
 
-	status = proc_enum_nodes(args->args_proc_enumnode_info.hprocessor,
+	status = proc_enum_nodes(hprocessor,
 				 node_tab,
 				 args->args_proc_enumnode_info.node_tab_size,
 				 &num_nodes, &alloc_cnt);
@@ -747,13 +749,14 @@ u32 procwrap_enum_resources(union trapped_args *args, void *pr_ctxt)
 {
 	int status = 0;
 	struct dsp_resourceinfo resource_info;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
 	if (args->args_proc_enumresources.resource_info_size <
 	    sizeof(struct dsp_resourceinfo))
 		return -EINVAL;
 
 	status =
-	    proc_get_resource_info(args->args_proc_enumresources.hprocessor,
+	    proc_get_resource_info(hprocessor,
 				   args->args_proc_enumresources.resource_type,
 				   &resource_info,
 				   args->args_proc_enumresources.
@@ -773,13 +776,13 @@ u32 procwrap_get_state(union trapped_args *args, void *pr_ctxt)
 {
 	int status;
 	struct dsp_processorstate proc_state;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
 	if (args->args_proc_getstate.state_info_size <
 	    sizeof(struct dsp_processorstate))
 		return -EINVAL;
 
-	status =
-	    proc_get_state(args->args_proc_getstate.hprocessor, &proc_state,
+	status = proc_get_state(hprocessor, &proc_state,
 			   args->args_proc_getstate.state_info_size);
 	CP_TO_USR(args->args_proc_getstate.proc_state_obj, &proc_state, status,
 		  1);
@@ -794,14 +797,14 @@ u32 procwrap_get_trace(union trapped_args *args, void *pr_ctxt)
 {
 	int status;
 	u8 *pbuf;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
 	if (args->args_proc_gettrace.max_size > MAX_TRACEBUFLEN)
 		return -EINVAL;
 
 	pbuf = kzalloc(args->args_proc_gettrace.max_size, GFP_KERNEL);
 	if (pbuf != NULL) {
-		status = proc_get_trace(args->args_proc_gettrace.hprocessor,
-					pbuf,
+		status = proc_get_trace(hprocessor, pbuf,
 					args->args_proc_gettrace.max_size);
 	} else {
 		status = -ENOMEM;
@@ -823,6 +826,7 @@ u32 procwrap_load(union trapped_args *args, void *pr_ctxt)
 	char *temp;
 	s32 count = args->args_proc_load.argc_index;
 	u8 **argv = NULL, **envp = NULL;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
 	if (count <= 0 || count > MAX_LOADARGS) {
 		status = -EINVAL;
@@ -905,7 +909,7 @@ u32 procwrap_load(union trapped_args *args, void *pr_ctxt)
 	}
 
 	if (!status) {
-		status = proc_load(args->args_proc_load.hprocessor,
+		status = proc_load(hprocessor,
 				   args->args_proc_load.argc_index,
 				   (const char **)argv, (const char **)envp);
 	}
@@ -936,6 +940,7 @@ u32 procwrap_map(union trapped_args *args, void *pr_ctxt)
 {
 	int status;
 	void *map_addr;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
 	if (!args->args_proc_mapmem.ul_size)
 		return -EINVAL;
@@ -948,8 +953,7 @@ u32 procwrap_map(union trapped_args *args, void *pr_ctxt)
 	if (!status) {
 		if (put_user(map_addr, args->args_proc_mapmem.pp_map_addr)) {
 			status = -EINVAL;
-			proc_un_map(args->args_proc_mapmem.hprocessor,
-				    map_addr, pr_ctxt);
+			proc_un_map(hprocessor, map_addr, pr_ctxt);
 		}
 
 	}
@@ -963,13 +967,13 @@ u32 procwrap_register_notify(union trapped_args *args, void *pr_ctxt)
 {
 	int status;
 	struct dsp_notification notification;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
 	/* Initialize the notification data structure */
 	notification.ps_name = NULL;
 	notification.handle = NULL;
 
-	status =
-	    proc_register_notify(args->args_proc_register_notify.hprocessor,
+	status = proc_register_notify(hprocessor,
 				 args->args_proc_register_notify.event_mask,
 				 args->args_proc_register_notify.notify_type,
 				 &notification);
@@ -985,12 +989,13 @@ u32 procwrap_reserve_memory(union trapped_args *args, void *pr_ctxt)
 {
 	int status;
 	void *prsv_addr;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
 	if ((args->args_proc_rsvmem.ul_size <= 0) ||
 	    (args->args_proc_rsvmem.ul_size & (PG_SIZE4K - 1)) != 0)
 		return -EINVAL;
 
-	status = proc_reserve_memory(args->args_proc_rsvmem.hprocessor,
+	status = proc_reserve_memory(hprocessor,
 				     args->args_proc_rsvmem.ul_size, &prsv_addr,
 				     pr_ctxt);
 	if (!status) {
@@ -1010,7 +1015,7 @@ u32 procwrap_start(union trapped_args *args, void *pr_ctxt)
 {
 	u32 ret;
 
-	ret = proc_start(args->args_proc_start.hprocessor);
+	ret = proc_start(((struct process_context *)pr_ctxt)->hprocessor);
 	return ret;
 }
 
@@ -1021,7 +1026,7 @@ u32 procwrap_un_map(union trapped_args *args, void *pr_ctxt)
 {
 	int status;
 
-	status = proc_un_map(args->args_proc_unmapmem.hprocessor,
+	status = proc_un_map(((struct process_context *)pr_ctxt)->hprocessor,
 			     args->args_proc_unmapmem.map_addr, pr_ctxt);
 	return status;
 }
@@ -1032,8 +1037,9 @@ u32 procwrap_un_map(union trapped_args *args, void *pr_ctxt)
 u32 procwrap_un_reserve_memory(union trapped_args *args, void *pr_ctxt)
 {
 	int status;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
-	status = proc_un_reserve_memory(args->args_proc_unrsvmem.hprocessor,
+	status = proc_un_reserve_memory(hprocessor,
 					args->args_proc_unrsvmem.prsv_addr,
 					pr_ctxt);
 	return status;
@@ -1046,7 +1052,7 @@ u32 procwrap_stop(union trapped_args *args, void *pr_ctxt)
 {
 	u32 ret;
 
-	ret = proc_stop(args->args_proc_stop.hprocessor);
+	ret = proc_stop(((struct process_context *)pr_ctxt)->hprocessor);
 
 	return ret;
 }
@@ -1078,6 +1084,7 @@ u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)
 	struct dsp_nodeattrin proc_attr_in, *attr_in = NULL;
 	struct node_res_object *node_res;
 	int nodeid;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
 	/* Optional argument */
 	if (psize) {
@@ -1108,7 +1115,7 @@ u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)
 
 	}
 	if (!status) {
-		status = node_allocate(args->args_node_allocate.hprocessor,
+		status = node_allocate(hprocessor,
 				       &node_uuid, (struct dsp_cbdata *)pargs,
 				       attr_in, &node_res, pr_ctxt);
 	}
@@ -1493,6 +1500,7 @@ u32 nodewrap_get_uuid_props(union trapped_args *args, void *pr_ctxt)
 	int status = 0;
 	struct dsp_uuid node_uuid;
 	struct dsp_ndbprops *pnode_props = NULL;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
 	CP_FM_USR(&node_uuid, args->args_node_getuuidprops.node_id_ptr, status,
 		  1);
@@ -1501,8 +1509,7 @@ u32 nodewrap_get_uuid_props(union trapped_args *args, void *pr_ctxt)
 	pnode_props = kmalloc(sizeof(struct dsp_ndbprops), GFP_KERNEL);
 	if (pnode_props != NULL) {
 		status =
-		    node_get_uuid_props(args->args_node_getuuidprops.hprocessor,
-					&node_uuid, pnode_props);
+		    node_get_uuid_props(hprocessor, &node_uuid, pnode_props);
 		CP_TO_USR(args->args_node_getuuidprops.node_props, pnode_props,
 			  status, 1);
 	} else
@@ -1788,8 +1795,9 @@ u32 cmmwrap_get_handle(union trapped_args *args, void *pr_ctxt)
 {
 	int status = 0;
 	struct cmm_object *hcmm_mgr;
+	void *hprocessor = ((struct process_context *)pr_ctxt)->hprocessor;
 
-	status = cmm_get_handle(args->args_cmm_gethandle.hprocessor, &hcmm_mgr);
+	status = cmm_get_handle(hprocessor, &hcmm_mgr);
 
 	CP_TO_USR(args->args_cmm_gethandle.ph_cmm_mgr, &hcmm_mgr, status, 1);
 
Signature · 1 line
1.5.4.5
#4 lore raw

PATCH 1/1 staging:ti dspbridge: use stream id instead of kernel address

Send stream ids to the user instead of handles, then when the id is coming from user dspbridge can retrive the handle using id and avoid using invalid handles.

---
 .../staging/tidspbridge/include/dspbridge/drv.h    |    5 +-
 .../include/dspbridge/resourcecleanup.h            |    6 -
 .../staging/tidspbridge/include/dspbridge/strm.h   |   22 ++--
 drivers/staging/tidspbridge/pmgr/dspapi.c          |  115 +++++++++++++---
 drivers/staging/tidspbridge/rmgr/drv.c             |  148 +++++++-------------
 drivers/staging/tidspbridge/rmgr/drv_interface.c   |   13 ++-
 drivers/staging/tidspbridge/rmgr/strm.c            |   54 +++----
 7 files changed, 193 insertions(+), 170 deletions(-)
drivers/staging/tidspbridge/include/dspbridge/drv.h +2 -3
index 0b36a11..f365015 100644
@@ -131,7 +131,7 @@ struct strm_res_object {
 	void *hstream;
 	u32 num_bufs;
 	u32 dir;
-	struct strm_res_object *next;
+	int id;
 };
 
 /* Overall Bridge process resource usage state */
@@ -173,8 +173,7 @@ struct process_context {
 	struct dspheap_res_object *pdspheap_list;
 
 	/* Stream resources */
-	struct strm_res_object *pstrm_list;
-	struct mutex strm_mutex;
+	struct idr *stream_id;
 };
 
 /*
drivers/staging/tidspbridge/include/dspbridge/resourcecleanup.h +0 -6
index d17c7fb..dfaf0c6 100644
@@ -47,12 +47,6 @@ extern int drv_proc_insert_strm_res_element(void *stream_obj,
 						   void *strm_res,
 						   void *process_ctxt);
 
-extern int drv_get_strm_res_element(void *stream_obj, void *strm_resources,
-					   void *process_ctxt);
-
-extern int drv_proc_remove_strm_res_element(void *strm_res,
-						   void *process_ctxt);
-
 extern int drv_remove_all_strm_res_elements(void *process_ctxt);
 
 extern enum node_state node_get_state(void *hnode);
drivers/staging/tidspbridge/include/dspbridge/strm.h +11 -11
index 0ddc797..3e4671e 100644
@@ -29,7 +29,7 @@
  *  Purpose:
  *      Allocate data buffer(s) for use with a stream.
  *  Parameter:
- *      stream_obj:     Stream handle returned from strm_open().
+ *      strmres:     Stream resource info handle returned from strm_open().
  *      usize:          Size (GPP bytes) of the buffer(s).
  *      num_bufs:       Number of buffers to allocate.
  *      ap_buffer:       Array to hold buffer addresses.
@@ -44,7 +44,7 @@
  *      ap_buffer != NULL.
  *  Ensures:
  */
-extern int strm_allocate_buffer(struct strm_object *stream_obj,
+extern int strm_allocate_buffer(struct strm_res_object *strmres,
 				       u32 usize,
 				       u8 **ap_buffer,
 				       u32 num_bufs,
@@ -55,7 +55,7 @@ extern int strm_allocate_buffer(struct strm_object *stream_obj,
  *  Purpose:
  *      Close a stream opened with strm_open().
  *  Parameter:
- *      stream_obj:          Stream handle returned from strm_open().
+ *      strmres:          Stream resource info handle returned from strm_open().
  *  Returns:
  *      0:        Success.
  *      -EFAULT:    Invalid stream_obj.
@@ -66,7 +66,7 @@ extern int strm_allocate_buffer(struct strm_object *stream_obj,
  *      strm_init(void) called.
  *  Ensures:
  */
-extern int strm_close(struct strm_object *stream_obj,
+extern int strm_close(struct strm_res_object *strmres,
 			     struct process_context *pr_ctxt);
 
 /*
@@ -125,7 +125,7 @@ extern void strm_exit(void);
  *  Purpose:
  *      Free buffer(s) allocated with strm_allocate_buffer.
  *  Parameter:
- *      stream_obj:     Stream handle returned from strm_open().
+ *      strmres:     Stream resource info handle returned from strm_open().
  *      ap_buffer:       Array containing buffer addresses.
  *      num_bufs:       Number of buffers to be freed.
  *  Returns:
@@ -137,7 +137,7 @@ extern void strm_exit(void);
  *      ap_buffer != NULL.
  *  Ensures:
  */
-extern int strm_free_buffer(struct strm_object *stream_obj,
+extern int strm_free_buffer(struct strm_res_object *strmres,
 				   u8 **ap_buffer, u32 num_bufs,
 				   struct process_context *pr_ctxt);
 
@@ -254,7 +254,7 @@ extern int strm_issue(struct strm_object *stream_obj, u8 * pbuf,
  *      index:         Stream index.
  *      pattr:          Pointer to structure containing attributes to be
  *                      applied to stream. Cannot be NULL.
- *      strm_objct:     Location to store stream handle on output.
+ *      strmres:     Location to store stream resuorce info handle on output.
  *  Returns:
  *      0:        Success.
  *      -EFAULT:    Invalid hnode.
@@ -264,15 +264,15 @@ extern int strm_issue(struct strm_object *stream_obj, u8 * pbuf,
  *      -EINVAL:     Invalid index.
  *  Requires:
  *      strm_init(void) called.
- *      strm_objct != NULL.
+ *      strmres != NULL.
  *      pattr != NULL.
  *  Ensures:
- *      0:        *strm_objct is valid.
- *      error:          *strm_objct == NULL.
+ *      0:        *strmres is valid.
+ *      error:          *strmres == NULL.
  */
 extern int strm_open(struct node_object *hnode, u32 dir,
 			    u32 index, struct strm_attr *pattr,
-			    struct strm_object **strm_objct,
+			    struct strm_res_object **strmres,
 			    struct process_context *pr_ctxt);
 
 /*
drivers/staging/tidspbridge/pmgr/dspapi.c +98 -17

230 lines not on this page · raw message

drivers/staging/tidspbridge/rmgr/drv.c +47 -99

177 lines not on this page · raw message

drivers/staging/tidspbridge/rmgr/drv_interface.c +10 -3
index 900cdd3..7ee8949 100644
@@ -511,17 +511,24 @@ static int bridge_open(struct inode *ip, struct file *filp)
 		INIT_LIST_HEAD(&pr_ctxt->dmm_map_list);
 		spin_lock_init(&pr_ctxt->dmm_rsv_lock);
 		INIT_LIST_HEAD(&pr_ctxt->dmm_rsv_list);
-		mutex_init(&pr_ctxt->strm_mutex);
 
 		pr_ctxt->node_id = kzalloc(sizeof(struct idr), GFP_KERNEL);
-		if (pr_ctxt->node_id)
+		if (pr_ctxt->node_id) {
 			idr_init(pr_ctxt->node_id);
+		} else {
+			status = -ENOMEM;
+			goto err;
+		}
+
+		pr_ctxt->stream_id = kzalloc(sizeof(struct idr), GFP_KERNEL);
+		if (pr_ctxt->stream_id)
+			idr_init(pr_ctxt->stream_id);
 		else
 			status = -ENOMEM;
 	} else {
 		status = -ENOMEM;
 	}
-
+err:
 	filp->private_data = pr_ctxt;
 #ifdef CONFIG_TIDSPBRIDGE_RECOVERY
 	if (!status)
drivers/staging/tidspbridge/rmgr/strm.c +24 -30

139 lines not on this page · raw message

Signature · 1 line
1.5.4.5
#5 lore raw

PATCH 1/1 staging:ti dspbridge: avoid errors if stream id is zero

As 'zero' can be a perfectly good id, it can be picked up as a NULL from userspace, avoid issues in API and user apps if stream handle is zero.

---
 drivers/staging/tidspbridge/pmgr/dspapi.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/staging/tidspbridge/pmgr/dspapi.c +6 -2
index 47892dd..7b42f72 100644
@@ -1527,7 +1527,7 @@ inline void find_strm_handle(struct strm_res_object **strmres,
 {
 	rcu_read_lock();
 	*strmres = idr_find(((struct process_context *)pr_ctxt)->stream_id,
-							(int)hstream);
+							(int)hstream - 1);
 	rcu_read_unlock();
 	return;
 }
@@ -1724,6 +1724,7 @@ u32 strmwrap_open(union trapped_args *args, void *pr_ctxt)
 	struct strm_res_object *strm_res_obj;
 	struct dsp_streamattrin strm_attr_in;
 	struct node_res_object *node_res;
+	int strmid;
 
 	find_node_handle(&node_res, pr_ctxt, args->args_strm_open.hnode);
 
@@ -1745,7 +1746,10 @@ u32 strmwrap_open(union trapped_args *args, void *pr_ctxt)
 			   args->args_strm_open.direction,
 			   args->args_strm_open.index, &attr, &strm_res_obj,
 			   pr_ctxt);
-	CP_TO_USR(args->args_strm_open.ph_stream, &strm_res_obj->id, status, 1);
+	if (!status) {
+		strmid = strm_res_obj->id + 1;
+		CP_TO_USR(args->args_strm_open.ph_stream, &strmid, status, 1);
+	}
 	return status;
 }
 
Signature · 1 line
1.5.4.5