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