Commit 5b28e4d8 authored by Arun Gopalakrishnan's avatar Arun Gopalakrishnan Committed by Hari Kanigeri

IPC GatePeterson 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 are made IOWR
3. Debug prints were added in all the APIs failure return
Signed-off-by: default avatarArun M G <arunmg@ti.com>
parent eb76e281
......@@ -36,7 +36,7 @@ enum CMD_GATEPETERSON {
GATEPETERSON_CLOSE,
GATEPETERSON_ENTER,
GATEPETERSON_LEAVE,
GATEPETERSON_SHAREDMEMREQ,
GATEPETERSON_SHAREDMEMREQ
};
/*
......@@ -53,15 +53,16 @@ enum CMD_GATEPETERSON {
/*
* Command for gatepeterson_setup
*/
#define CMD_GATEPETERSON_SETUP _IOW(IPC_IOC_MAGIC, \
#define CMD_GATEPETERSON_SETUP _IOWR(IPC_IOC_MAGIC, \
GATEPETERSON_SETUP, \
struct gatepeterson_cmd_args)
/*
* Command for gatepeterson_setup
*/
#define CMD_GATEPETERSON_DESTROY _IO(IPC_IOC_MAGIC, \
GATEPETERSON_DESTROY)
#define CMD_GATEPETERSON_DESTROY _IOWR(IPC_IOC_MAGIC, \
GATEPETERSON_DESTROY, \
struct gatepeterson_cmd_args)
/*
* Command for gatepeterson_destroy
......@@ -99,14 +100,14 @@ enum CMD_GATEPETERSON {
/*
* Command for gatepeterson_enter
*/
#define CMD_GATEPETERSON_ENTER _IOW(IPC_IOC_MAGIC, \
#define CMD_GATEPETERSON_ENTER _IOWR(IPC_IOC_MAGIC, \
GATEPETERSON_ENTER, \
struct gatepeterson_cmd_args)
/*
* Command for gatepeterson_leave
*/
#define CMD_GATEPETERSON_LEAVE _IOW(IPC_IOC_MAGIC, \
#define CMD_GATEPETERSON_LEAVE _IOWR(IPC_IOC_MAGIC, \
GATEPETERSON_LEAVE, \
struct gatepeterson_cmd_args)
......@@ -175,7 +176,7 @@ union gatepeterson_arg {
* Command arguments for gatepeterson
*/
struct gatepeterson_cmd_args {
union gatepeterson_arg cmd_arg;
union gatepeterson_arg args;
s32 api_status;
};
......
......@@ -16,6 +16,7 @@
* PURPOSE.
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/list.h>
......@@ -113,8 +114,6 @@ int gatepeterson_get_config(struct gatepeterson_config *config)
{
s32 retval = 0;
gt_1trace(gatepeterson_mask, GT_ENTER,
"gatepeterson_get_config:\n config: %x\n", config);
if (WARN_ON(config == NULL)) {
retval = -EINVAL;
goto exit;
......@@ -131,6 +130,7 @@ int gatepeterson_get_config(struct gatepeterson_config *config)
exit:
return retval;
}
EXPORT_SYMBOL(gatepeterson_get_config);
/*
* ======== gatepeterson_setup ========
......@@ -144,8 +144,6 @@ int gatepeterson_setup(const struct gatepeterson_config *config)
s32 retval = 0;
s32 ret;
gt_1trace(gatepeterson_mask, GT_ENTER,
"gatepeterson_setup:\n config: %x\n", config);
BUG_ON(config == NULL);
if (WARN_ON(config->max_name_len == 0)) {
retval = -EINVAL;
......@@ -183,8 +181,11 @@ int gatepeterson_setup(const struct gatepeterson_config *config)
return 0;
exit:
printk(KERN_ERR "gatepeterson_setup failed status: %x\n",
retval);
return retval;
}
EXPORT_SYMBOL(gatepeterson_setup);
/*
* ======== gatepeterson_destroy ========
......@@ -197,7 +198,6 @@ int gatepeterson_destroy(void)
struct mutex *lock = NULL;
s32 retval = 0;
gt_0trace(gatepeterson_mask, GT_ENTER, "gatepeterson_destroy:\n");
if (WARN_ON(gatepeterson_state.is_init != true)) {
retval = -ENODEV;
goto exit;
......@@ -205,8 +205,6 @@ int gatepeterson_destroy(void)
/* If an entry exist, do not proceed */
if (!list_empty(&gatepeterson_state.obj_list)) {
gt_0trace(gatepeterson_mask, GT_6CLASS,
"gatepeterson_destroy: gatepeterson in use!\n");
retval = -EBUSY;
goto exit;
}
......@@ -230,9 +228,11 @@ int gatepeterson_destroy(void)
return 0;
exit:;
printk(KERN_ERR "gatepeterson_destroy failed status:%x\n", retval);
return retval;
}
EXPORT_SYMBOL(gatepeterson_destroy);
/*
* ======== gatepeterson_params_init ========
......@@ -242,8 +242,6 @@ exit:;
*/
int gatepeterson_params_init(struct gatepeterson_params *params)
{
gt_1trace(gatepeterson_mask, GT_ENTER,
"gatepeterson_params_init:\n params: %x\n", params);
BUG_ON(params == NULL);
params->shared_addr = 0;
......@@ -253,6 +251,7 @@ int gatepeterson_params_init(struct gatepeterson_params *params)
params->opener_proc_id = MULTIPROC_INVALIDID;
return 0;
}
EXPORT_SYMBOL(gatepeterson_params_init);
/*
* ======== gatepeterson_create ========
......@@ -263,17 +262,13 @@ void *gatepeterson_create(const struct gatepeterson_params *params)
{
struct gatepeterson_object *handle = NULL;
struct gatepeterson_obj *obj = NULL;
s32 retval;
s32 retval = 0;
u32 shaddrsize;
u32 len;
s32 status;
void *entry = NULL;
BUG_ON(params == NULL);
gt_3trace(gatepeterson_mask, GT_ENTER,
"gatepeterson_create:\n params: %x, shared_addr: %x,\n"
" shared_addr_size: %x", params,
params->shared_addr, params->shared_addr_size);
if (WARN_ON(gatepeterson_state.is_init != true)) {
retval = -ENODEV;
goto exit;
......@@ -356,7 +351,7 @@ void *gatepeterson_create(const struct gatepeterson_params *params)
case GATEPETERSON_PROTECT_THREAD: /* Fall through */
case GATEPETERSON_PROTECT_PROCESS:
obj->local_gate = kmalloc(sizeof(struct mutex), GFP_KERNEL);
if (obj->local_gate) {
if (obj->local_gate == NULL) {
retval = -ENOMEM;
goto gate_create_fail;
}
......@@ -396,8 +391,10 @@ obj_alloc_fail:
handle_alloc_fail: /* Fall through */
exit:
printk(KERN_ERR "gatepeterson_create failed status: %x\n", retval);
return NULL;;
}
EXPORT_SYMBOL(gatepeterson_create);
/*
* ======== gatepeterson_delete ========
......@@ -414,9 +411,6 @@ int gatepeterson_delete(void **gphandle)
BUG_ON(gphandle == NULL);
BUG_ON(*gphandle == NULL);
gt_2trace(gatepeterson_mask, GT_ENTER,
"gatepeterson_create:\n gphandle: %x, *gphandle: %x,\n",
gphandle, *gphandle);
if (WARN_ON(gatepeterson_state.is_init != true)) {
retval = -ENODEV;
goto exit;
......@@ -483,8 +477,11 @@ error_handle:
mutex_unlock(obj->local_gate);
exit:
printk(KERN_ERR "gatepeterson_create failed status: %x\n",
retval);
return retval;
}
EXPORT_SYMBOL(gatepeterson_delete);
/*
* ======== gatepeterson_inc_refcount ========
......@@ -552,9 +549,6 @@ int gatepeterson_open(void **gphandle,
BUG_ON(params == NULL);
BUG_ON(gphandle == NULL);
gt_3trace(gatepeterson_mask, GT_ENTER,
"gatepeterson_open:\n gphandle: %x, *gphandle: %x,\n"
"params: %x\n", gphandle, *gphandle, params);
if (WARN_ON(gatepeterson_state.is_init != true)) {
retval = -EINVAL;
goto exit;
......@@ -600,13 +594,13 @@ int gatepeterson_open(void **gphandle,
}
handle = kmalloc(sizeof(struct gatepeterson_object), GFP_KERNEL);
if (handle) {
if (handle == NULL) {
retval = -ENOMEM;
goto handle_alloc_fail;
}
obj = kmalloc(sizeof(struct gatepeterson_obj), GFP_KERNEL);
if (obj) {
if (obj == NULL) {
retval = -ENOMEM; /* Not created */
goto obj_alloc_fail;
}
......@@ -661,7 +655,7 @@ int gatepeterson_open(void **gphandle,
case GATEPETERSON_PROTECT_THREAD: /* Fall through */
case GATEPETERSON_PROTECT_PROCESS:
obj->local_gate = kmalloc(sizeof(struct mutex), GFP_KERNEL);
if (obj->local_gate) {
if (obj->local_gate == NULL) {
retval = -ENOMEM;
goto gate_create_fail;
}
......@@ -703,9 +697,11 @@ obj_alloc_fail:
handle_alloc_fail: /* Fall through */
noentry_fail: /* Fall through */
exit:
printk(KERN_ERR "gatepeterson_open failed status: %x\n", retval);
return retval;;
}
EXPORT_SYMBOL(gatepeterson_open);
/*
* ======== gatepeterson_close ========
......@@ -721,9 +717,6 @@ int gatepeterson_close(void **gphandle)
s32 retval = 0;
BUG_ON(gphandle == NULL);
gt_2trace(gatepeterson_mask, GT_ENTER,
"gatepeterson_create:\n gphandle: %x, *gphandle: %x,\n",
gphandle, *gphandle);
if (WARN_ON(gatepeterson_state.is_init != true)) {
retval = -EINVAL;
goto exit;
......@@ -790,8 +783,10 @@ error_handle:
mutex_unlock(obj->local_gate);
exit:
printk(KERN_ERR "gatepeterson_close failed status: %x\n", retval);
return retval;
}
EXPORT_SYMBOL(gatepeterson_close);
/*
* ======== gatepeterson_enter ========
......@@ -804,8 +799,6 @@ u32 gatepeterson_enter(void *gphandle)
struct gatepeterson_obj *obj = NULL;
s32 retval = 0;
gt_1trace(gatepeterson_mask, GT_ENTER,
"gatepeterson_enter:\n gphandle: %x\n", gphandle);
BUG_ON(gphandle == NULL);
if (WARN_ON(gatepeterson_state.is_init != true)) {
retval = -EINVAL;
......@@ -838,6 +831,7 @@ u32 gatepeterson_enter(void *gphandle)
exit:
return retval;
}
EXPORT_SYMBOL(gatepeterson_enter);
/*
* ======== gatepeterson_leave ========
......@@ -849,8 +843,6 @@ void gatepeterson_leave(void *gphandle, u32 flag)
struct gatepeterson_object *handle = NULL;
struct gatepeterson_obj *obj = NULL;
gt_1trace(gatepeterson_mask, GT_ENTER,
"gatepeterson_enter:\n gphandle: %x\n", gphandle);
BUG_ON(gatepeterson_state.is_init != true);
BUG_ON(gphandle == NULL);
......@@ -864,6 +856,7 @@ void gatepeterson_leave(void *gphandle, u32 flag)
mutex_unlock(obj->local_gate);
return;
}
EXPORT_SYMBOL(gatepeterson_leave);
/*
* ======== gatepeterson_get_knl_handle ========
......@@ -872,13 +865,10 @@ void gatepeterson_leave(void *gphandle, u32 flag)
*/
void *gatepeterson_get_knl_handle(void **gphandle)
{
gt_1trace(gatepeterson_mask, GT_ENTER,
"gatepeterson_get_knl_handle:\n"
"gphandle: %x\n", gphandle);
BUG_ON(gphandle == NULL);
return gphandle;
}
EXPORT_SYMBOL(gatepeterson_get_knl_handle);
/*
* ======== gatepeterson_shared_memreq ========
......@@ -890,9 +880,6 @@ u32 gatepeterson_shared_memreq(const struct gatepeterson_params *params)
{
u32 retval = 0;
gt_1trace(gatepeterson_mask, GT_ENTER,
"gatepeterson_shared_memreq:\n params: %x\n", params);
if (params != NULL)
retval = 128 * 4;
else
......@@ -900,4 +887,5 @@ u32 gatepeterson_shared_memreq(const struct gatepeterson_params *params)
return retval;
}
EXPORT_SYMBOL(gatepeterson_shared_memreq);
......@@ -15,6 +15,10 @@
* 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>
......@@ -31,33 +35,20 @@
* Purpose:
* This ioctl interface to gatepeterson_get_config function
*/
static int gatepeterson_ioctl_get_config(struct gatepeterson_cmd_args *args)
static int gatepeterson_ioctl_get_config(struct gatepeterson_cmd_args *cargs)
{
struct gatepeterson_cmd_args uarg;
struct gatepeterson_cmd_args *cargs = &uarg;
struct gatepeterson_config config;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct gatepeterson_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = gatepeterson_get_config(&config);
if (unlikely(retval))
goto exit;
size = copy_to_user(cargs->cmd_arg.get_config.config, &config,
size = copy_to_user(cargs->args.get_config.config, &config,
sizeof(struct gatepeterson_config));
if (size) {
if (size)
retval = -EFAULT;
goto exit;
}
return 0;
exit:
return retval;
......@@ -68,22 +59,13 @@ exit:
* Purpose:
* This ioctl interface to gatepeterson_setup function
*/
static int gatepeterson_ioctl_setup(struct gatepeterson_cmd_args *args)
static int gatepeterson_ioctl_setup(struct gatepeterson_cmd_args *cargs)
{
struct gatepeterson_cmd_args uarg;
struct gatepeterson_cmd_args *cargs = &uarg;
struct gatepeterson_config config;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct gatepeterson_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 gatepeterson_config));
if (size) {
retval = -EFAULT;
......@@ -91,11 +73,6 @@ static int gatepeterson_ioctl_setup(struct gatepeterson_cmd_args *args)
}
retval = gatepeterson_setup(&config);
if (unlikely(retval))
goto exit;
return 0;
exit:
return retval;
}
......@@ -117,32 +94,18 @@ static int gatepeterson_ioctl_destroy()
* Purpose:
* This ioctl interface to gatepeterson_params_init function
*/
static int gatepeterson_ioctl_params_init(struct gatepeterson_cmd_args *args)
static int gatepeterson_ioctl_params_init(struct gatepeterson_cmd_args *cargs)
{
struct gatepeterson_cmd_args uarg;
struct gatepeterson_cmd_args *cargs = &uarg;
struct gatepeterson_params params;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct gatepeterson_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = gatepeterson_params_init(&params);
size = copy_to_user(cargs->cmd_arg.params_init.params, &params,
size = copy_to_user(cargs->args.params_init.params, &params,
sizeof(struct gatepeterson_params));
if (size) {
if (size)
retval = -EFAULT;
goto exit;
}
return 0;
exit:
return retval;
}
......@@ -151,40 +114,32 @@ exit:
* Purpose:
* This ioctl interface to gatepeterson_create function
*/
static int gatepeterson_ioctl_create(struct gatepeterson_cmd_args *args)
static int gatepeterson_ioctl_create(struct gatepeterson_cmd_args *cargs)
{
struct gatepeterson_cmd_args uarg;
struct gatepeterson_cmd_args *cargs = &uarg;
struct gatepeterson_params params;
void *handle = NULL;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct gatepeterson_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
size = copy_from_user(&params, cargs->cmd_arg.create.params,
size = copy_from_user(&params, cargs->args.create.params,
sizeof(struct gatepeterson_params));
if (size) {
retval = -EFAULT;
goto exit;
}
if (cargs->cmd_arg.create.name_len > 0) {
params.name = kmalloc(cargs->cmd_arg.create.name_len,
if (cargs->args.create.name_len > 0) {
params.name = kmalloc(cargs->args.create.name_len + 1,
GFP_KERNEL);
if (params.name == NULL) {
retval = -ENOMEM;
goto exit;
}
params.name[cargs->args.create.name_len] = '\0';
size = copy_from_user(params.name,
cargs->cmd_arg.create.params->name,
cargs->cmd_arg.create.name_len);
cargs->args.create.params->name,
cargs->args.create.name_len);
if (size) {
retval = -EFAULT;
goto name_from_usr_error;
......@@ -198,24 +153,10 @@ static int gatepeterson_ioctl_create(struct gatepeterson_cmd_args *args)
Even it is nul, we pass it to user and user has to pass
proper return to application
*/
size = copy_to_user(&args->cmd_arg.create.handle, &handle,
sizeof(void *));
if (size) {
retval = -EFAULT;
goto handle_to_usr_error;
}
if (cargs->cmd_arg.create.name_len > 0)
kfree(params.name);
return 0;
handle_to_usr_error:
if (handle)
gatepeterson_delete(&handle);
cargs->args.create.handle = handle;
name_from_usr_error:
if (cargs->cmd_arg.open.name_len > 0)
if (cargs->args.open.name_len > 0)
kfree(params.name);
exit:
......@@ -227,34 +168,12 @@ exit:
* Purpose:
* This ioctl interface to gatepeterson_ioctl_delete function
*/
static int gatepeterson_ioctl_delete(struct gatepeterson_cmd_args *args)
static int gatepeterson_ioctl_delete(struct gatepeterson_cmd_args *cargs)
{
struct gatepeterson_cmd_args uarg;
struct gatepeterson_cmd_args *cargs = &uarg;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct gatepeterson_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = gatepeterson_delete(&cargs->cmd_arg.delete.handle);
if (retval)
goto exit;
/* Clear user side memory that stored handle */
size = copy_to_user(&args->cmd_arg.delete.handle,
&cargs->cmd_arg.delete.handle, sizeof(void *));
if (size) {
retval = -EFAULT;
goto exit;
}
exit:
retval = gatepeterson_delete(&cargs->args.delete.handle);
return retval;
}
......@@ -263,40 +182,32 @@ exit:
* Purpose:
* This ioctl interface to gatepeterson_open function
*/
static int gatepeterson_ioctl_open(struct gatepeterson_cmd_args *args)
static int gatepeterson_ioctl_open(struct gatepeterson_cmd_args *cargs)
{
struct gatepeterson_cmd_args uarg;
struct gatepeterson_cmd_args *cargs = &uarg;
struct gatepeterson_params params;
void *handle = NULL;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct gatepeterson_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
size = copy_from_user(&params, cargs->cmd_arg.open.params,
size = copy_from_user(&params, cargs->args.open.params,
sizeof(struct gatepeterson_params));
if (size) {
retval = -EFAULT;
goto exit;
}
if (cargs->cmd_arg.open.name_len > 0) {
params.name = kmalloc(cargs->cmd_arg.open.name_len, GFP_KERNEL);
if (cargs->args.open.name_len > 0) {
params.name = kmalloc(cargs->args.open.name_len + 1,
GFP_KERNEL);
if (params.name != NULL) {
retval = -ENOMEM;
goto exit;
}
params.name[cargs->args.open.name_len] = '\0';
size = copy_from_user(params.name,
cargs->cmd_arg.open.params->name,
cargs->cmd_arg.open.name_len);
cargs->args.open.params->name,
cargs->args.open.name_len);
if (size) {
retval = -EFAULT;
goto name_from_usr_error;
......@@ -305,28 +216,10 @@ static int gatepeterson_ioctl_open(struct gatepeterson_cmd_args *args)
params.shared_addr = sharedregion_get_ptr((u32 *)params.shared_addr);
retval = gatepeterson_open(&handle, &params);
if (retval)
goto exit;
size = copy_to_user(&args->cmd_arg.open.handle, &handle,
sizeof(void *));
if (size) {
retval = -EFAULT;
goto handle_to_usr_error;
}
if (cargs->cmd_arg.open.name_len > 0)
kfree(params.name);
return 0;
handle_to_usr_error:
if (handle)
gatepeterson_delete(&handle);
cargs->args.open.handle = handle;
name_from_usr_error:
if (cargs->cmd_arg.open.name_len > 0)
if (cargs->args.open.name_len > 0)
kfree(params.name);
exit:
......@@ -338,33 +231,11 @@ exit:
* Purpose:
* This ioctl interface to gatepeterson_close function
*/
static int gatepeterson_ioctl_close(struct gatepeterson_cmd_args *args)
static int gatepeterson_ioctl_close(struct gatepeterson_cmd_args *cargs)
{
struct gatepeterson_cmd_args uarg;
struct gatepeterson_cmd_args *cargs = &uarg;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct gatepeterson_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = gatepeterson_close(&cargs->cmd_arg.close.handle);
if (retval)
goto exit;
size = copy_to_user(&args->cmd_arg.close.handle,
&cargs->cmd_arg.close.handle, sizeof(void *));
if (size) {
retval = -EFAULT;
goto exit;
}
exit:
retval = gatepeterson_close(&cargs->args.close.handle);
return retval;
}
......@@ -373,23 +244,11 @@ exit:
* Purpose:
* This ioctl interface to gatepeterson_enter function
*/
static int gatepeterson_ioctl_enter(struct gatepeterson_cmd_args *args)
static int gatepeterson_ioctl_enter(struct gatepeterson_cmd_args *cargs)
{
struct gatepeterson_cmd_args uarg;
struct gatepeterson_cmd_args *cargs = &uarg;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct gatepeterson_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = gatepeterson_enter(cargs->cmd_arg.enter.handle);
exit:
retval = gatepeterson_enter(cargs->args.enter.handle);
return retval;
}
......@@ -398,24 +257,10 @@ exit:
* Purpose:
* This ioctl interface to gatepeterson_leave function
*/
static int gatepeterson_ioctl_leave(struct gatepeterson_cmd_args *args)
static int gatepeterson_ioctl_leave(struct gatepeterson_cmd_args *cargs)
{
struct gatepeterson_cmd_args uarg;
struct gatepeterson_cmd_args *cargs = &uarg;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct gatepeterson_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
gatepeterson_leave(cargs->cmd_arg.enter.handle,
cargs->cmd_arg.enter.flags);
exit:
gatepeterson_leave(cargs->args.enter.handle,
cargs->args.enter.flags);
return 0;
}
......@@ -424,39 +269,22 @@ exit:
* Purpose:
* This ioctl interface to gatepeterson_shared_memreq function
*/
static int gatepeterson_ioctl_shared_memreq(struct gatepeterson_cmd_args *args)
static int gatepeterson_ioctl_shared_memreq(struct gatepeterson_cmd_args *cargs)
{
struct gatepeterson_cmd_args uarg;
struct gatepeterson_cmd_args *cargs = &uarg;
struct gatepeterson_params params;
s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct gatepeterson_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
size = copy_from_user(&params, cargs->cmd_arg.shared_memreq.params,
size = copy_from_user(&params, cargs->args.shared_memreq.params,
sizeof(struct gatepeterson_params));
if (size) {
retval = -EFAULT;
goto exit;
}
cargs->cmd_arg.shared_memreq.bytes =
gatepeterson_shared_memreq(cargs->cmd_arg.shared_memreq.params);
size = copy_to_user(&args->cmd_arg.shared_memreq.bytes,
&cargs->cmd_arg.shared_memreq.bytes, sizeof(u32));
if (size) {
retval = -EFAULT;
goto exit;
}
return 0;
cargs->args.shared_memreq.bytes =
gatepeterson_shared_memreq(cargs->args.shared_memreq.params);
exit:
return retval;
......@@ -470,76 +298,91 @@ exit:
int gatepeterson_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long args)
{
s32 os_status = 0;
s32 size = 0;
struct gatepeterson_cmd_args __user *uarg =
(struct gatepeterson_cmd_args __user *)args;
s32 retval = 0;
struct gatepeterson_cmd_args cargs;
gt_4trace(curTrace, GT_ENTER, "gatepeterson_ioctl"
"inode: %x, filp: %x,\n cmd: %x, args: %x",
inode, filp, cmd, args);
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 gatepeterson_cmd_args));
if (size) {
os_status = -EFAULT;
goto exit;
}
switch (cmd) {
case CMD_GATEPETERSON_GETCONFIG:
retval = gatepeterson_ioctl_get_config(uarg);
os_status = gatepeterson_ioctl_get_config(&cargs);
break;
case CMD_GATEPETERSON_SETUP:
retval = gatepeterson_ioctl_setup(uarg);
os_status = gatepeterson_ioctl_setup(&cargs);
break;
case CMD_GATEPETERSON_DESTROY:
retval = gatepeterson_ioctl_destroy();
os_status = gatepeterson_ioctl_destroy();
break;
case CMD_GATEPETERSON_PARAMS_INIT:
retval = gatepeterson_ioctl_params_init(uarg);
os_status = gatepeterson_ioctl_params_init(&cargs);
break;
case CMD_GATEPETERSON_CREATE:
retval = gatepeterson_ioctl_create(uarg);
os_status = gatepeterson_ioctl_create(&cargs);
break;
case CMD_GATEPETERSON_DELETE:
retval = gatepeterson_ioctl_delete(uarg);
os_status = gatepeterson_ioctl_delete(&cargs);
break;
case CMD_GATEPETERSON_OPEN:
retval = gatepeterson_ioctl_open(uarg);
os_status = gatepeterson_ioctl_open(&cargs);
break;
case CMD_GATEPETERSON_CLOSE:
retval = gatepeterson_ioctl_close(uarg);
os_status = gatepeterson_ioctl_close(&cargs);
break;
case CMD_GATEPETERSON_ENTER:
retval = gatepeterson_ioctl_enter(uarg);
os_status = gatepeterson_ioctl_enter(&cargs);
break;
case CMD_GATEPETERSON_LEAVE:
retval = gatepeterson_ioctl_leave(uarg);
os_status = gatepeterson_ioctl_leave(&cargs);
break;
case CMD_GATEPETERSON_SHAREDMEMREQ:
retval = gatepeterson_ioctl_shared_memreq(uarg);
os_status = gatepeterson_ioctl_shared_memreq(&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 gatepeterson_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