* [patch 4/6] drivers/scsi/sg.c: convert to kstrtoul_from_user()
@ 2012-01-10 23:42 akpm
2012-01-11 0:08 ` James Bottomley
2012-01-11 13:08 ` Douglas Gilbert
0 siblings, 2 replies; 5+ messages in thread
From: akpm @ 2012-01-10 23:42 UTC (permalink / raw)
To: James.Bottomley; +Cc: linux-scsi, akpm, sboyd, dgilbert, dougg
From: Stephen Boyd <sboyd@codeaurora.org>
Subject: 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 <sboyd@codeaurora.org>
Cc: Doug Gilbert <dgilbert@interlog.com>
Cc: Douglas Gilbert <dougg@torque.net>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
drivers/scsi/sg.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff -puN drivers/scsi/sg.c~drivers-scsi-sgc-convert-to-kstrtoul_from_user drivers/scsi/sg.c
--- a/drivers/scsi/sg.c~drivers-scsi-sgc-convert-to-kstrtoul_from_user
+++ a/drivers/scsi/sg.c
@@ -2368,16 +2368,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;
}
@@ -2390,17 +2389,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;
_
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch 4/6] drivers/scsi/sg.c: convert to kstrtoul_from_user()
2012-01-10 23:42 [patch 4/6] drivers/scsi/sg.c: convert to kstrtoul_from_user() akpm
@ 2012-01-11 0:08 ` James Bottomley
2012-01-11 0:12 ` Andrew Morton
2012-01-11 13:08 ` Douglas Gilbert
1 sibling, 1 reply; 5+ messages in thread
From: James Bottomley @ 2012-01-11 0:08 UTC (permalink / raw)
To: akpm; +Cc: linux-scsi, sboyd, dgilbert, dougg
On Tue, 2012-01-10 at 15:42 -0800, akpm@linux-foundation.org wrote:
> From: Stephen Boyd <sboyd@codeaurora.org>
> Subject: drivers/scsi/sg.c: convert to kstrtoul_from_user()
>
> Instead of open coding this function use kstrtoul_from_user() directly.
I really don't like these invent post facto functions and then try to
insert them on the grounds the original users are now "open coded".
However, if doug acks (or sends it as part of an update), I'll apply.
James
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch 4/6] drivers/scsi/sg.c: convert to kstrtoul_from_user()
2012-01-11 0:08 ` James Bottomley
@ 2012-01-11 0:12 ` Andrew Morton
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2012-01-11 0:12 UTC (permalink / raw)
To: James Bottomley; +Cc: linux-scsi, sboyd, dgilbert, dougg
On Tue, 10 Jan 2012 19:08:44 -0500
James Bottomley <James.Bottomley@HansenPartnership.com> wrote:
> On Tue, 2012-01-10 at 15:42 -0800, akpm@linux-foundation.org wrote:
> > From: Stephen Boyd <sboyd@codeaurora.org>
> > Subject: drivers/scsi/sg.c: convert to kstrtoul_from_user()
> >
> > Instead of open coding this function use kstrtoul_from_user() directly.
>
> I really don't like these invent post facto functions and then try to
> insert them on the grounds the original users are now "open coded".
> However, if doug acks (or sends it as part of an update), I'll apply.
>
The main reason for adding helpers such as kstrtoul_from_user() is that
we have recognised that certain code patterns appear in multiple
places. So we add the helper and then clean up the code sites which
inspired that addition.
This is good! It's a part of our basic code maintenance.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch 4/6] drivers/scsi/sg.c: convert to kstrtoul_from_user()
2012-01-10 23:42 [patch 4/6] drivers/scsi/sg.c: convert to kstrtoul_from_user() akpm
2012-01-11 0:08 ` James Bottomley
@ 2012-01-11 13:08 ` Douglas Gilbert
1 sibling, 0 replies; 5+ messages in thread
From: Douglas Gilbert @ 2012-01-11 13:08 UTC (permalink / raw)
To: akpm; +Cc: James.Bottomley, linux-scsi, sboyd
On 12-01-11 10:42 AM, akpm@linux-foundation.org wrote:
> From: Stephen Boyd<sboyd@codeaurora.org>
> Subject: 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<sboyd@codeaurora.org>
> Cc: Doug Gilbert<dgilbert@interlog.com>
> Cc: Douglas Gilbert<dougg@torque.net>
> Cc: James Bottomley<James.Bottomley@HansenPartnership.com>
> Signed-off-by: Andrew Morton<akpm@linux-foundation.org>
Acked-by: Douglas Gilbert<dgilbert@interlog.com>
> ---
>
> drivers/scsi/sg.c | 25 +++++++++++--------------
> 1 file changed, 11 insertions(+), 14 deletions(-)
>
> diff -puN drivers/scsi/sg.c~drivers-scsi-sgc-convert-to-kstrtoul_from_user drivers/scsi/sg.c
> --- a/drivers/scsi/sg.c~drivers-scsi-sgc-convert-to-kstrtoul_from_user
> +++ a/drivers/scsi/sg.c
> @@ -2368,16 +2368,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;
> }
>
> @@ -2390,17 +2389,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;
> _
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [patch 4/6] drivers/scsi/sg.c: convert to kstrtoul_from_user()
@ 2011-11-15 22:58 akpm
0 siblings, 0 replies; 5+ messages in thread
From: akpm @ 2011-11-15 22:58 UTC (permalink / raw)
To: James.Bottomley; +Cc: linux-scsi, akpm, sboyd, dgilbert, dougg
From: Stephen Boyd <sboyd@codeaurora.org>
Subject: 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 <sboyd@codeaurora.org>
Cc: Doug Gilbert <dgilbert@interlog.com>
Cc: Douglas Gilbert <dougg@torque.net>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
drivers/scsi/sg.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff -puN drivers/scsi/sg.c~drivers-scsi-sgc-convert-to-kstrtoul_from_user drivers/scsi/sg.c
--- a/drivers/scsi/sg.c~drivers-scsi-sgc-convert-to-kstrtoul_from_user
+++ a/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;
_
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-01-11 13:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-10 23:42 [patch 4/6] drivers/scsi/sg.c: convert to kstrtoul_from_user() akpm
2012-01-11 0:08 ` James Bottomley
2012-01-11 0:12 ` Andrew Morton
2012-01-11 13:08 ` Douglas Gilbert
-- strict thread matches above, loose matches on Subject: below --
2011-11-15 22:58 akpm
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.