Commit 22fe9b54 authored by Peter Huewe's avatar Peter Huewe Committed by Steven Rostedt

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: default avatarPeter Huewe <peterhuewe@gmx.de>
Link: http://lkml.kernel.org/r/1307476707-14762-1-git-send-email-peterhuewe@gmx.deSigned-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 749230b0
...@@ -803,19 +803,10 @@ ftrace_profile_write(struct file *filp, const char __user *ubuf, ...@@ -803,19 +803,10 @@ ftrace_profile_write(struct file *filp, const char __user *ubuf,
size_t cnt, loff_t *ppos) size_t cnt, loff_t *ppos)
{ {
unsigned long val; unsigned long val;
char buf[64]; /* big enough to hold a number */
int ret; int ret;
if (cnt >= sizeof(buf)) ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
return -EINVAL; if (ret)
if (copy_from_user(&buf, ubuf, cnt))
return -EFAULT;
buf[cnt] = 0;
ret = strict_strtoul(buf, 10, &val);
if (ret < 0)
return ret; return ret;
val = !!val; val = !!val;
......
...@@ -3980,20 +3980,11 @@ rb_simple_write(struct file *filp, const char __user *ubuf, ...@@ -3980,20 +3980,11 @@ rb_simple_write(struct file *filp, const char __user *ubuf,
size_t cnt, loff_t *ppos) size_t cnt, loff_t *ppos)
{ {
unsigned long *p = filp->private_data; unsigned long *p = filp->private_data;
char buf[64];
unsigned long val; unsigned long val;
int ret; int ret;
if (cnt >= sizeof(buf)) ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
return -EINVAL; if (ret)
if (copy_from_user(&buf, ubuf, cnt))
return -EFAULT;
buf[cnt] = 0;
ret = strict_strtoul(buf, 10, &val);
if (ret < 0)
return ret; return ret;
if (val) if (val)
......
...@@ -2706,20 +2706,11 @@ tracing_ctrl_write(struct file *filp, const char __user *ubuf, ...@@ -2706,20 +2706,11 @@ tracing_ctrl_write(struct file *filp, const char __user *ubuf,
size_t cnt, loff_t *ppos) size_t cnt, loff_t *ppos)
{ {
struct trace_array *tr = filp->private_data; struct trace_array *tr = filp->private_data;
char buf[64];
unsigned long val; unsigned long val;
int ret; int ret;
if (cnt >= sizeof(buf)) ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
return -EINVAL; if (ret)
if (copy_from_user(&buf, ubuf, cnt))
return -EFAULT;
buf[cnt] = 0;
ret = strict_strtoul(buf, 10, &val);
if (ret < 0)
return ret; return ret;
val = !!val; val = !!val;
...@@ -3006,20 +2997,11 @@ tracing_max_lat_write(struct file *filp, const char __user *ubuf, ...@@ -3006,20 +2997,11 @@ tracing_max_lat_write(struct file *filp, const char __user *ubuf,
size_t cnt, loff_t *ppos) size_t cnt, loff_t *ppos)
{ {
unsigned long *ptr = filp->private_data; unsigned long *ptr = filp->private_data;
char buf[64];
unsigned long val; unsigned long val;
int ret; int ret;
if (cnt >= sizeof(buf)) ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
return -EINVAL; if (ret)
if (copy_from_user(&buf, ubuf, cnt))
return -EFAULT;
buf[cnt] = 0;
ret = strict_strtoul(buf, 10, &val);
if (ret < 0)
return ret; return ret;
*ptr = val * 1000; *ptr = val * 1000;
...@@ -3474,19 +3456,10 @@ tracing_entries_write(struct file *filp, const char __user *ubuf, ...@@ -3474,19 +3456,10 @@ tracing_entries_write(struct file *filp, const char __user *ubuf,
size_t cnt, loff_t *ppos) size_t cnt, loff_t *ppos)
{ {
unsigned long val; unsigned long val;
char buf[64];
int ret; int ret;
if (cnt >= sizeof(buf)) ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
return -EINVAL; if (ret)
if (copy_from_user(&buf, ubuf, cnt))
return -EFAULT;
buf[cnt] = 0;
ret = strict_strtoul(buf, 10, &val);
if (ret < 0)
return ret; return ret;
/* must have at least 1 entry */ /* must have at least 1 entry */
...@@ -4139,19 +4112,10 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, ...@@ -4139,19 +4112,10 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,
{ {
struct trace_option_dentry *topt = filp->private_data; struct trace_option_dentry *topt = filp->private_data;
unsigned long val; unsigned long val;
char buf[64];
int ret; int ret;
if (cnt >= sizeof(buf)) ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
return -EINVAL; if (ret)
if (copy_from_user(&buf, ubuf, cnt))
return -EFAULT;
buf[cnt] = 0;
ret = strict_strtoul(buf, 10, &val);
if (ret < 0)
return ret; return ret;
if (val != 0 && val != 1) if (val != 0 && val != 1)
...@@ -4199,20 +4163,11 @@ trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, ...@@ -4199,20 +4163,11 @@ trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt,
loff_t *ppos) loff_t *ppos)
{ {
long index = (long)filp->private_data; long index = (long)filp->private_data;
char buf[64];
unsigned long val; unsigned long val;
int ret; int ret;
if (cnt >= sizeof(buf)) ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
return -EINVAL; if (ret)
if (copy_from_user(&buf, ubuf, cnt))
return -EFAULT;
buf[cnt] = 0;
ret = strict_strtoul(buf, 10, &val);
if (ret < 0)
return ret; return ret;
if (val != 0 && val != 1) if (val != 0 && val != 1)
......
...@@ -486,20 +486,11 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, ...@@ -486,20 +486,11 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
loff_t *ppos) loff_t *ppos)
{ {
struct ftrace_event_call *call = filp->private_data; struct ftrace_event_call *call = filp->private_data;
char buf[64];
unsigned long val; unsigned long val;
int ret; int ret;
if (cnt >= sizeof(buf)) ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
return -EINVAL; if (ret)
if (copy_from_user(&buf, ubuf, cnt))
return -EFAULT;
buf[cnt] = 0;
ret = strict_strtoul(buf, 10, &val);
if (ret < 0)
return ret; return ret;
ret = tracing_update_buffers(); ret = tracing_update_buffers();
...@@ -571,19 +562,10 @@ system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, ...@@ -571,19 +562,10 @@ system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
{ {
const char *system = filp->private_data; const char *system = filp->private_data;
unsigned long val; unsigned long val;
char buf[64];
ssize_t ret; ssize_t ret;
if (cnt >= sizeof(buf)) ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
return -EINVAL; if (ret)
if (copy_from_user(&buf, ubuf, cnt))
return -EFAULT;
buf[cnt] = 0;
ret = strict_strtoul(buf, 10, &val);
if (ret < 0)
return ret; return ret;
ret = tracing_update_buffers(); ret = tracing_update_buffers();
......
...@@ -156,20 +156,11 @@ stack_max_size_write(struct file *filp, const char __user *ubuf, ...@@ -156,20 +156,11 @@ stack_max_size_write(struct file *filp, const char __user *ubuf,
{ {
long *ptr = filp->private_data; long *ptr = filp->private_data;
unsigned long val, flags; unsigned long val, flags;
char buf[64];
int ret; int ret;
int cpu; int cpu;
if (count >= sizeof(buf)) ret = kstrtoul_from_user(ubuf, count, 10, &val);
return -EINVAL; if (ret)
if (copy_from_user(&buf, ubuf, count))
return -EFAULT;
buf[count] = 0;
ret = strict_strtoul(buf, 10, &val);
if (ret < 0)
return ret; return ret;
local_irq_save(flags); local_irq_save(flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment