提交 a20a99fb 编写于 作者: D Dan Carpenter 提交者: Wim Van Sebroeck

watchdog: ts72xx_wdt: cleanup return codes in ioctl

There seems to be some confusion here which functions return positive
numbers and which return negative error codes.

copy_to_user() returns the number of bytes remaining to be copied but we
want to return -EFAULT.

The rest is just clean up.  get_user() actually returns zero on success
and -EFAULT on error so we can preserve the error code.  The
timeout_to_regval() function returns -EINVAL on failure, but we can
propogate that back instead of hardcoding -EINVAL ourselves.
Signed-off-by: NDan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: NGuenter Roeck <linux@roeck-us.net>
Signed-off-by: NWim Van Sebroeck <wim@iguana.be>
--
上级 cfff96e6
...@@ -305,7 +305,8 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd, ...@@ -305,7 +305,8 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd,
switch (cmd) { switch (cmd) {
case WDIOC_GETSUPPORT: case WDIOC_GETSUPPORT:
error = copy_to_user(argp, &winfo, sizeof(winfo)); if (copy_to_user(argp, &winfo, sizeof(winfo)))
error = -EFAULT;
break; break;
case WDIOC_GETSTATUS: case WDIOC_GETSTATUS:
...@@ -320,10 +321,9 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd, ...@@ -320,10 +321,9 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd,
case WDIOC_SETOPTIONS: { case WDIOC_SETOPTIONS: {
int options; int options;
if (get_user(options, p)) { error = get_user(options, p);
error = -EFAULT; if (error)
break; break;
}
error = -EINVAL; error = -EINVAL;
...@@ -341,30 +341,26 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd, ...@@ -341,30 +341,26 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd,
case WDIOC_SETTIMEOUT: { case WDIOC_SETTIMEOUT: {
int new_timeout; int new_timeout;
if (get_user(new_timeout, p)) {
error = -EFAULT;
} else {
int regval; int regval;
error = get_user(new_timeout, p);
if (error)
break;
regval = timeout_to_regval(new_timeout); regval = timeout_to_regval(new_timeout);
if (regval < 0) { if (regval < 0) {
error = -EINVAL; error = regval;
} else { break;
}
ts72xx_wdt_stop(wdt); ts72xx_wdt_stop(wdt);
wdt->regval = regval; wdt->regval = regval;
ts72xx_wdt_start(wdt); ts72xx_wdt_start(wdt);
}
}
if (error)
break;
/*FALLTHROUGH*/ /*FALLTHROUGH*/
} }
case WDIOC_GETTIMEOUT: case WDIOC_GETTIMEOUT:
if (put_user(regval_to_timeout(wdt->regval), p)) error = put_user(regval_to_timeout(wdt->regval), p);
error = -EFAULT;
break; break;
default: default:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册