Commit c1de8ad2 authored by Ramesh Gupta's avatar Ramesh Gupta Committed by Hari Kanigeri

Cleanup for ducati ioctl

removed osStatus and optimized the code.
Signed-off-by: default avatarRamesh Gupta G <grgupta@ti.com>
parent 5d63f210
...@@ -102,8 +102,7 @@ static int drvducati_ioctl(struct inode *inode, ...@@ -102,8 +102,7 @@ static int drvducati_ioctl(struct inode *inode,
unsigned long args) unsigned long args)
{ {
int status = 0; int status = 0;
int osStatus = 0; int retval = 0;
int retVal = 0;
struct notify_ducatidrv_cmdargs *cmd_args = struct notify_ducatidrv_cmdargs *cmd_args =
(struct notify_ducatidrv_cmdargs *) args; (struct notify_ducatidrv_cmdargs *) args;
struct notify_ducatidrv_cmdargs common_args; struct notify_ducatidrv_cmdargs common_args;
...@@ -115,13 +114,13 @@ static int drvducati_ioctl(struct inode *inode, ...@@ -115,13 +114,13 @@ static int drvducati_ioctl(struct inode *inode,
struct notify_ducatidrv_config cfg; struct notify_ducatidrv_config cfg;
notify_ducatidrv_getconfig(&cfg); notify_ducatidrv_getconfig(&cfg);
if (osStatus == 0) { retval = copy_to_user((void *)(src_args->cfg),
retVal = copy_to_user((void *)(src_args->cfg),
(const void *) &cfg, (const void *) &cfg,
sizeof(struct notify_ducatidrv_config)); sizeof(struct notify_ducatidrv_config));
if (retVal != 0)
osStatus = -EFAULT; if (WARN_ON(retval != 0))
} goto func_end;
} }
break; break;
...@@ -129,17 +128,16 @@ static int drvducati_ioctl(struct inode *inode, ...@@ -129,17 +128,16 @@ static int drvducati_ioctl(struct inode *inode,
struct notify_ducatidrv_cmdargs_setup *src_args = struct notify_ducatidrv_cmdargs_setup *src_args =
(struct notify_ducatidrv_cmdargs_setup *) args; (struct notify_ducatidrv_cmdargs_setup *) args;
struct notify_ducatidrv_config cfg; struct notify_ducatidrv_config cfg;
retVal = copy_from_user((void *) &cfg, retval = copy_from_user((void *) &cfg,
(const void *)(src_args->cfg), (const void *)(src_args->cfg),
sizeof(struct notify_ducatidrv_config)); sizeof(struct notify_ducatidrv_config));
if (retVal != 0) { if (WARN_ON(retval != 0))
osStatus = -EFAULT; goto func_end;
} else {
status = notify_ducatidrv_setup(&cfg); status = notify_ducatidrv_setup(&cfg);
if (status < 0) if (status < 0)
printk(KERN_ERR "FAIL: notify_ducatidrv_setup\n"); printk(KERN_ERR "FAIL: notify_ducatidrv_setup\n");
} }
}
break; break;
case CMD_NOTIFYDRIVERSHM_DESTROY: { case CMD_NOTIFYDRIVERSHM_DESTROY: {
...@@ -153,33 +151,29 @@ static int drvducati_ioctl(struct inode *inode, ...@@ -153,33 +151,29 @@ static int drvducati_ioctl(struct inode *inode,
case CMD_NOTIFYDRIVERSHM_PARAMS_INIT: { case CMD_NOTIFYDRIVERSHM_PARAMS_INIT: {
struct notify_ducatidrv_cmdargs_paramsinit src_args; struct notify_ducatidrv_cmdargs_paramsinit src_args;
struct notify_ducatidrv_params params; struct notify_ducatidrv_params params;
retVal = copy_from_user((void *) &src_args, retval = copy_from_user((void *) &src_args,
(const void *)(args), (const void *)(args),
sizeof( sizeof(
struct notify_ducatidrv_cmdargs_paramsinit)); struct notify_ducatidrv_cmdargs_paramsinit));
if (retVal != 0) if (WARN_ON(retval != 0))
osStatus = -EFAULT; goto func_end;
else
notify_ducatidrv_params_init(src_args.handle, &params); notify_ducatidrv_params_init(src_args.handle, &params);
if (osStatus == 0) { retval = copy_to_user((void *)(src_args.params),
retVal = copy_to_user((void *)(src_args.params),
(const void *) &params, (const void *) &params,
sizeof(struct notify_ducatidrv_params)); sizeof(struct notify_ducatidrv_params));
if (retVal != 0) if (WARN_ON(retval != 0))
osStatus = -EFAULT; goto func_end;
}
} }
break; break;
case CMD_NOTIFYDRIVERSHM_CREATE: { case CMD_NOTIFYDRIVERSHM_CREATE: {
struct notify_ducatidrv_cmdargs_create src_args; struct notify_ducatidrv_cmdargs_create src_args;
retVal = copy_from_user((void *) &src_args, retval = copy_from_user((void *) &src_args,
(const void *)(args), (const void *)(args),
sizeof(struct notify_ducatidrv_cmdargs_create)); sizeof(struct notify_ducatidrv_cmdargs_create));
if (retVal != 0) if (WARN_ON(retval != 0))
osStatus = -EFAULT; goto func_end;
else {
src_args.handle = notify_ducatidrv_create( src_args.handle = notify_ducatidrv_create(
src_args.driverName, src_args.driverName,
&(src_args.params)); &(src_args.params));
...@@ -189,104 +183,89 @@ static int drvducati_ioctl(struct inode *inode, ...@@ -189,104 +183,89 @@ static int drvducati_ioctl(struct inode *inode,
"NotifyDriverShm_create failed", "NotifyDriverShm_create failed",
status); status);
} }
} retval = copy_to_user((void *)(args),
if (osStatus == 0) {
retVal = copy_to_user((void *)(args),
(const void *) &src_args, (const void *) &src_args,
sizeof(struct notify_ducatidrv_cmdargs_create)); sizeof(struct notify_ducatidrv_cmdargs_create));
if (retVal != 0) if (WARN_ON(retval != 0))
osStatus = -EFAULT; goto func_end;
}
} }
break; break;
case CMD_NOTIFYDRIVERSHM_DELETE: { case CMD_NOTIFYDRIVERSHM_DELETE: {
struct notify_ducatidrv_cmdargs_delete src_args; struct notify_ducatidrv_cmdargs_delete src_args;
retVal = copy_from_user((void *) &src_args, retval = copy_from_user((void *) &src_args,
(const void *)(args), (const void *)(args),
sizeof(struct notify_ducatidrv_cmdargs_delete)); sizeof(struct notify_ducatidrv_cmdargs_delete));
if (WARN_ON(retval != 0))
goto func_end;
if (retVal != 0)
osStatus = -EFAULT;
else {
status = notify_ducatidrv_delete(&(src_args.handle)); status = notify_ducatidrv_delete(&(src_args.handle));
if (status < 0) if (status < 0)
printk(KERN_ERR "drvducati_ioctl:" printk(KERN_ERR "drvducati_ioctl:"
" notify_ducatidrv_delete failed" " notify_ducatidrv_delete failed"
" status = %d\n", status); " status = %d\n", status);
} }
}
break; break;
case CMD_NOTIFYDRIVERSHM_OPEN: { case CMD_NOTIFYDRIVERSHM_OPEN: {
struct notify_ducatidrv_cmdargs_open src_args; struct notify_ducatidrv_cmdargs_open src_args;
retVal = copy_from_user((void *) &src_args, retval = copy_from_user((void *) &src_args,
(const void *)(args), (const void *)(args),
sizeof(struct notify_ducatidrv_cmdargs_open)); sizeof(struct notify_ducatidrv_cmdargs_open));
if (retVal != 0) { if (WARN_ON(retval != 0))
osStatus = -EFAULT; goto func_end;
} else {
status = notify_ducatidrv_open(src_args.driverName, status = notify_ducatidrv_open(src_args.driverName,
&(src_args.handle)); &(src_args.handle));
if (status < 0) if (status < 0)
printk(KERN_ERR "drvducati_ioctl:" printk(KERN_ERR "drvducati_ioctl:"
" notify_ducatidrv_open failed" " notify_ducatidrv_open failed"
" status = %d\n", status); " status = %d\n", status);
} retval = copy_to_user((void *)(args),
if (osStatus == 0) {
retVal = copy_to_user((void *)(args),
(const void *) &src_args, (const void *) &src_args,
sizeof( sizeof(struct notify_ducatidrv_cmdargs_open));
struct notify_ducatidrv_cmdargs_open)); if (WARN_ON(retval != 0))
if (retVal != 0) goto func_end;
osStatus = -EFAULT;
}
} }
break; break;
case CMD_NOTIFYDRIVERSHM_CLOSE: { case CMD_NOTIFYDRIVERSHM_CLOSE: {
struct notify_ducatidrv_cmdargs_close src_args; struct notify_ducatidrv_cmdargs_close src_args;
retVal = copy_from_user((void *) &src_args, retval = copy_from_user((void *) &src_args,
(const void *)(args), (const void *)(args),
sizeof(struct notify_ducatidrv_cmdargs_close)); sizeof(struct notify_ducatidrv_cmdargs_close));
if (retVal != 0) { if (WARN_ON(retval != 0))
osStatus = -EFAULT; goto func_end;
} else {
status = notify_ducatidrv_close(&(src_args.handle)); status = notify_ducatidrv_close(&(src_args.handle));
if (status < 0) if (status < 0)
printk(KERN_ERR "drvducati_ioctl:" printk(KERN_ERR "drvducati_ioctl:"
" notify_ducatidrv_close" " notify_ducatidrv_close"
" failed status = %d\n", status); " failed status = %d\n", status);
} }
}
break; break;
default: { default: {
status = -EINVAL; status = -EINVAL;
osStatus = -EINVAL;
printk(KERN_ERR "drivducati_ioctl:Unsupported" printk(KERN_ERR "drivducati_ioctl:Unsupported"
" ioctl command specified"); " ioctl command specified");
} }
break; break;
} }
func_end:
/* Set the status and copy the common args to user-side. */ /* Set the status and copy the common args to user-side. */
common_args.api_status = status; common_args.api_status = status;
retVal = copy_to_user((void *) cmd_args, status = copy_to_user((void *) cmd_args,
(const void *) &common_args, (const void *) &common_args,
sizeof(struct notify_ducatidrv_cmdargs)); sizeof(struct notify_ducatidrv_cmdargs));
if (retVal != 0) { if (status < 0)
osStatus = -EFAULT; retval = -EFAULT;
} else {
if (status == -ERESTARTSYS)
osStatus = -ERESTARTSYS;
}
return osStatus; return retval;
} }
......
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