diff options
author | Peter Huewe <peterhuewe@gmx.de> | 2011-06-07 15:58:27 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-06-14 22:48:50 -0400 |
commit | 22fe9b54d859e53bfbbbdc1a0a77a82bc453927c (patch) | |
tree | 4aec2d069decbe0786ad5474908f5bbe49732ad4 /kernel/trace | |
parent | 749230b06a753a22f6ed96e5dd60815d6ab12865 (diff) |
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>
Diffstat (limited to 'kernel/trace')
-rw-r--r-- | kernel/trace/ftrace.c | 13 | ||||
-rw-r--r-- | kernel/trace/ring_buffer.c | 13 | ||||
-rw-r--r-- | kernel/trace/trace.c | 65 | ||||
-rw-r--r-- | kernel/trace/trace_events.c | 26 | ||||
-rw-r--r-- | kernel/trace/trace_stack.c | 13 |
5 files changed, 20 insertions, 110 deletions
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index e1538071660d..458018a1ac9a 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -803,19 +803,10 @@ ftrace_profile_write(struct file *filp, const char __user *ubuf, | |||
803 | size_t cnt, loff_t *ppos) | 803 | size_t cnt, loff_t *ppos) |
804 | { | 804 | { |
805 | unsigned long val; | 805 | unsigned long val; |
806 | char buf[64]; /* big enough to hold a number */ | ||
807 | int ret; | 806 | int ret; |
808 | 807 | ||
809 | if (cnt >= sizeof(buf)) | 808 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
810 | return -EINVAL; | 809 | if (ret) |
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) | ||
819 | return ret; | 810 | return ret; |
820 | 811 | ||
821 | val = !!val; | 812 | val = !!val; |
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 725153d6cf73..f00ede314eb6 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c | |||
@@ -3980,20 +3980,11 @@ rb_simple_write(struct file *filp, const char __user *ubuf, | |||
3980 | size_t cnt, loff_t *ppos) | 3980 | size_t cnt, loff_t *ppos) |
3981 | { | 3981 | { |
3982 | unsigned long *p = filp->private_data; | 3982 | unsigned long *p = filp->private_data; |
3983 | char buf[64]; | ||
3984 | unsigned long val; | 3983 | unsigned long val; |
3985 | int ret; | 3984 | int ret; |
3986 | 3985 | ||
3987 | if (cnt >= sizeof(buf)) | 3986 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
3988 | return -EINVAL; | 3987 | if (ret) |
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) | ||
3997 | return ret; | 3988 | return ret; |
3998 | 3989 | ||
3999 | if (val) | 3990 | if (val) |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index cf22b4bf9896..c977018e87c2 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -2706,20 +2706,11 @@ tracing_ctrl_write(struct file *filp, const char __user *ubuf, | |||
2706 | size_t cnt, loff_t *ppos) | 2706 | size_t cnt, loff_t *ppos) |
2707 | { | 2707 | { |
2708 | struct trace_array *tr = filp->private_data; | 2708 | struct trace_array *tr = filp->private_data; |
2709 | char buf[64]; | ||
2710 | unsigned long val; | 2709 | unsigned long val; |
2711 | int ret; | 2710 | int ret; |
2712 | 2711 | ||
2713 | if (cnt >= sizeof(buf)) | 2712 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
2714 | return -EINVAL; | 2713 | if (ret) |
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) | ||
2723 | return ret; | 2714 | return ret; |
2724 | 2715 | ||
2725 | val = !!val; | 2716 | val = !!val; |
@@ -3006,20 +2997,11 @@ tracing_max_lat_write(struct file *filp, const char __user *ubuf, | |||
3006 | size_t cnt, loff_t *ppos) | 2997 | size_t cnt, loff_t *ppos) |
3007 | { | 2998 | { |
3008 | unsigned long *ptr = filp->private_data; | 2999 | unsigned long *ptr = filp->private_data; |
3009 | char buf[64]; | ||
3010 | unsigned long val; | 3000 | unsigned long val; |
3011 | int ret; | 3001 | int ret; |
3012 | 3002 | ||
3013 | if (cnt >= sizeof(buf)) | 3003 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
3014 | return -EINVAL; | 3004 | if (ret) |
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) | ||
3023 | return ret; | 3005 | return ret; |
3024 | 3006 | ||
3025 | *ptr = val * 1000; | 3007 | *ptr = val * 1000; |
@@ -3474,19 +3456,10 @@ tracing_entries_write(struct file *filp, const char __user *ubuf, | |||
3474 | size_t cnt, loff_t *ppos) | 3456 | size_t cnt, loff_t *ppos) |
3475 | { | 3457 | { |
3476 | unsigned long val; | 3458 | unsigned long val; |
3477 | char buf[64]; | ||
3478 | int ret; | 3459 | int ret; |
3479 | 3460 | ||
3480 | if (cnt >= sizeof(buf)) | 3461 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
3481 | return -EINVAL; | 3462 | if (ret) |
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) | ||
3490 | return ret; | 3463 | return ret; |
3491 | 3464 | ||
3492 | /* must have at least 1 entry */ | 3465 | /* must have at least 1 entry */ |
@@ -4139,19 +4112,10 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, | |||
4139 | { | 4112 | { |
4140 | struct trace_option_dentry *topt = filp->private_data; | 4113 | struct trace_option_dentry *topt = filp->private_data; |
4141 | unsigned long val; | 4114 | unsigned long val; |
4142 | char buf[64]; | ||
4143 | int ret; | 4115 | int ret; |
4144 | 4116 | ||
4145 | if (cnt >= sizeof(buf)) | 4117 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
4146 | return -EINVAL; | 4118 | if (ret) |
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) | ||
4155 | return ret; | 4119 | return ret; |
4156 | 4120 | ||
4157 | if (val != 0 && val != 1) | 4121 | if (val != 0 && val != 1) |
@@ -4199,20 +4163,11 @@ trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, | |||
4199 | loff_t *ppos) | 4163 | loff_t *ppos) |
4200 | { | 4164 | { |
4201 | long index = (long)filp->private_data; | 4165 | long index = (long)filp->private_data; |
4202 | char buf[64]; | ||
4203 | unsigned long val; | 4166 | unsigned long val; |
4204 | int ret; | 4167 | int ret; |
4205 | 4168 | ||
4206 | if (cnt >= sizeof(buf)) | 4169 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
4207 | return -EINVAL; | 4170 | if (ret) |
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) | ||
4216 | return ret; | 4171 | return ret; |
4217 | 4172 | ||
4218 | if (val != 0 && val != 1) | 4173 | if (val != 0 && val != 1) |
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 686ec399f2a8..4d7e1498ae91 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c | |||
@@ -486,20 +486,11 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, | |||
486 | loff_t *ppos) | 486 | loff_t *ppos) |
487 | { | 487 | { |
488 | struct ftrace_event_call *call = filp->private_data; | 488 | struct ftrace_event_call *call = filp->private_data; |
489 | char buf[64]; | ||
490 | unsigned long val; | 489 | unsigned long val; |
491 | int ret; | 490 | int ret; |
492 | 491 | ||
493 | if (cnt >= sizeof(buf)) | 492 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
494 | return -EINVAL; | 493 | if (ret) |
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) | ||
503 | return ret; | 494 | return ret; |
504 | 495 | ||
505 | ret = tracing_update_buffers(); | 496 | ret = tracing_update_buffers(); |
@@ -571,19 +562,10 @@ system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, | |||
571 | { | 562 | { |
572 | const char *system = filp->private_data; | 563 | const char *system = filp->private_data; |
573 | unsigned long val; | 564 | unsigned long val; |
574 | char buf[64]; | ||
575 | ssize_t ret; | 565 | ssize_t ret; |
576 | 566 | ||
577 | if (cnt >= sizeof(buf)) | 567 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
578 | return -EINVAL; | 568 | if (ret) |
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) | ||
587 | return ret; | 569 | return ret; |
588 | 570 | ||
589 | ret = tracing_update_buffers(); | 571 | ret = tracing_update_buffers(); |
diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c index b0b53b8e4c25..77575b386d97 100644 --- a/kernel/trace/trace_stack.c +++ b/kernel/trace/trace_stack.c | |||
@@ -156,20 +156,11 @@ stack_max_size_write(struct file *filp, const char __user *ubuf, | |||
156 | { | 156 | { |
157 | long *ptr = filp->private_data; | 157 | long *ptr = filp->private_data; |
158 | unsigned long val, flags; | 158 | unsigned long val, flags; |
159 | char buf[64]; | ||
160 | int ret; | 159 | int ret; |
161 | int cpu; | 160 | int cpu; |
162 | 161 | ||
163 | if (count >= sizeof(buf)) | 162 | ret = kstrtoul_from_user(ubuf, count, 10, &val); |
164 | return -EINVAL; | 163 | if (ret) |
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) | ||
173 | return ret; | 164 | return ret; |
174 | 165 | ||
175 | local_irq_save(flags); | 166 | local_irq_save(flags); |