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

IPC HeapBuf 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 128d99c0
...@@ -40,7 +40,7 @@ enum CMD_HEAPBUF { ...@@ -40,7 +40,7 @@ enum CMD_HEAPBUF {
HEAPBUF_FREE, HEAPBUF_FREE,
HEAPBUF_SHAREDMEMREQ, HEAPBUF_SHAREDMEMREQ,
HEAPBUF_GETSTATS, HEAPBUF_GETSTATS,
HEAPBUF_GETEXTENDEDSTATS, HEAPBUF_GETEXTENDEDSTATS
}; };
/* /*
...@@ -52,12 +52,13 @@ enum CMD_HEAPBUF { ...@@ -52,12 +52,13 @@ enum CMD_HEAPBUF {
/* /*
* Command for heapbuf_setup * Command for heapbuf_setup
*/ */
#define CMD_HEAPBUF_SETUP _IOW(IPC_IOC_MAGIC, HEAPBUF_SETUP, \ #define CMD_HEAPBUF_SETUP _IOWR(IPC_IOC_MAGIC, HEAPBUF_SETUP, \
struct heapbuf_cmd_args) struct heapbuf_cmd_args)
/* /*
* Command for heapbuf_destroy * Command for heapbuf_destroy
*/ */
#define CMD_HEAPBUF_DESTROY _IO(IPC_IOC_MAGIC, HEAPBUF_DESTROY) \ #define CMD_HEAPBUF_DESTROY _IOWR(IPC_IOC_MAGIC, HEAPBUF_DESTROY, \
struct heapbuf_cmd_args)
/* /*
* Command for heapbuf_prams_init * Command for heapbuf_prams_init
...@@ -75,7 +76,7 @@ enum CMD_HEAPBUF { ...@@ -75,7 +76,7 @@ enum CMD_HEAPBUF {
/* /*
* Command for heapbuf_delete * Command for heapbuf_delete
*/ */
#define CMD_HEAPBUF_DELETE _IOW(IPC_IOC_MAGIC, HEAPBUF_DELETE, \ #define CMD_HEAPBUF_DELETE _IOWR(IPC_IOC_MAGIC, HEAPBUF_DELETE, \
struct heapbuf_cmd_args) struct heapbuf_cmd_args)
/* /*
...@@ -87,7 +88,7 @@ enum CMD_HEAPBUF { ...@@ -87,7 +88,7 @@ enum CMD_HEAPBUF {
/* /*
* Command for heapbuf_close * Command for heapbuf_close
*/ */
#define CMD_HEAPBUF_CLOSE _IOW(IPC_IOC_MAGIC, HEAPBUF_CLOSE, \ #define CMD_HEAPBUF_CLOSE _IOWR(IPC_IOC_MAGIC, HEAPBUF_CLOSE, \
struct heapbuf_cmd_args) struct heapbuf_cmd_args)
/* /*
...@@ -99,7 +100,7 @@ enum CMD_HEAPBUF { ...@@ -99,7 +100,7 @@ enum CMD_HEAPBUF {
/* /*
* Command for heapbuf_free * Command for heapbuf_free
*/ */
#define CMD_HEAPBUF_FREE _IOW(IPC_IOC_MAGIC, HEAPBUF_FREE, \ #define CMD_HEAPBUF_FREE _IOWR(IPC_IOC_MAGIC, HEAPBUF_FREE, \
struct heapbuf_cmd_args) struct heapbuf_cmd_args)
/* /*
...@@ -195,7 +196,7 @@ union heapbuf_arg { ...@@ -195,7 +196,7 @@ union heapbuf_arg {
* Command arguments for heapbuf * Command arguments for heapbuf
*/ */
struct heapbuf_cmd_args{ struct heapbuf_cmd_args{
union heapbuf_arg cmd_arg; union heapbuf_arg args;
s32 api_status; s32 api_status;
}; };
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +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>
...@@ -126,6 +126,7 @@ int heapbuf_get_config(struct heap_config *cfgparams) ...@@ -126,6 +126,7 @@ int heapbuf_get_config(struct heap_config *cfgparams)
sizeof(struct heap_config)); sizeof(struct heap_config));
return 0; return 0;
} }
EXPORT_SYMBOL(heapbuf_get_config);
/* /*
* ======== heapbuf_setup ======== * ======== heapbuf_setup ========
...@@ -170,8 +171,10 @@ ns_create_fail: ...@@ -170,8 +171,10 @@ ns_create_fail:
kfree(heapbuf_state.list_lock); kfree(heapbuf_state.list_lock);
error: error:
printk(KERN_ERR "heapbuf_setup failed status: %x\n", retval);
return retval; return retval;
} }
EXPORT_SYMBOL(heapbuf_setup);
/* /*
* ======== heapbuf_destroy ======== * ======== heapbuf_destroy ========
...@@ -221,8 +224,10 @@ int heapbuf_destroy(void) ...@@ -221,8 +224,10 @@ int heapbuf_destroy(void)
return 0; return 0;
error: error:
printk(KERN_ERR "heapbuf_destroy failed status: %x\n", retval);
return retval; return retval;
} }
EXPORT_SYMBOL(heapbuf_destroy);
/* /*
* ======== heapbuf_params_init ======== * ======== heapbuf_params_init ========
...@@ -249,7 +254,7 @@ void heapbuf_params_init(void *handle, ...@@ -249,7 +254,7 @@ void heapbuf_params_init(void *handle,
memcpy(&obj->params, params, sizeof(struct heapbuf_params)); memcpy(&obj->params, params, sizeof(struct heapbuf_params));
} }
} }
EXPORT_SYMBOL(heapbuf_params_init);
/* /*
* ======== _heapbuf_create ======== * ======== _heapbuf_create ========
...@@ -310,7 +315,7 @@ static void *_heapbuf_create(const struct heapbuf_params *params, ...@@ -310,7 +315,7 @@ static void *_heapbuf_create(const struct heapbuf_params *params,
goto listmp_error; goto listmp_error;
} }
obj->lock_handle = kmalloc(sizeof(struct mutex), GFP_KERNEL); obj->lock_handle = kmalloc(sizeof(struct mutex), GFP_KERNEL);
if (obj->lock_handle) { if (obj->lock_handle == NULL) {
retval = -ENOMEM; retval = -ENOMEM;
goto gate_create_error; goto gate_create_error;
} }
...@@ -376,7 +381,7 @@ static void *_heapbuf_create(const struct heapbuf_params *params, ...@@ -376,7 +381,7 @@ static void *_heapbuf_create(const struct heapbuf_params *params,
obj->remote->proc_id = MULTIPROC_INVALIDID; obj->remote->proc_id = MULTIPROC_INVALIDID;
obj->owner->creator = false; obj->owner->creator = false;
obj->owner->open_count = 0; obj->owner->open_count = 0;
obj->owner->proc_id = multiproc_get_id("Ducati"); obj->owner->proc_id = multiproc_get_id("SysM3");
obj->top = handle; obj->top = handle;
} }
...@@ -418,6 +423,7 @@ obj_alloc_error: ...@@ -418,6 +423,7 @@ obj_alloc_error:
kfree(handle); kfree(handle);
error: error:
printk(KERN_ERR "_heapbuf_create failed status: %x\n", retval);
return NULL; return NULL;
} }
...@@ -456,8 +462,10 @@ void *heapbuf_create(const struct heapbuf_params *params) ...@@ -456,8 +462,10 @@ void *heapbuf_create(const struct heapbuf_params *params)
return handle; return handle;
error: error:
printk(KERN_ERR "heapbuf_create failed status: %x\n", retval);
return handle; return handle;
} }
EXPORT_SYMBOL(heapbuf_create);
/* /*
* ======== heapbuf_delete ======== * ======== heapbuf_delete ========
...@@ -538,8 +546,10 @@ device_busy_error: ...@@ -538,8 +546,10 @@ device_busy_error:
mutex_unlock(obj->lock_handle); mutex_unlock(obj->lock_handle);
error: error:
printk(KERN_ERR "heapbuf_delete failed status: %x\n", retval);
return retval; return retval;
} }
EXPORT_SYMBOL(heapbuf_delete);
/* /*
* ======== heapbuf_open ======== * ======== heapbuf_open ========
...@@ -609,8 +619,10 @@ int heapbuf_open(void **hphandle, ...@@ -609,8 +619,10 @@ int heapbuf_open(void **hphandle,
return 0; return 0;
error: error:
printk(KERN_ERR "heapbuf_open failed status: %x\n", retval);
return retval; return retval;
} }
EXPORT_SYMBOL(heapbuf_open);
/* /*
* ======== heapbuf_close ======== * ======== heapbuf_close ========
...@@ -680,9 +692,11 @@ int heapbuf_close(void *hphandle) ...@@ -680,9 +692,11 @@ int heapbuf_close(void *hphandle)
return 0; return 0;
error: error:
printk(KERN_ERR "heapbuf_close failed status: %x\n", retval);
return retval; return retval;
} }
EXPORT_SYMBOL(heapbuf_close);
/* /*
* ======== heapbuf_free ======== * ======== heapbuf_free ========
...@@ -740,8 +754,10 @@ void *heapbuf_alloc(void *hphandle, u32 size, u32 align) ...@@ -740,8 +754,10 @@ void *heapbuf_alloc(void *hphandle, u32 size, u32 align)
mutex_unlock(heapbuf_state.list_lock); mutex_unlock(heapbuf_state.list_lock);
return block; return block;
error: error:
printk(KERN_ERR "heapbuf_alloc failed status: %x\n", retval);
return NULL; return NULL;
} }
EXPORT_SYMBOL(heapbuf_alloc);
/* /*
* ======== heapbuf_free ======== * ======== heapbuf_free ========
...@@ -786,9 +802,10 @@ int heapbuf_free(void *hphandle, void *block, u32 size) ...@@ -786,9 +802,10 @@ int heapbuf_free(void *hphandle, void *block, u32 size)
return 0; return 0;
error: error:
printk(KERN_ERR "heapbuf_free failed status: %x\n", retval);
return retval; return retval;
} }
EXPORT_SYMBOL(heapbuf_free);
/* /*
* ======== heapbuf_get_stats ======== * ======== heapbuf_get_stats ========
...@@ -836,8 +853,10 @@ int heapbuf_get_stats(void *hphandle, struct memory_stats *stats) ...@@ -836,8 +853,10 @@ int heapbuf_get_stats(void *hphandle, struct memory_stats *stats)
return 0; return 0;
error: error:
printk(KERN_ERR "heapbuf_get_stats failed status: %x\n", retval);
return retval; return retval;
} }
EXPORT_SYMBOL(heapbuf_get_stats);
/* /*
* ======== heapbuf_get_extended_stats ======== * ======== heapbuf_get_extended_stats ========
...@@ -896,8 +915,11 @@ int heapbuf_get_extended_stats(void *hphandle, ...@@ -896,8 +915,11 @@ int heapbuf_get_extended_stats(void *hphandle,
mutex_unlock(heapbuf_state.list_lock); mutex_unlock(heapbuf_state.list_lock);
error: error:
printk(KERN_ERR "heapbuf_get_extended_stats failed status: %x\n",
retval);
return retval; return retval;
} }
EXPORT_SYMBOL(heapbuf_get_extended_stats);
/* /*
* ======== heapbuf_shared_memreq ======== * ======== heapbuf_shared_memreq ========
...@@ -920,4 +942,5 @@ int heapbuf_shared_memreq(const struct heapbuf_params *params) ...@@ -920,4 +942,5 @@ int heapbuf_shared_memreq(const struct heapbuf_params *params)
retval += HEAPBUF_CACHESIZE; /* Add in attrs */ retval += HEAPBUF_CACHESIZE; /* Add in attrs */
return retval; return retval;
} }
EXPORT_SYMBOL(heapbuf_shared_memreq);
...@@ -32,26 +32,16 @@ ...@@ -32,26 +32,16 @@
* Purpose: * Purpose:
* This ioctl interface to heapbuf_alloc function * This ioctl interface to heapbuf_alloc function
*/ */
static int heapbuf_ioctl_alloc(struct heapbuf_cmd_args *args) static int heapbuf_ioctl_alloc(struct heapbuf_cmd_args *cargs)
{ {
struct heapbuf_cmd_args uarg;
struct heapbuf_cmd_args *cargs = &uarg;
u32 *block_srptr = SHAREDREGION_INVALIDSRPTR; u32 *block_srptr = SHAREDREGION_INVALIDSRPTR;
void *block; void *block;
s32 index; s32 index;
s32 retval = 0; s32 retval = 0;
u32 size;
size = copy_from_user(cargs, args,
sizeof(struct heapbuf_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
block = heapbuf_alloc(cargs->cmd_arg.alloc.handle, block = heapbuf_alloc(cargs->args.alloc.handle,
cargs->cmd_arg.alloc.size, cargs->args.alloc.size,
cargs->cmd_arg.alloc.align); cargs->args.alloc.align);
if (block != NULL) { if (block != NULL) {
index = sharedregion_get_index(block); index = sharedregion_get_index(block);
if (index < 0) { if (index < 0) {
...@@ -66,14 +56,8 @@ static int heapbuf_ioctl_alloc(struct heapbuf_cmd_args *args) ...@@ -66,14 +56,8 @@ static int heapbuf_ioctl_alloc(struct heapbuf_cmd_args *args)
we are getting from the heapbuf module. So IOCTL will succed, we are getting from the heapbuf module. So IOCTL will succed,
but the actual fn might be failed inside heapbuf but the actual fn might be failed inside heapbuf
*/ */
size = copy_to_user(&args->cmd_arg.alloc.block_srptr, cargs->args.alloc.block_srptr = block_srptr;
&block_srptr, sizeof(u32 *));
if (size) {
retval = -EFAULT;
goto exit;
}
return 0;
exit: exit:
return retval; return retval;
} }
...@@ -83,30 +67,14 @@ exit: ...@@ -83,30 +67,14 @@ exit:
* Purpose: * Purpose:
* This ioctl interface to heapbuf_free function * This ioctl interface to heapbuf_free function
*/ */
static int heapbuf_ioctl_free(struct heapbuf_cmd_args *args) static int heapbuf_ioctl_free(struct heapbuf_cmd_args *cargs)
{ {
struct heapbuf_cmd_args uarg;
struct heapbuf_cmd_args *cargs = &uarg;
char *block; char *block;
s32 retval = 0; s32 retval = 0;
s32 size;
size = copy_from_user(cargs, args,
sizeof(struct heapbuf_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
block = sharedregion_get_ptr(cargs->cmd_arg.free.block_srptr);
retval = heapbuf_free(cargs->cmd_arg.free.handle, block,
cargs->cmd_arg.free.size);
if (retval)
goto exit;
return 0;
exit: block = sharedregion_get_ptr(cargs->args.free.block_srptr);
retval = heapbuf_free(cargs->args.free.handle, block,
cargs->args.free.size);
return retval; return retval;
} }
...@@ -115,33 +83,19 @@ exit: ...@@ -115,33 +83,19 @@ exit:
* Purpose: * Purpose:
* This ioctl interface to heapbuf_params_init function * This ioctl interface to heapbuf_params_init function
*/ */
static int heapbuf_ioctl_params_init(struct heapbuf_cmd_args *args) static int heapbuf_ioctl_params_init(struct heapbuf_cmd_args *cargs)
{ {
struct heapbuf_cmd_args uarg;
struct heapbuf_cmd_args *cargs = &uarg;
struct heapbuf_params params; struct heapbuf_params params;
s32 retval = 0; s32 retval = 0;
u32 size; u32 size;
size = copy_from_user(cargs, args, heapbuf_params_init(cargs->args.params_init.handle, &params);
sizeof(struct heapbuf_cmd_args)); size = copy_to_user(cargs->args.params_init.params, &params,
if (size) {
retval = -EFAULT;
goto exit;
}
heapbuf_params_init(cargs->cmd_arg.params_init.handle, &params);
size = copy_to_user(cargs->cmd_arg.params_init.params, &params,
sizeof(struct heapbuf_params)); sizeof(struct heapbuf_params));
if (size) { if (size)
retval = -EFAULT; retval = -EFAULT;
goto exit;
}
return 0;
exit:
return retval; return retval;
} }
/* /*
...@@ -149,40 +103,32 @@ exit: ...@@ -149,40 +103,32 @@ exit:
* Purpose: * Purpose:
* This ioctl interface to heapbuf_create function * This ioctl interface to heapbuf_create function
*/ */
static int heapbuf_ioctl_create(struct heapbuf_cmd_args *args) static int heapbuf_ioctl_create(struct heapbuf_cmd_args *cargs)
{ {
struct heapbuf_cmd_args uarg;
struct heapbuf_cmd_args *cargs = &uarg;
struct heapbuf_params params; struct heapbuf_params params;
s32 retval = 0; s32 retval = 0;
u32 size; u32 size;
void *handle = NULL; void *handle = NULL;
size = copy_from_user(cargs, args, size = copy_from_user(&params, cargs->args.create.params,
sizeof(struct heapbuf_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
size = copy_from_user(&params, cargs->cmd_arg.create.params,
sizeof(struct heapbuf_params)); sizeof(struct heapbuf_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) { 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;
...@@ -190,26 +136,12 @@ static int heapbuf_ioctl_create(struct heapbuf_cmd_args *args) ...@@ -190,26 +136,12 @@ static int heapbuf_ioctl_create(struct heapbuf_cmd_args *args)
} }
params.shared_addr = sharedregion_get_ptr((u32 *) params.shared_addr = sharedregion_get_ptr((u32 *)
cargs->cmd_arg.create.params->shared_addr); cargs->args.create.params->shared_addr);
handle = heapbuf_create(&params); handle = heapbuf_create(&params);
size = copy_to_user(&args->cmd_arg.create.handle, cargs->args.create.handle = handle;
&handle, sizeof(u32 *));
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)
heapbuf_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:
...@@ -222,27 +154,11 @@ exit: ...@@ -222,27 +154,11 @@ exit:
* Purpose: * Purpose:
* This ioctl interface to heapbuf_delete function * This ioctl interface to heapbuf_delete function
*/ */
static int heapbuf_ioctl_delete(struct heapbuf_cmd_args *args) static int heapbuf_ioctl_delete(struct heapbuf_cmd_args *cargs)
{ {
struct heapbuf_cmd_args uarg;
struct heapbuf_cmd_args *cargs = &uarg;
s32 retval = 0; s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct heapbuf_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = heapbuf_delete(cargs->cmd_arg.delete.handle);
if (retval)
goto exit;
return 0;
exit: retval = heapbuf_delete(cargs->args.delete.handle);
return retval; return retval;
} }
...@@ -251,77 +167,62 @@ exit: ...@@ -251,77 +167,62 @@ exit:
* Purpose: * Purpose:
* This ioctl interface to heapbuf_open function * This ioctl interface to heapbuf_open function
*/ */
static int heapbuf_ioctl_open(struct heapbuf_cmd_args *args) static int heapbuf_ioctl_open(struct heapbuf_cmd_args *cargs)
{ {
struct heapbuf_cmd_args uarg;
struct heapbuf_cmd_args *cargs = &uarg;
struct heapbuf_params params; struct heapbuf_params params;
void *handle = NULL; void *handle = NULL;
s32 retval = 0; s32 retval = 0;
ulong size; ulong size;
size = copy_from_user(cargs, args, size = copy_from_user(&params, cargs->args.open.params,
sizeof(struct heapbuf_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
size = copy_from_user(&params, cargs->cmd_arg.open.params,
sizeof(struct heapbuf_params)); sizeof(struct heapbuf_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,
if (params.name) { GFP_KERNEL);
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.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 copy_from_usr_error; goto free_name;
} }
} }
params.shared_addr = sharedregion_get_ptr((u32 *) params.shared_addr = sharedregion_get_ptr((u32 *)
cargs->cmd_arg.open.params->shared_addr); cargs->args.open.params->shared_addr);
retval = heapbuf_open(&handle, &params); retval = heapbuf_open(&handle, &params);
if (retval) if (retval)
goto heap_open_error; goto free_name;
size = copy_to_user(cargs->cmd_arg.open.params, &params, cargs->args.open.handle = handle;
size = copy_to_user(cargs->args.open.params, &params,
sizeof(struct heapbuf_params)); sizeof(struct heapbuf_params));
if (size) { if (size) {
retval = -EFAULT; retval = -EFAULT;
goto copy_to_usr_error; goto copy_to_usr_error;
} }
size = copy_to_user(&args->cmd_arg.open.handle, &handle, goto free_name;
sizeof(void *));
if (size) {
retval = -EFAULT;
goto copy_to_usr_error;
}
if (cargs->cmd_arg.open.name_len > 0)
kfree(params.name);
return 0;
copy_to_usr_error: copy_to_usr_error:
if (handle) {
heapbuf_close(handle); heapbuf_close(handle);
cargs->args.open.handle = NULL;
}
heap_open_error: /* Fall through */ free_name:
copy_from_usr_error: if (cargs->args.open.name_len > 0)
if (cargs->cmd_arg.open.name_len > 0)
kfree(params.name); kfree(params.name);
exit: exit:
...@@ -334,27 +235,11 @@ exit: ...@@ -334,27 +235,11 @@ exit:
* Purpose: * Purpose:
* This ioctl interface to heapbuf_close function * This ioctl interface to heapbuf_close function
*/ */
static int heapbuf_ioctl_close(struct heapbuf_cmd_args *args) static int heapbuf_ioctl_close(struct heapbuf_cmd_args *cargs)
{ {
struct heapbuf_cmd_args uarg;
struct heapbuf_cmd_args *cargs = &uarg;
s32 retval = 0; s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct heapbuf_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = heapbuf_close(cargs->cmd_arg.close.handle); retval = heapbuf_close(cargs->args.close.handle);
if (retval)
goto exit;
return 0;
exit:
return retval; return retval;
} }
...@@ -363,23 +248,14 @@ exit: ...@@ -363,23 +248,14 @@ exit:
* Purpose: * Purpose:
* This ioctl interface to heapbuf_shared_memreq function * This ioctl interface to heapbuf_shared_memreq function
*/ */
static int heapbuf_ioctl_shared_memreq(struct heapbuf_cmd_args *args) static int heapbuf_ioctl_shared_memreq(struct heapbuf_cmd_args *cargs)
{ {
struct heapbuf_cmd_args uarg;
struct heapbuf_cmd_args *cargs = &uarg;
struct heapbuf_params params; struct heapbuf_params params;
s32 retval = 0; s32 retval = 0;
ulong size; ulong size;
u32 bytes; u32 bytes;
size = copy_from_user(cargs, args, size = copy_from_user(&params, cargs->args.shared_memreq.params,
sizeof(struct heapbuf_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
size = copy_from_user(&params, cargs->cmd_arg.shared_memreq.params,
sizeof(struct heapbuf_params)); sizeof(struct heapbuf_params));
if (size) { if (size) {
retval = -EFAULT; retval = -EFAULT;
...@@ -387,14 +263,7 @@ static int heapbuf_ioctl_shared_memreq(struct heapbuf_cmd_args *args) ...@@ -387,14 +263,7 @@ static int heapbuf_ioctl_shared_memreq(struct heapbuf_cmd_args *args)
} }
bytes = heapbuf_shared_memreq(&params); bytes = heapbuf_shared_memreq(&params);
size = copy_to_user(&args->cmd_arg.shared_memreq.bytes, cargs->args.shared_memreq.bytes = bytes;
&bytes, sizeof(u32));
if (size) {
retval = -EFAULT;
goto exit;
}
return 0;
exit: exit:
return retval; return retval;
...@@ -406,32 +275,18 @@ exit: ...@@ -406,32 +275,18 @@ exit:
* Purpose: * Purpose:
* This ioctl interface to heapbuf_get_config function * This ioctl interface to heapbuf_get_config function
*/ */
static int heapbuf_ioctl_get_config(struct heapbuf_cmd_args *args) static int heapbuf_ioctl_get_config(struct heapbuf_cmd_args *cargs)
{ {
struct heapbuf_cmd_args uarg;
struct heapbuf_cmd_args *cargs = &uarg;
struct heap_config config; struct heap_config config;
s32 retval = 0; s32 retval = 0;
ulong size; ulong size;
size = copy_from_user(cargs, args,
sizeof(struct heapbuf_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = heapbuf_get_config(&config); retval = heapbuf_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 heap_config)); sizeof(struct heap_config));
if (size) { if (size)
retval = -EFAULT; retval = -EFAULT;
goto exit;
}
return 0;
exit:
return retval; return retval;
} }
...@@ -440,22 +295,13 @@ exit: ...@@ -440,22 +295,13 @@ exit:
* Purpose: * Purpose:
* This ioctl interface to heapbuf_setup function * This ioctl interface to heapbuf_setup function
*/ */
static int heapbuf_ioctl_setup(struct heapbuf_cmd_args *args) static int heapbuf_ioctl_setup(struct heapbuf_cmd_args *cargs)
{ {
struct heapbuf_cmd_args uarg;
struct heapbuf_cmd_args *cargs = &uarg;
struct heap_config config; struct heap_config config;
s32 retval = 0; s32 retval = 0;
ulong size; ulong size;
size = copy_from_user(cargs, args, size = copy_from_user(&config, cargs->args.setup.config,
sizeof(struct heapbuf_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
size = copy_from_user(&config, cargs->cmd_arg.setup.config,
sizeof(struct heap_config)); sizeof(struct heap_config));
if (size) { if (size) {
retval = -EFAULT; retval = -EFAULT;
...@@ -463,10 +309,6 @@ static int heapbuf_ioctl_setup(struct heapbuf_cmd_args *args) ...@@ -463,10 +309,6 @@ static int heapbuf_ioctl_setup(struct heapbuf_cmd_args *args)
} }
retval = heapbuf_setup(&config); retval = heapbuf_setup(&config);
if (retval)
goto exit;
return 0;
exit: exit:
return retval; return retval;
...@@ -489,33 +331,21 @@ static int heapbuf_ioctl_destroy() ...@@ -489,33 +331,21 @@ static int heapbuf_ioctl_destroy()
* Purpose: * Purpose:
* This ioctl interface to heapbuf_get_stats function * This ioctl interface to heapbuf_get_stats function
*/ */
static int heapbuf_ioctl_get_stats(struct heapbuf_cmd_args *args) static int heapbuf_ioctl_get_stats(struct heapbuf_cmd_args *cargs)
{ {
struct heapbuf_cmd_args uarg;
struct heapbuf_cmd_args *cargs = &uarg;
struct memory_stats stats; struct memory_stats stats;
s32 retval = 0; s32 retval = 0;
ulong size; ulong size;
size = copy_from_user(cargs, args,
sizeof(struct heapbuf_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = heapbuf_get_stats(cargs->cmd_arg.get_stats.handle, &stats); retval = heapbuf_get_stats(cargs->args.get_stats.handle, &stats);
if (retval) if (retval)
goto exit; goto exit;
size = copy_to_user(cargs->cmd_arg.get_stats.stats, &stats, size = copy_to_user(cargs->args.get_stats.stats, &stats,
sizeof(struct memory_stats)); sizeof(struct memory_stats));
if (size) { if (size)
retval = -EFAULT; retval = -EFAULT;
goto exit;
}
return 0;
exit: exit:
return retval; return retval;
...@@ -526,33 +356,21 @@ exit: ...@@ -526,33 +356,21 @@ exit:
* Purpose: * Purpose:
* This ioctl interface to heapbuf_get_extended_stats function * This ioctl interface to heapbuf_get_extended_stats function
*/ */
static int heapbuf_ioctl_get_extended_stats(struct heapbuf_cmd_args *args) static int heapbuf_ioctl_get_extended_stats(struct heapbuf_cmd_args *cargs)
{ {
struct heapbuf_cmd_args uarg;
struct heapbuf_cmd_args *cargs = &uarg;
struct heap_extended_stats stats; struct heap_extended_stats stats;
s32 retval = 0; s32 retval = 0;
ulong size; ulong size;
size = copy_from_user(cargs, args,
sizeof(struct heapbuf_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = heapbuf_get_extended_stats( retval = heapbuf_get_extended_stats(
cargs->cmd_arg.get_extended_stats.handle, &stats); cargs->args.get_extended_stats.handle, &stats);
if (retval) if (retval)
goto exit; goto exit;
size = copy_to_user(cargs->cmd_arg.get_extended_stats.stats, &stats,
size = copy_to_user(cargs->args.get_extended_stats.stats, &stats,
sizeof(struct heap_extended_stats)); sizeof(struct heap_extended_stats));
if (size) { if (size)
retval = -EFAULT; retval = -EFAULT;
goto exit;
}
return 0;
exit: exit:
return retval; return retval;
...@@ -566,84 +384,99 @@ exit: ...@@ -566,84 +384,99 @@ exit:
int heapbuf_ioctl(struct inode *pinode, struct file *filp, int heapbuf_ioctl(struct inode *pinode, struct file *filp,
unsigned int cmd, unsigned long args) unsigned int cmd, unsigned long args)
{ {
s32 os_status = 0;
s32 size = 0;
struct heapbuf_cmd_args __user *uarg = struct heapbuf_cmd_args __user *uarg =
(struct heapbuf_cmd_args __user *)args; (struct heapbuf_cmd_args __user *)args;
s32 retval = 0; struct heapbuf_cmd_args cargs;
gt_4trace(curTrace, GT_ENTER, "heapbuf_ioctl"
"pinode: %x, filp: %x,\n cmd: %x, args: %x",
pinode, 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; goto exit;
} }
/* Copy the full args from user-side */
size = copy_from_user(&cargs, uarg,
sizeof(struct heapbuf_cmd_args));
if (size) {
os_status = -EFAULT;
goto exit;
}
switch (cmd) { switch (cmd) {
case CMD_HEAPBUF_ALLOC: case CMD_HEAPBUF_ALLOC:
retval = heapbuf_ioctl_alloc(uarg); os_status = heapbuf_ioctl_alloc(uarg);
break; break;
case CMD_HEAPBUF_FREE: case CMD_HEAPBUF_FREE:
retval = heapbuf_ioctl_free(uarg); os_status = heapbuf_ioctl_free(uarg);
break; break;
case CMD_HEAPBUF_PARAMS_INIT: case CMD_HEAPBUF_PARAMS_INIT:
retval = heapbuf_ioctl_params_init(uarg); os_status = heapbuf_ioctl_params_init(uarg);
break; break;
case CMD_HEAPBUF_CREATE: case CMD_HEAPBUF_CREATE:
retval = heapbuf_ioctl_create(uarg); os_status = heapbuf_ioctl_create(uarg);
break; break;
case CMD_HEAPBUF_DELETE: case CMD_HEAPBUF_DELETE:
retval = heapbuf_ioctl_delete(uarg); os_status = heapbuf_ioctl_delete(uarg);
break; break;
case CMD_HEAPBUF_OPEN: case CMD_HEAPBUF_OPEN:
retval = heapbuf_ioctl_open(uarg); os_status = heapbuf_ioctl_open(uarg);
break; break;
case CMD_HEAPBUF_CLOSE: case CMD_HEAPBUF_CLOSE:
retval = heapbuf_ioctl_close(uarg); os_status = heapbuf_ioctl_close(uarg);
break; break;
case CMD_HEAPBUF_SHAREDMEMREQ: case CMD_HEAPBUF_SHAREDMEMREQ:
retval = heapbuf_ioctl_shared_memreq(uarg); os_status = heapbuf_ioctl_shared_memreq(uarg);
break; break;
case CMD_HEAPBUF_GETCONFIG: case CMD_HEAPBUF_GETCONFIG:
retval = heapbuf_ioctl_get_config(uarg); os_status = heapbuf_ioctl_get_config(uarg);
break; break;
case CMD_HEAPBUF_SETUP: case CMD_HEAPBUF_SETUP:
retval = heapbuf_ioctl_setup(uarg); os_status = heapbuf_ioctl_setup(uarg);
break; break;
case CMD_HEAPBUF_DESTROY: case CMD_HEAPBUF_DESTROY:
retval = heapbuf_ioctl_destroy(); os_status = heapbuf_ioctl_destroy();
break; break;
case CMD_HEAPBUF_GETSTATS: case CMD_HEAPBUF_GETSTATS:
retval = heapbuf_ioctl_get_stats(uarg); os_status = heapbuf_ioctl_get_stats(uarg);
break; break;
case CMD_HEAPBUF_GETEXTENDEDSTATS: case CMD_HEAPBUF_GETEXTENDEDSTATS:
retval = heapbuf_ioctl_get_extended_stats(uarg); os_status = heapbuf_ioctl_get_extended_stats(uarg);
break; break;
default: default:
WARN_ON(cmd); 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 heapbuf_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