Commit c811c05d authored by Hari Kanigeri's avatar Hari Kanigeri

SYSLINK-Proc-fixes in proc4430 driver

This patch handles the following.
   - Calling the proc4430 setup multiple twice.
   - Fixes the bugs in proc4430 create function that were
     causing segmentation fault.
   - Handled wrong check for return value of kmalloc.
Signed-off-by: default avatarHari Kanigeri <h-kanigeri2@ti.com>
Signed-off-by: default avatarArun Radhakrishnan <x0051460@ti.com>
parent eee91af6
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/uaccess.h>
/* Module level headers */ /* Module level headers */
#include "../procdefs.h" #include "../procdefs.h"
...@@ -125,6 +126,7 @@ int proc4430_setup(struct proc4430_config *cfg) ...@@ -125,6 +126,7 @@ int proc4430_setup(struct proc4430_config *cfg)
proc4430_get_config(&tmp_cfg); proc4430_get_config(&tmp_cfg);
cfg = &tmp_cfg; cfg = &tmp_cfg;
} }
if (proc4430_state.is_setup == false) {
dmm_create(); dmm_create();
dmm_create_tables(DUCATI_DMM_START_ADDR, DUCATI_DMM_POOL_SIZE); dmm_create_tables(DUCATI_DMM_START_ADDR, DUCATI_DMM_POOL_SIZE);
if (cfg->gate_handle != NULL) { if (cfg->gate_handle != NULL) {
...@@ -132,17 +134,19 @@ int proc4430_setup(struct proc4430_config *cfg) ...@@ -132,17 +134,19 @@ int proc4430_setup(struct proc4430_config *cfg)
} else { } else {
/* User has not provided any gate handle, so create a /* User has not provided any gate handle, so create a
* default handle. */ * default handle. */
proc4430_state.gate_handle = kmalloc(sizeof(struct mutex), proc4430_state.gate_handle =
GFP_KERNEL); kmalloc(sizeof(struct mutex), GFP_KERNEL);
mutex_init(proc4430_state.gate_handle); mutex_init(proc4430_state.gate_handle);
ducati_setup(); ducati_setup();
} }
/* Copy the user provided values into the state object. */
memcpy(&proc4430_state.cfg, cfg,
sizeof(struct proc4430_config));
/* Initialize the name to handles mapping array. */ /* Initialize the name to handles mapping array. */
memset(&proc4430_state.proc_handles, 0, memset(&proc4430_state.proc_handles, 0,
(sizeof(void *) * MULTIPROC_MAXPROCESSORS)); (sizeof(void *) * MULTIPROC_MAXPROCESSORS));
proc4430_state.is_setup = true;
}
/* Copy the user provided values into the state object. */
memcpy(&proc4430_state.cfg, cfg,
sizeof(struct proc4430_config));
return retval; return retval;
} }
EXPORT_SYMBOL(proc4430_setup); EXPORT_SYMBOL(proc4430_setup);
...@@ -218,11 +222,13 @@ void *proc4430_create(u16 proc_id, const struct proc4430_params *params) ...@@ -218,11 +222,13 @@ void *proc4430_create(u16 proc_id, const struct proc4430_params *params)
printk(KERN_WARNING "Processor already exists for specified" printk(KERN_WARNING "Processor already exists for specified"
"%d proc_id\n", proc_id); "%d proc_id\n", proc_id);
WARN_ON(1); WARN_ON(1);
handle = proc4430_state.proc_handles[proc_id];
goto func_end; goto func_end;
} else { } else {
handle = (struct processor_object *) handle = (struct processor_object *)
vmalloc(sizeof(struct processor_object)); vmalloc(sizeof(struct processor_object));
if (handle == NULL) { if (WARN_ON(handle == NULL))
goto func_end;
handle->proc_fxn_table.attach = &proc4430_attach; handle->proc_fxn_table.attach = &proc4430_attach;
handle->proc_fxn_table.detach = &proc4430_detach; handle->proc_fxn_table.detach = &proc4430_detach;
handle->proc_fxn_table.start = &proc4430_start; handle->proc_fxn_table.start = &proc4430_start;
...@@ -237,25 +243,25 @@ void *proc4430_create(u16 proc_id, const struct proc4430_params *params) ...@@ -237,25 +243,25 @@ void *proc4430_create(u16 proc_id, const struct proc4430_params *params)
handle->state = PROC_MGR_STATE_UNKNOWN; handle->state = PROC_MGR_STATE_UNKNOWN;
handle->object = vmalloc handle->object = vmalloc
(sizeof(struct proc4430_object)); (sizeof(struct proc4430_object));
handle->proc_id = proc_id; handle->proc_id = proc_id;
object = (struct proc4430_object *)handle->object; object = (struct proc4430_object *)handle->object;
/* Copy params into instance object. */ /* Copy params into instance object. */
memcpy(&(object->params), (void *)params, memcpy(&(object->params), (void *)params,
sizeof(struct proc4430_object)); sizeof(struct proc4430_object));
if (params->mem_entries != NULL &&
params->num_mem_entries > 0) {
/* Allocate memory for, and copy memEntries table*/ /* Allocate memory for, and copy memEntries table*/
object->params.mem_entries = vmalloc( object->params.mem_entries = vmalloc(
sizeof(struct proc4430_mem_entry) * sizeof(struct proc4430_mem_entry) *
params->num_mem_entries); params->num_mem_entries);
memcpy(object->params.mem_entries, copy_from_user(object->params.mem_entries,
params->mem_entries, params->mem_entries,
(sizeof(struct proc4430_mem_entry) (sizeof(struct proc4430_mem_entry)
* params->num_mem_entries)); * params->num_mem_entries));
}
/* Set the handle in the state object. */ /* Set the handle in the state object. */
proc4430_state.proc_handles[proc_id] = handle; proc4430_state.proc_handles[proc_id] = handle;
} }
}
func_end: func_end:
mutex_unlock(proc4430_state.gate_handle); mutex_unlock(proc4430_state.gate_handle);
return handle; return handle;
......
...@@ -59,7 +59,7 @@ struct proc4430_mem_entry { ...@@ -59,7 +59,7 @@ struct proc4430_mem_entry {
Configuration parameters specific to this processor. Configuration parameters specific to this processor.
*/ */
struct proc4430_params { struct proc4430_params {
u32 num_mem_entries; int num_mem_entries;
/* Number of memory regions to be configured. */ /* Number of memory regions to be configured. */
struct proc4430_mem_entry *mem_entries; struct proc4430_mem_entry *mem_entries;
/* Array of information structures for memory regions /* Array of information structures for memory regions
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment