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