diff options
author | Stephen Boyd <sboyd@codeaurora.org> | 2012-01-10 18:42:34 -0500 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2012-01-16 03:17:29 -0500 |
commit | 7e95fffe080d4dbe826dfe864eb084916cdc6468 (patch) | |
tree | afc65af7003d1d4fdb977e5a2cccda7b5c4ac32e /drivers/scsi | |
parent | 466c08c71a7dc19528e9b336c5bfa5ec41730c7c (diff) |
[SCSI] sg: convert to kstrtoul_from_user()
Instead of open coding this function use kstrtoul_from_user() directly.
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r-- | drivers/scsi/sg.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 02d99982a74d..eacd46bb36b9 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c | |||
@@ -2368,16 +2368,15 @@ static ssize_t | |||
2368 | sg_proc_write_adio(struct file *filp, const char __user *buffer, | 2368 | sg_proc_write_adio(struct file *filp, const char __user *buffer, |
2369 | size_t count, loff_t *off) | 2369 | size_t count, loff_t *off) |
2370 | { | 2370 | { |
2371 | int num; | 2371 | int err; |
2372 | char buff[11]; | 2372 | unsigned long num; |
2373 | 2373 | ||
2374 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) | 2374 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) |
2375 | return -EACCES; | 2375 | return -EACCES; |
2376 | num = (count < 10) ? count : 10; | 2376 | err = kstrtoul_from_user(buffer, count, 0, &num); |
2377 | if (copy_from_user(buff, buffer, num)) | 2377 | if (err) |
2378 | return -EFAULT; | 2378 | return err; |
2379 | buff[num] = '\0'; | 2379 | sg_allow_dio = num ? 1 : 0; |
2380 | sg_allow_dio = simple_strtoul(buff, NULL, 10) ? 1 : 0; | ||
2381 | return count; | 2380 | return count; |
2382 | } | 2381 | } |
2383 | 2382 | ||
@@ -2390,17 +2389,15 @@ static ssize_t | |||
2390 | sg_proc_write_dressz(struct file *filp, const char __user *buffer, | 2389 | sg_proc_write_dressz(struct file *filp, const char __user *buffer, |
2391 | size_t count, loff_t *off) | 2390 | size_t count, loff_t *off) |
2392 | { | 2391 | { |
2393 | int num; | 2392 | int err; |
2394 | unsigned long k = ULONG_MAX; | 2393 | unsigned long k = ULONG_MAX; |
2395 | char buff[11]; | ||
2396 | 2394 | ||
2397 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) | 2395 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) |
2398 | return -EACCES; | 2396 | return -EACCES; |
2399 | num = (count < 10) ? count : 10; | 2397 | |
2400 | if (copy_from_user(buff, buffer, num)) | 2398 | err = kstrtoul_from_user(buffer, count, 0, &k); |
2401 | return -EFAULT; | 2399 | if (err) |
2402 | buff[num] = '\0'; | 2400 | return err; |
2403 | k = simple_strtoul(buff, NULL, 10); | ||
2404 | if (k <= 1048576) { /* limit "big buff" to 1 MB */ | 2401 | if (k <= 1048576) { /* limit "big buff" to 1 MB */ |
2405 | sg_big_buff = k; | 2402 | sg_big_buff = k; |
2406 | return count; | 2403 | return count; |