Commit 31ba0ef8 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 8580a48a
...@@ -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,24 +126,27 @@ int proc4430_setup(struct proc4430_config *cfg) ...@@ -125,24 +126,27 @@ int proc4430_setup(struct proc4430_config *cfg)
proc4430_get_config(&tmp_cfg); proc4430_get_config(&tmp_cfg);
cfg = &tmp_cfg; cfg = &tmp_cfg;
} }
dmm_create(); if (proc4430_state.is_setup == false) {
dmm_create_tables(DUCATI_DMM_START_ADDR, DUCATI_DMM_POOL_SIZE); dmm_create();
if (cfg->gate_handle != NULL) { dmm_create_tables(DUCATI_DMM_START_ADDR, DUCATI_DMM_POOL_SIZE);
proc4430_state.gate_handle = cfg->gate_handle; if (cfg->gate_handle != NULL) {
} else { proc4430_state.gate_handle = cfg->gate_handle;
/* User has not provided any gate handle, so create a } else {
* default handle. */ /* User has not provided any gate handle, so create a
proc4430_state.gate_handle = kmalloc(sizeof(struct mutex), * default handle. */
GFP_KERNEL); proc4430_state.gate_handle =
mutex_init(proc4430_state.gate_handle); kmalloc(sizeof(struct mutex), GFP_KERNEL);
ducati_setup(); mutex_init(proc4430_state.gate_handle);
ducati_setup();
}
/* Initialize the name to handles mapping array. */
memset(&proc4430_state.proc_handles, 0,
(sizeof(void *) * MULTIPROC_MAXPROCESSORS));
proc4430_state.is_setup = true;
} }
/* Copy the user provided values into the state object. */ /* Copy the user provided values into the state object. */
memcpy(&proc4430_state.cfg, cfg, memcpy(&proc4430_state.cfg, cfg,
sizeof(struct proc4430_config)); sizeof(struct proc4430_config));
/* Initialize the name to handles mapping array. */
memset(&proc4430_state.proc_handles, 0,
(sizeof(void *) * MULTIPROC_MAXPROCESSORS));
return retval; return retval;
} }
EXPORT_SYMBOL(proc4430_setup); EXPORT_SYMBOL(proc4430_setup);
...@@ -218,43 +222,45 @@ void *proc4430_create(u16 proc_id, const struct proc4430_params *params) ...@@ -218,43 +222,45 @@ 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))
handle->proc_fxn_table.attach = &proc4430_attach; goto func_end;
handle->proc_fxn_table.detach = &proc4430_detach; handle->proc_fxn_table.attach = &proc4430_attach;
handle->proc_fxn_table.start = &proc4430_start; handle->proc_fxn_table.detach = &proc4430_detach;
handle->proc_fxn_table.stop = &proc4430_stop; handle->proc_fxn_table.start = &proc4430_start;
handle->proc_fxn_table.read = &proc4430_read; handle->proc_fxn_table.stop = &proc4430_stop;
handle->proc_fxn_table.write = &proc4430_write; handle->proc_fxn_table.read = &proc4430_read;
handle->proc_fxn_table.control = &proc4430_control; handle->proc_fxn_table.write = &proc4430_write;
handle->proc_fxn_table.translateAddr = handle->proc_fxn_table.control = &proc4430_control;
&proc4430_translate_addr; handle->proc_fxn_table.translateAddr =
handle->proc_fxn_table.map = &proc4430_map; &proc4430_translate_addr;
handle->proc_fxn_table.unmap = &proc4430_unmap; handle->proc_fxn_table.map = &proc4430_map;
handle->state = PROC_MGR_STATE_UNKNOWN; handle->proc_fxn_table.unmap = &proc4430_unmap;
handle->object = vmalloc handle->state = PROC_MGR_STATE_UNKNOWN;
(sizeof(struct proc4430_object)); handle->object = vmalloc
(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. */
proc4430_state.proc_handles[proc_id] = handle;
} }
/* Set the handle in the state object. */
proc4430_state.proc_handles[proc_id] = handle;
} }
func_end: func_end:
mutex_unlock(proc4430_state.gate_handle); mutex_unlock(proc4430_state.gate_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