Commit 22fe9b54d859e53bfbbbdc1a0a77a82bc453927c

Authored by Peter Huewe
Committed by Steven Rostedt
1 parent 749230b06a

tracing: Convert to kstrtoul_from_user

This patch replaces the code for getting an unsigned long from a
userspace buffer by a simple call to kstroul_from_user.
This makes it easier to read and less error prone.

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Link: http://lkml.kernel.org/r/1307476707-14762-1-git-send-email-peterhuewe@gmx.de
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

Showing 5 changed files with 20 additions and 110 deletions Side-by-side Diff

kernel/trace/ftrace.c
... ... @@ -803,19 +803,10 @@
803 803 size_t cnt, loff_t *ppos)
804 804 {
805 805 unsigned long val;
806   - char buf[64]; /* big enough to hold a number */
807 806 int ret;
808 807  
809   - if (cnt >= sizeof(buf))
810   - return -EINVAL;
811   -
812   - if (copy_from_user(&buf, ubuf, cnt))
813   - return -EFAULT;
814   -
815   - buf[cnt] = 0;
816   -
817   - ret = strict_strtoul(buf, 10, &val);
818   - if (ret < 0)
  808 + ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
  809 + if (ret)
819 810 return ret;
820 811  
821 812 val = !!val;
kernel/trace/ring_buffer.c
... ... @@ -3980,20 +3980,11 @@
3980 3980 size_t cnt, loff_t *ppos)
3981 3981 {
3982 3982 unsigned long *p = filp->private_data;
3983   - char buf[64];
3984 3983 unsigned long val;
3985 3984 int ret;
3986 3985  
3987   - if (cnt >= sizeof(buf))
3988   - return -EINVAL;
3989   -
3990   - if (copy_from_user(&buf, ubuf, cnt))
3991   - return -EFAULT;
3992   -
3993   - buf[cnt] = 0;
3994   -
3995   - ret = strict_strtoul(buf, 10, &val);
3996   - if (ret < 0)
  3986 + ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
  3987 + if (ret)
3997 3988 return ret;
3998 3989  
3999 3990 if (val)
kernel/trace/trace.c
... ... @@ -2706,20 +2706,11 @@
2706 2706 size_t cnt, loff_t *ppos)
2707 2707 {
2708 2708 struct trace_array *tr = filp->private_data;
2709   - char buf[64];
2710 2709 unsigned long val;
2711 2710 int ret;
2712 2711  
2713   - if (cnt >= sizeof(buf))
2714   - return -EINVAL;
2715   -
2716   - if (copy_from_user(&buf, ubuf, cnt))
2717   - return -EFAULT;
2718   -
2719   - buf[cnt] = 0;
2720   -
2721   - ret = strict_strtoul(buf, 10, &val);
2722   - if (ret < 0)
  2712 + ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
  2713 + if (ret)
2723 2714 return ret;
2724 2715  
2725 2716 val = !!val;
2726 2717  
... ... @@ -3006,20 +2997,11 @@
3006 2997 size_t cnt, loff_t *ppos)
3007 2998 {
3008 2999 unsigned long *ptr = filp->private_data;
3009   - char buf[64];
3010 3000 unsigned long val;
3011 3001 int ret;
3012 3002  
3013   - if (cnt >= sizeof(buf))
3014   - return -EINVAL;
3015   -
3016   - if (copy_from_user(&buf, ubuf, cnt))
3017   - return -EFAULT;
3018   -
3019   - buf[cnt] = 0;
3020   -
3021   - ret = strict_strtoul(buf, 10, &val);
3022   - if (ret < 0)
  3003 + ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
  3004 + if (ret)
3023 3005 return ret;
3024 3006  
3025 3007 *ptr = val * 1000;
3026 3008  
... ... @@ -3474,19 +3456,10 @@
3474 3456 size_t cnt, loff_t *ppos)
3475 3457 {
3476 3458 unsigned long val;
3477   - char buf[64];
3478 3459 int ret;
3479 3460  
3480   - if (cnt >= sizeof(buf))
3481   - return -EINVAL;
3482   -
3483   - if (copy_from_user(&buf, ubuf, cnt))
3484   - return -EFAULT;
3485   -
3486   - buf[cnt] = 0;
3487   -
3488   - ret = strict_strtoul(buf, 10, &val);
3489   - if (ret < 0)
  3461 + ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
  3462 + if (ret)
3490 3463 return ret;
3491 3464  
3492 3465 /* must have at least 1 entry */
3493 3466  
... ... @@ -4139,19 +4112,10 @@
4139 4112 {
4140 4113 struct trace_option_dentry *topt = filp->private_data;
4141 4114 unsigned long val;
4142   - char buf[64];
4143 4115 int ret;
4144 4116  
4145   - if (cnt >= sizeof(buf))
4146   - return -EINVAL;
4147   -
4148   - if (copy_from_user(&buf, ubuf, cnt))
4149   - return -EFAULT;
4150   -
4151   - buf[cnt] = 0;
4152   -
4153   - ret = strict_strtoul(buf, 10, &val);
4154   - if (ret < 0)
  4117 + ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
  4118 + if (ret)
4155 4119 return ret;
4156 4120  
4157 4121 if (val != 0 && val != 1)
4158 4122  
... ... @@ -4199,20 +4163,11 @@
4199 4163 loff_t *ppos)
4200 4164 {
4201 4165 long index = (long)filp->private_data;
4202   - char buf[64];
4203 4166 unsigned long val;
4204 4167 int ret;
4205 4168  
4206   - if (cnt >= sizeof(buf))
4207   - return -EINVAL;
4208   -
4209   - if (copy_from_user(&buf, ubuf, cnt))
4210   - return -EFAULT;
4211   -
4212   - buf[cnt] = 0;
4213   -
4214   - ret = strict_strtoul(buf, 10, &val);
4215   - if (ret < 0)
  4169 + ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
  4170 + if (ret)
4216 4171 return ret;
4217 4172  
4218 4173 if (val != 0 && val != 1)
kernel/trace/trace_events.c
... ... @@ -486,20 +486,11 @@
486 486 loff_t *ppos)
487 487 {
488 488 struct ftrace_event_call *call = filp->private_data;
489   - char buf[64];
490 489 unsigned long val;
491 490 int ret;
492 491  
493   - if (cnt >= sizeof(buf))
494   - return -EINVAL;
495   -
496   - if (copy_from_user(&buf, ubuf, cnt))
497   - return -EFAULT;
498   -
499   - buf[cnt] = 0;
500   -
501   - ret = strict_strtoul(buf, 10, &val);
502   - if (ret < 0)
  492 + ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
  493 + if (ret)
503 494 return ret;
504 495  
505 496 ret = tracing_update_buffers();
506 497  
... ... @@ -571,19 +562,10 @@
571 562 {
572 563 const char *system = filp->private_data;
573 564 unsigned long val;
574   - char buf[64];
575 565 ssize_t ret;
576 566  
577   - if (cnt >= sizeof(buf))
578   - return -EINVAL;
579   -
580   - if (copy_from_user(&buf, ubuf, cnt))
581   - return -EFAULT;
582   -
583   - buf[cnt] = 0;
584   -
585   - ret = strict_strtoul(buf, 10, &val);
586   - if (ret < 0)
  567 + ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
  568 + if (ret)
587 569 return ret;
588 570  
589 571 ret = tracing_update_buffers();
kernel/trace/trace_stack.c
... ... @@ -156,20 +156,11 @@
156 156 {
157 157 long *ptr = filp->private_data;
158 158 unsigned long val, flags;
159   - char buf[64];
160 159 int ret;
161 160 int cpu;
162 161  
163   - if (count >= sizeof(buf))
164   - return -EINVAL;
165   -
166   - if (copy_from_user(&buf, ubuf, count))
167   - return -EFAULT;
168   -
169   - buf[count] = 0;
170   -
171   - ret = strict_strtoul(buf, 10, &val);
172   - if (ret < 0)
  162 + ret = kstrtoul_from_user(ubuf, count, 10, &val);
  163 + if (ret)
173 164 return ret;
174 165  
175 166 local_irq_save(flags);