aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2013-08-23 05:38:32 -0400
committerWim Van Sebroeck <wim@iguana.be>2013-11-17 13:36:59 -0500
commita20a99fbb88ac58c2e118e8759967d1cd7355322 (patch)
treefad8c2ce78aa51b679d0ac0a561d3216d92eef31
parentcfff96e69f05176afd0e58d3a8c853a6d68ce544 (diff)
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: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@iguana.be> --
-rw-r--r--drivers/watchdog/ts72xx_wdt.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/drivers/watchdog/ts72xx_wdt.c b/drivers/watchdog/ts72xx_wdt.c
index c9b0c627fe7e..df5dd55b9b3a 100644
--- a/drivers/watchdog/ts72xx_wdt.c
+++ b/drivers/watchdog/ts72xx_wdt.c
@@ -305,7 +305,8 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd,
305 305
306 switch (cmd) { 306 switch (cmd) {
307 case WDIOC_GETSUPPORT: 307 case WDIOC_GETSUPPORT:
308 error = copy_to_user(argp, &winfo, sizeof(winfo)); 308 if (copy_to_user(argp, &winfo, sizeof(winfo)))
309 error = -EFAULT;
309 break; 310 break;
310 311
311 case WDIOC_GETSTATUS: 312 case WDIOC_GETSTATUS:
@@ -320,10 +321,9 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd,
320 case WDIOC_SETOPTIONS: { 321 case WDIOC_SETOPTIONS: {
321 int options; 322 int options;
322 323
323 if (get_user(options, p)) { 324 error = get_user(options, p);
324 error = -EFAULT; 325 if (error)
325 break; 326 break;
326 }
327 327
328 error = -EINVAL; 328 error = -EINVAL;
329 329
@@ -341,30 +341,26 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd,
341 341
342 case WDIOC_SETTIMEOUT: { 342 case WDIOC_SETTIMEOUT: {
343 int new_timeout; 343 int new_timeout;
344 int regval;
344 345
345 if (get_user(new_timeout, p)) { 346 error = get_user(new_timeout, p);
346 error = -EFAULT;
347 } else {
348 int regval;
349
350 regval = timeout_to_regval(new_timeout);
351 if (regval < 0) {
352 error = -EINVAL;
353 } else {
354 ts72xx_wdt_stop(wdt);
355 wdt->regval = regval;
356 ts72xx_wdt_start(wdt);
357 }
358 }
359 if (error) 347 if (error)
360 break; 348 break;
361 349
350 regval = timeout_to_regval(new_timeout);
351 if (regval < 0) {
352 error = regval;
353 break;
354 }
355 ts72xx_wdt_stop(wdt);
356 wdt->regval = regval;
357 ts72xx_wdt_start(wdt);
358
362 /*FALLTHROUGH*/ 359 /*FALLTHROUGH*/
363 } 360 }
364 361
365 case WDIOC_GETTIMEOUT: 362 case WDIOC_GETTIMEOUT:
366 if (put_user(regval_to_timeout(wdt->regval), p)) 363 error = put_user(regval_to_timeout(wdt->regval), p);
367 error = -EFAULT;
368 break; 364 break;
369 365
370 default: 366 default: