Skip to content

Commit 22fe9b5

Browse files
PeterHuewerostedt
authored andcommitted
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>
1 parent 749230b commit 22fe9b5

5 files changed

Lines changed: 20 additions & 110 deletions

File tree

‎kernel/trace/ftrace.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -803,19 +803,10 @@ ftrace_profile_write(struct file *filp, const char __user *ubuf,
803803
size_t cnt, loff_t *ppos)
804804
{
805805
unsigned long val;
806-
char buf[64]; /* big enough to hold a number */
807806
int ret;
808807

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)
819810
return ret;
820811

821812
val = !!val;

‎kernel/trace/ring_buffer.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3980,20 +3980,11 @@ rb_simple_write(struct file *filp, const char __user *ubuf,
39803980
size_t cnt, loff_t *ppos)
39813981
{
39823982
unsigned long *p = filp->private_data;
3983-
char buf[64];
39843983
unsigned long val;
39853984
int ret;
39863985

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)
39973988
return ret;
39983989

39993990
if (val)

‎kernel/trace/trace.c‎

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,20 +2706,11 @@ tracing_ctrl_write(struct file *filp, const char __user *ubuf,
27062706
size_t cnt, loff_t *ppos)
27072707
{
27082708
struct trace_array *tr = filp->private_data;
2709-
char buf[64];
27102709
unsigned long val;
27112710
int ret;
27122711

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)
27232714
return ret;
27242715

27252716
val = !!val;
@@ -3006,20 +2997,11 @@ tracing_max_lat_write(struct file *filp, const char __user *ubuf,
30062997
size_t cnt, loff_t *ppos)
30072998
{
30082999
unsigned long *ptr = filp->private_data;
3009-
char buf[64];
30103000
unsigned long val;
30113001
int ret;
30123002

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)
30233005
return ret;
30243006

30253007
*ptr = val * 1000;
@@ -3474,19 +3456,10 @@ tracing_entries_write(struct file *filp, const char __user *ubuf,
34743456
size_t cnt, loff_t *ppos)
34753457
{
34763458
unsigned long val;
3477-
char buf[64];
34783459
int ret;
34793460

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)
34903463
return ret;
34913464

34923465
/* must have at least 1 entry */
@@ -4139,19 +4112,10 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,
41394112
{
41404113
struct trace_option_dentry *topt = filp->private_data;
41414114
unsigned long val;
4142-
char buf[64];
41434115
int ret;
41444116

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)
41554119
return ret;
41564120

41574121
if (val != 0 && val != 1)
@@ -4199,20 +4163,11 @@ trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt,
41994163
loff_t *ppos)
42004164
{
42014165
long index = (long)filp->private_data;
4202-
char buf[64];
42034166
unsigned long val;
42044167
int ret;
42054168

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)
42164171
return ret;
42174172

42184173
if (val != 0 && val != 1)

‎kernel/trace/trace_events.c‎

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -486,20 +486,11 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
486486
loff_t *ppos)
487487
{
488488
struct ftrace_event_call *call = filp->private_data;
489-
char buf[64];
490489
unsigned long val;
491490
int ret;
492491

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)
503494
return ret;
504495

505496
ret = tracing_update_buffers();
@@ -571,19 +562,10 @@ system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
571562
{
572563
const char *system = filp->private_data;
573564
unsigned long val;
574-
char buf[64];
575565
ssize_t ret;
576566

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)
587569
return ret;
588570

589571
ret = tracing_update_buffers();

‎kernel/trace/trace_stack.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,11 @@ stack_max_size_write(struct file *filp, const char __user *ubuf,
156156
{
157157
long *ptr = filp->private_data;
158158
unsigned long val, flags;
159-
char buf[64];
160159
int ret;
161160
int cpu;
162161

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)
173164
return ret;
174165

175166
local_irq_save(flags);

0 commit comments

Comments
 (0)