Commit bda097a3 authored by Arun Gopalakrishnan's avatar Arun Gopalakrishnan Committed by Hari Kanigeri

IPC SharedRegion module fixes

The changes are
1. The ioctl interface is modified based on review comment
   to make it consistest with other ipc modules(e.g messageq)
2. All the ioctl commands were made as IOWR commands
3. Debug prints were added in all the APIs failure return
Signed-off-by: default avatarArun M G <arunmg@ti.com>
parent 0d24eb5f
......@@ -53,18 +53,19 @@ enum CMD_SHAREDREGION {
/*
* Command for sharedregion_setup
*/
#define CMD_SHAREDREGION_SETUP _IOW(IPC_IOC_MAGIC, \
#define CMD_SHAREDREGION_SETUP _IOWR(IPC_IOC_MAGIC, \
SHAREDREGION_SETUP, \
struct sharedregion_cmd_args)
/*
* Command for sharedregion_setup
*/
#define CMD_SHAREDREGION_DESTROY _IO(IPC_IOC_MAGIC, \
SHAREDREGION_DESTROY)
#define CMD_SHAREDREGION_DESTROY _IOWR(IPC_IOC_MAGIC, \
SHAREDREGION_DESTROY, \
struct sharedregion_cmd_args)
/*
* Command for sharedregion_ADD
*/
#define CMD_SHAREDREGION_ADD _IOW(IPC_IOC_MAGIC, \
#define CMD_SHAREDREGION_ADD _IOWR(IPC_IOC_MAGIC, \
SHAREDREGION_ADD, \
struct sharedregion_cmd_args)
/*
......@@ -91,13 +92,13 @@ enum CMD_SHAREDREGION {
/*
* Command for sharedregion_remove
*/
#define CMD_SHAREDREGION_REMOVE _IOW(IPC_IOC_MAGIC, \
#define CMD_SHAREDREGION_REMOVE _IOWR(IPC_IOC_MAGIC, \
SHAREDREGION_REMOVE, \
struct sharedregion_cmd_args)
/*
* Command for sharedregion_set_table_info
*/
#define CMD_SHAREDREGION_SETTABLEINFO _IOW(IPC_IOC_MAGIC, \
#define CMD_SHAREDREGION_SETTABLEINFO _IOWR(IPC_IOC_MAGIC, \
SHAREDREGION_SETTABLEINFO, \
struct sharedregion_cmd_args)
......@@ -163,7 +164,7 @@ union sharedregion_arg {
* Command arguments for sharedregion
*/
struct sharedregion_cmd_args {
union sharedregion_arg cmd_arg;
union sharedregion_arg args;
s32 api_status;
};
......
......@@ -16,7 +16,7 @@
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/slab.h>
......@@ -32,7 +32,7 @@
* Module state object
*/
struct sharedregion_object {
void *gate_handle;
struct mutex *gate_handle;
struct sharedregion_info *table; /* Ptr to the table */
u32 bitOffset; /* Index bit offset */
u32 region_size; /* Max size of each region */
......@@ -55,14 +55,12 @@ static struct sharedregion_object sharedregion_state = {
*/
int sharedregion_get_config(struct sharedregion_config *config)
{
gt_1trace(sharedregion_mask, GT_ENTER,
"sharedregion_get_config:\n config: %x \n", config);
BUG_ON((config == NULL));
memcpy(config, &sharedregion_state.cfg,
sizeof(struct sharedregion_config));
return 0;
}
EXPORT_SYMBOL(sharedregion_get_config);
/*
......@@ -97,8 +95,6 @@ int sharedregion_setup(const struct sharedregion_config *config)
s32 retval = 0;
u16 proc_count;
gt_1trace(sharedregion_mask, GT_ENTER,
"sharedregion_setup:\n config: %x \n", config);
if (config != NULL) {
if (WARN_ON(config->max_regions == 0)) {
retval = -EINVAL;
......@@ -147,8 +143,10 @@ gate_create_fail:
sharedregion_state.cfg.max_regions = SHAREDREGION_MAX_REGIONS_DEFAULT;
error:
printk(KERN_ERR "sharedregion_setup failed status:%x\n", retval);
return retval;
}
EXPORT_SYMBOL(sharedregion_setup);
/*
* ======== sharedregion_destroy ========
......@@ -160,7 +158,6 @@ int sharedregion_destroy(void)
s32 retval = 0;
void *gate_handle = NULL;
gt_0trace(sharedregion_mask, GT_ENTER, "sharedregion_destroy: \n");
if (WARN_ON(sharedregion_state.table == NULL)) {
retval = -ENODEV;
goto error;
......@@ -179,8 +176,10 @@ int sharedregion_destroy(void)
return 0;
error:
printk(KERN_ERR "sharedregion_destroy failed status:%x\n", retval);
return retval;
}
EXPORT_SYMBOL(sharedregion_destroy);
/*
* ======== sharedregion_add ========
......@@ -197,9 +196,6 @@ int sharedregion_add(u32 index, void *base, u32 len)
u16 myproc_id;
bool overlap = false;
gt_3trace(sharedregion_mask, GT_ENTER, "sharedregion_add:\n"
" index: %x base: %x,\n len: %x", index, base, len);
if (WARN_ON(sharedregion_state.table == NULL)) {
retval = -ENODEV;
goto error;
......@@ -262,8 +258,10 @@ mem_overlap_error:
mutex_unlock(sharedregion_state.gate_handle);
error:
printk(KERN_ERR "sharedregion_add failed status:%x\n", retval);
return retval;
}
EXPORT_SYMBOL(sharedregion_add);
/*
* ======== sharedregion_remove ========
......@@ -277,8 +275,6 @@ int sharedregion_remove(u32 index)
struct sharedregion_info *table = NULL;
s32 retval = 0;
gt_1trace(sharedregion_mask, GT_ENTER,
"sharedregion_remove:\n index: %x \n", index);
if (WARN_ON(sharedregion_state.table == NULL)) {
retval = -ENODEV;
goto error;
......@@ -302,9 +298,10 @@ int sharedregion_remove(u32 index)
return 0;
error:
printk(KERN_ERR "sharedregion_remove failed status:%x\n", retval);
return retval;
}
EXPORT_SYMBOL(sharedregion_remove);
/*
* ======== sharedregion_get_index ========
......@@ -320,8 +317,6 @@ int sharedregion_get_index(void *addr)
u16 myproc_id;
s32 retval = 0;
gt_1trace(sharedregion_mask, GT_ENTER,
"sharedregion_get_index:\n addr: %x \n", addr);
if (WARN_ON(sharedregion_state.table == NULL)) {
retval = -ENODEV;
goto exit;
......@@ -352,8 +347,10 @@ int sharedregion_get_index(void *addr)
mutex_unlock(sharedregion_state.gate_handle);
exit:
printk(KERN_ERR "sharedregion_get_index failed status:%x\n", retval);
return retval;
}
EXPORT_SYMBOL(sharedregion_get_index);
/*
* ======== sharedregion_get_ptr ========
......@@ -368,8 +365,6 @@ void *sharedregion_get_ptr(u32 *srptr)
u16 myproc_id;
s32 retval = 0;
gt_1trace(sharedregion_mask, GT_ENTER,
"sharedregion_get_ptr:\n srptr: %x \n", srptr);
if (WARN_ON(sharedregion_state.table == NULL))
goto error;
......@@ -391,9 +386,11 @@ void *sharedregion_get_ptr(u32 *srptr)
return ptr;
error:
printk(KERN_ERR "sharedregion_get_ptr failed \n");
return (void *)NULL;
}
EXPORT_SYMBOL(sharedregion_get_ptr);
/*
* ======== sharedregion_get_srptr ========
......@@ -409,9 +406,6 @@ u32 *sharedregion_get_srptr(void *addr, s32 index)
u32 myproc_id;
s32 retval = 0;
gt_2trace(sharedregion_mask, GT_ENTER,
"sharedregion_get_srptr:\n"
"addr: %x, index: %x \n", addr, index);
if (WARN_ON(sharedregion_state.table == NULL))
goto error;
......@@ -435,8 +429,10 @@ u32 *sharedregion_get_srptr(void *addr, s32 index)
return ptr;
error:
printk(KERN_ERR "sharedregion_get_srptr failed\n");
return (u32 *)NULL;
}
EXPORT_SYMBOL(sharedregion_get_srptr);
/*
* ======== sharedregion_get_table_info ========
......@@ -452,10 +448,6 @@ int sharedregion_get_table_info(u32 index, u16 proc_id,
u16 proc_count;
s32 retval = 0;
gt_3trace(sharedregion_mask, GT_ENTER,
"sharedregion_get_table_info:\n"
"index: %x, proc_id: %x,\n info: %x \n",
index, proc_id, info);
BUG_ON(info != NULL);
if (WARN_ON(sharedregion_state.table == NULL)) {
retval = -ENODEV;
......@@ -482,8 +474,11 @@ int sharedregion_get_table_info(u32 index, u16 proc_id,
return 0;
error:
printk(KERN_ERR "sharedregion_get_table_info failed status:%x\n",
retval);
return retval;
}
EXPORT_SYMBOL(sharedregion_get_table_info);
/*
* ======== sharedregion_set_table_info ========
......@@ -499,10 +494,6 @@ int sharedregion_set_table_info(u32 index, u16 proc_id,
u16 proc_count;
s32 retval = 0;
gt_3trace(sharedregion_mask, GT_ENTER,
"sharedregion_set_table_info:\n"
"index: %x, proc_id: %x,\n info: %x \n",
index, proc_id, info);
BUG_ON(info != NULL);
if (WARN_ON(sharedregion_state.table == NULL)) {
retval = -ENODEV;
......@@ -529,8 +520,11 @@ int sharedregion_set_table_info(u32 index, u16 proc_id,
return 0;
error:
printk(KERN_ERR "sharedregion_set_table_info failed status:%x\n",
retval);
return retval;
}
EXPORT_SYMBOL(sharedregion_set_table_info);
/*
* ======== Sharedregion_attach ========
......@@ -583,8 +577,6 @@ void sharedregion_attach(u16 proc_id)
s32 retval = 0;
s32 i;
gt_1trace(sharedregion_mask, GT_ENTER,
"sharedregion_attach:\n proc_id: %x\n", proc_id);
if (WARN_ON(sharedregion_state.table == NULL))
goto error;
......@@ -662,8 +654,7 @@ void sharedregion_attach(u16 proc_id)
error:
return;
}
EXPORT_SYMBOL(sharedregion_attach);
/*
* ======== Sharedregion_detach ========
......@@ -696,8 +687,6 @@ void sharedregion_detach(u16 proc_id)
{
u16 proc_count;
gt_1trace(sharedregion_mask, GT_ENTER,
"sharedRegion_detach:\n proc_id: %x\n", proc_id);
if (WARN_ON(sharedregion_state.table == NULL))
goto error;
......@@ -708,4 +697,5 @@ void sharedregion_detach(u16 proc_id)
error:
return;
}
EXPORT_SYMBOL(sharedregion_detach);
......@@ -16,6 +16,11 @@
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
#include <linux/uaccess.h>
#include <linux/types.h>
#include <linux/bug.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/types.h>
......@@ -32,32 +37,19 @@
* Purpose:
* This ioctl interface to sharedregion_get_config function
*/
static int sharedregion_ioctl_get_config(struct sharedregion_cmd_args *args)
static int sharedregion_ioctl_get_config(struct sharedregion_cmd_args *cargs)
{
struct sharedregion_cmd_args uarg;
struct sharedregion_cmd_args *cargs = &uarg;
struct sharedregion_config config;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct sharedregion_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = sharedregion_get_config(&config);
size = copy_to_user(cargs->cmd_arg.get_config.config, &config,
size = copy_to_user(cargs->args.get_config.config, &config,
sizeof(struct sharedregion_config));
if (size) {
if (size)
retval = -EFAULT;
goto exit;
}
return 0;
exit:
return retval;
}
......@@ -67,22 +59,13 @@ exit:
* Purpose:
* This ioctl interface to sharedregion_setup function
*/
static int sharedregion_ioctl_setup(struct sharedregion_cmd_args *args)
static int sharedregion_ioctl_setup(struct sharedregion_cmd_args *cargs)
{
struct sharedregion_cmd_args uarg;
struct sharedregion_cmd_args *cargs = &uarg;
struct sharedregion_config config;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct sharedregion_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
size = copy_from_user(&config, cargs->cmd_arg.setup.config,
size = copy_from_user(&config, cargs->args.setup.config,
sizeof(struct sharedregion_config));
if (size) {
retval = -EFAULT;
......@@ -90,10 +73,6 @@ static int sharedregion_ioctl_setup(struct sharedregion_cmd_args *args)
}
retval = sharedregion_setup(&config);
if (retval)
goto exit;
return 0;
exit:
return retval;
......@@ -116,29 +95,13 @@ static int sharedregion_ioctl_destroy()
* Purpose:
* This ioctl interface to sharedregion_add function
*/
static int sharedregion_ioctl_add(struct sharedregion_cmd_args *args)
static int sharedregion_ioctl_add(struct sharedregion_cmd_args *cargs)
{
struct sharedregion_cmd_args uarg;
struct sharedregion_cmd_args *cargs = &uarg;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct sharedregion_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = sharedregion_add(cargs->cmd_arg.add.index,
cargs->cmd_arg.add.base,
cargs->cmd_arg.add.len);
if (retval)
goto exit;
return 0;
exit:
retval = sharedregion_add(cargs->args.add.index,
cargs->args.add.base,
cargs->args.add.len);
return retval;
}
......@@ -149,37 +112,16 @@ exit:
* Purpose:
* This ioctl interface to sharedregion_get_index function
*/
static int sharedregion_ioctl_get_index(struct sharedregion_cmd_args *args)
static int sharedregion_ioctl_get_index(struct sharedregion_cmd_args *cargs)
{
struct sharedregion_cmd_args uarg;
struct sharedregion_cmd_args *cargs = &uarg;
s32 retval = 0;
s32 size;
s32 index = 0;
size = copy_from_user(cargs, args,
sizeof(struct sharedregion_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
index = sharedregion_get_index(cargs->cmd_arg.get_index.addr);
if (index < 0) {
index = sharedregion_get_index(cargs->args.get_index.addr);
cargs->args.get_index.index = index;
if (index < 0)
retval = index;
goto exit;
}
size = copy_to_user(&args->cmd_arg.get_index.index, &index,
sizeof(s32));
if (size) {
retval = -EFAULT;
goto exit;
}
return 0;
exit:
return retval;
}
......@@ -188,35 +130,16 @@ exit:
* Purpose:
* This ioctl interface to sharedregion_get_ptr function
*/
static int sharedregion_ioctl_get_ptr(struct sharedregion_cmd_args *args)
static int sharedregion_ioctl_get_ptr(struct sharedregion_cmd_args *cargs)
{
struct sharedregion_cmd_args uarg;
struct sharedregion_cmd_args *cargs = &uarg;
s32 retval = 0;
s32 size;
void *addr = NULL;
size = copy_from_user(cargs, args,
sizeof(struct sharedregion_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
addr = sharedregion_get_ptr(cargs->cmd_arg.get_ptr.srptr);
addr = sharedregion_get_ptr(cargs->args.get_ptr.srptr);
/* We are not checking the return from the module, its user
responsibilty to pass proper value to application
*/
size = copy_to_user(&args->cmd_arg.get_ptr.addr, &addr,
sizeof(void *));
if (size) {
retval = -EFAULT;
goto exit;
}
return 0;
exit:
cargs->args.get_ptr.addr = addr;
return retval;
}
......@@ -225,36 +148,17 @@ exit:
* Purpose:
* This ioctl interface to sharedregion_get_srptr function
*/
static int sharedregion_ioctl_get_srptr(struct sharedregion_cmd_args *args)
static int sharedregion_ioctl_get_srptr(struct sharedregion_cmd_args *cargs)
{
struct sharedregion_cmd_args uarg;
struct sharedregion_cmd_args *cargs = &uarg;
s32 retval = 0;
s32 size;
u32 *srptr = NULL;
size = copy_from_user(cargs, args,
sizeof(struct sharedregion_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
srptr = sharedregion_get_srptr(cargs->cmd_arg.get_srptr.addr,
cargs->cmd_arg.get_srptr.index);
srptr = sharedregion_get_srptr(cargs->args.get_srptr.addr,
cargs->args.get_srptr.index);
/* We are not checking the return from the module, its user
responsibilty to pass proper value to application
*/
size = copy_to_user(&args->cmd_arg.get_srptr.srptr, &srptr,
sizeof(u32 *));
if (size) {
retval = -EFAULT;
goto exit;
}
return 0;
exit:
cargs->args.get_srptr.srptr = srptr;
return retval;
}
......@@ -263,35 +167,23 @@ exit:
* Purpose:
* This ioctl interface to sharedregion_get_table_info function
*/
static int sharedregion_ioctl_get_table_info(struct sharedregion_cmd_args *args)
static int sharedregion_ioctl_get_table_info(
struct sharedregion_cmd_args *cargs)
{
struct sharedregion_cmd_args uarg;
struct sharedregion_cmd_args *cargs = &uarg;
struct sharedregion_info info;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct sharedregion_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = sharedregion_get_table_info(
cargs->cmd_arg.get_table_info.index,
cargs->cmd_arg.get_table_info.proc_id, &info);
cargs->args.get_table_info.index,
cargs->args.get_table_info.proc_id, &info);
if (retval)
goto exit;
size = copy_to_user(cargs->cmd_arg.get_table_info.info, &info,
size = copy_to_user(cargs->args.get_table_info.info, &info,
sizeof(struct sharedregion_info));
if (size) {
if (size)
retval = -EFAULT;
goto exit;
}
return 0;
exit:
return retval;
......@@ -303,27 +195,11 @@ exit:
* Purpose:
* This ioctl interface to sharedregion_remove function
*/
static int sharedregion_ioctl_remove(struct sharedregion_cmd_args *args)
static int sharedregion_ioctl_remove(struct sharedregion_cmd_args *cargs)
{
struct sharedregion_cmd_args uarg;
struct sharedregion_cmd_args *cargs = &uarg;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct sharedregion_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = sharedregion_remove(cargs->cmd_arg.remove.index);
if (retval)
goto exit;
return 0;
exit:
retval = sharedregion_remove(cargs->args.remove.index);
return retval;
}
......@@ -332,22 +208,14 @@ exit:
* Purpose:
* This ioctl interface to sharedregion_set_table_info function
*/
static int sharedregion_ioctl_set_table_info(struct sharedregion_cmd_args *args)
static int sharedregion_ioctl_set_table_info(
struct sharedregion_cmd_args *cargs)
{
struct sharedregion_cmd_args uarg;
struct sharedregion_cmd_args *cargs = &uarg;
struct sharedregion_info info;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct sharedregion_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
size = copy_from_user(&info, cargs->cmd_arg.set_table_info.info,
size = copy_from_user(&info, cargs->args.set_table_info.info,
sizeof(struct sharedregion_info));
if (size) {
retval = -EFAULT;
......@@ -355,12 +223,8 @@ static int sharedregion_ioctl_set_table_info(struct sharedregion_cmd_args *args)
}
retval = sharedregion_set_table_info(
cargs->cmd_arg.set_table_info.index,
cargs->cmd_arg.set_table_info.proc_id, &info);
if (retval)
goto exit;
return 0;
cargs->args.set_table_info.index,
cargs->args.set_table_info.proc_id, &info);
exit:
return retval;
......@@ -374,72 +238,86 @@ exit:
int sharedregion_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long args)
{
s32 os_status = 0;
s32 size = 0;
struct sharedregion_cmd_args __user *uarg =
(struct sharedregion_cmd_args __user *)args;
s32 retval = 0;
gt_4trace(curTrace, GT_ENTER, "sharedregion_ioctl"
"inode: %x, filp: %x,\n cmd: %x, args: %x",
inode, filp, cmd, args);
struct sharedregion_cmd_args cargs;
if (_IOC_DIR(cmd) & _IOC_READ)
retval = !access_ok(VERIFY_WRITE, uarg, _IOC_SIZE(cmd));
os_status = !access_ok(VERIFY_WRITE, uarg, _IOC_SIZE(cmd));
else if (_IOC_DIR(cmd) & _IOC_WRITE)
retval = !access_ok(VERIFY_READ, uarg, _IOC_SIZE(cmd));
os_status = !access_ok(VERIFY_READ, uarg, _IOC_SIZE(cmd));
if (retval) {
retval = -EFAULT;
if (os_status) {
os_status = -EFAULT;
goto exit;
}
/* Copy the full args from user-side */
size = copy_from_user(&cargs, uarg,
sizeof(struct sharedregion_cmd_args));
if (size) {
os_status = -EFAULT;
goto exit;
}
switch (cmd) {
case CMD_SHAREDREGION_GETCONFIG:
retval = sharedregion_ioctl_get_config(uarg);
os_status = sharedregion_ioctl_get_config(&cargs);
break;
case CMD_SHAREDREGION_SETUP:
retval = sharedregion_ioctl_setup(uarg);
os_status = sharedregion_ioctl_setup(&cargs);
break;
case CMD_SHAREDREGION_DESTROY:
retval = sharedregion_ioctl_destroy();
os_status = sharedregion_ioctl_destroy();
break;
case CMD_SHAREDREGION_ADD:
retval = sharedregion_ioctl_add(uarg);
os_status = sharedregion_ioctl_add(&cargs);
break;
case CMD_SHAREDREGION_GETINDEX:
retval = sharedregion_ioctl_get_index(uarg);
os_status = sharedregion_ioctl_get_index(&cargs);
break;
case CMD_SHAREDREGION_GETPTR:
retval = sharedregion_ioctl_get_ptr(uarg);
os_status = sharedregion_ioctl_get_ptr(&cargs);
break;
case CMD_SHAREDREGION_GETSRPTR:
retval = sharedregion_ioctl_get_srptr(uarg);
os_status = sharedregion_ioctl_get_srptr(&cargs);
break;
case CMD_SHAREDREGION_GETTABLEINFO:
retval = sharedregion_ioctl_get_table_info(uarg);
os_status = sharedregion_ioctl_get_table_info(&cargs);
break;
case CMD_SHAREDREGION_REMOVE:
retval = sharedregion_ioctl_remove(uarg);
os_status = sharedregion_ioctl_remove(&cargs);
break;
case CMD_SHAREDREGION_SETTABLEINFO:
retval = sharedregion_ioctl_set_table_info(uarg);
os_status = sharedregion_ioctl_set_table_info(&cargs);
break;
default:
WARN_ON(cmd);
retval = -ENOTTY;
os_status = -ENOTTY;
break;
}
/* Copy the full args to the user-side. */
size = copy_to_user(uarg, &cargs, sizeof(struct sharedregion_cmd_args));
if (size) {
os_status = -EFAULT;
goto exit;
}
exit:
return retval;
return os_status;
}
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