From: Stephen Boyd Date: Wed, 30 Nov 2011 04:07:59 +0000 (+1100) Subject: drivers/scsi/sg.c: convert to kstrtoul_from_user() X-Git-Tag: next-20111130~3^2~146 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=c2233c6f2b5c1e9e57994fd7d1a8379d7ba8f7b9;p=karo-tx-linux.git drivers/scsi/sg.c: convert to kstrtoul_from_user() Instead of open coding this function use kstrtoul_from_user() directly. Signed-off-by: Stephen Boyd Cc: Doug Gilbert Cc: Douglas Gilbert Cc: James Bottomley Signed-off-by: Andrew Morton --- diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 441a1c5b8974..6b35b72504e2 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -2369,16 +2369,15 @@ static ssize_t sg_proc_write_adio(struct file *filp, const char __user *buffer, size_t count, loff_t *off) { - int num; - char buff[11]; + int err; + unsigned long num; if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) return -EACCES; - num = (count < 10) ? count : 10; - if (copy_from_user(buff, buffer, num)) - return -EFAULT; - buff[num] = '\0'; - sg_allow_dio = simple_strtoul(buff, NULL, 10) ? 1 : 0; + err = kstrtoul_from_user(buffer, count, 0, &num); + if (err) + return err; + sg_allow_dio = num ? 1 : 0; return count; } @@ -2391,17 +2390,15 @@ static ssize_t sg_proc_write_dressz(struct file *filp, const char __user *buffer, size_t count, loff_t *off) { - int num; + int err; unsigned long k = ULONG_MAX; - char buff[11]; if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) return -EACCES; - num = (count < 10) ? count : 10; - if (copy_from_user(buff, buffer, num)) - return -EFAULT; - buff[num] = '\0'; - k = simple_strtoul(buff, NULL, 10); + + err = kstrtoul_from_user(buffer, count, 0, &k); + if (err) + return err; if (k <= 1048576) { /* limit "big buff" to 1 MB */ sg_big_buff = k; return count;