mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 03:36:19 +00:00
[PATCH] proc: sysctl: add _proc_do_string helper
The logic in proc_do_string is worth re-using without passing in a ctl_table structure (say, we want to calculate a pointer and pass that in instead); pass in the two fields it uses from that structure as explicit arguments. Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz> Cc: Serge E. Hallyn <serue@us.ibm.com> Cc: Kirill Korotaev <dev@openvz.org> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Herbert Poetzl <herbert@13thfloor.at> Cc: Andrey Savochkin <saw@sw.ru> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
12fd352038
commit
f5dd3d6fad
1 changed files with 51 additions and 44 deletions
|
@ -1624,6 +1624,55 @@ static ssize_t proc_writesys(struct file * file, const char __user * buf,
|
|||
return do_rw_proc(1, file, (char __user *) buf, count, ppos);
|
||||
}
|
||||
|
||||
int _proc_do_string(void* data, int maxlen, int write, struct file *filp,
|
||||
void __user *buffer, size_t *lenp, loff_t *ppos)
|
||||
{
|
||||
size_t len;
|
||||
char __user *p;
|
||||
char c;
|
||||
|
||||
if (!data || !maxlen || !*lenp ||
|
||||
(*ppos && !write)) {
|
||||
*lenp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (write) {
|
||||
len = 0;
|
||||
p = buffer;
|
||||
while (len < *lenp) {
|
||||
if (get_user(c, p++))
|
||||
return -EFAULT;
|
||||
if (c == 0 || c == '\n')
|
||||
break;
|
||||
len++;
|
||||
}
|
||||
if (len >= maxlen)
|
||||
len = maxlen-1;
|
||||
if(copy_from_user(data, buffer, len))
|
||||
return -EFAULT;
|
||||
((char *) data)[len] = 0;
|
||||
*ppos += *lenp;
|
||||
} else {
|
||||
len = strlen(data);
|
||||
if (len > maxlen)
|
||||
len = maxlen;
|
||||
if (len > *lenp)
|
||||
len = *lenp;
|
||||
if (len)
|
||||
if(copy_to_user(buffer, data, len))
|
||||
return -EFAULT;
|
||||
if (len < *lenp) {
|
||||
if(put_user('\n', ((char __user *) buffer) + len))
|
||||
return -EFAULT;
|
||||
len++;
|
||||
}
|
||||
*lenp = len;
|
||||
*ppos += len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* proc_dostring - read a string sysctl
|
||||
* @table: the sysctl table
|
||||
|
@ -1645,50 +1694,8 @@ static ssize_t proc_writesys(struct file * file, const char __user * buf,
|
|||
int proc_dostring(ctl_table *table, int write, struct file *filp,
|
||||
void __user *buffer, size_t *lenp, loff_t *ppos)
|
||||
{
|
||||
size_t len;
|
||||
char __user *p;
|
||||
char c;
|
||||
|
||||
if (!table->data || !table->maxlen || !*lenp ||
|
||||
(*ppos && !write)) {
|
||||
*lenp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (write) {
|
||||
len = 0;
|
||||
p = buffer;
|
||||
while (len < *lenp) {
|
||||
if (get_user(c, p++))
|
||||
return -EFAULT;
|
||||
if (c == 0 || c == '\n')
|
||||
break;
|
||||
len++;
|
||||
}
|
||||
if (len >= table->maxlen)
|
||||
len = table->maxlen-1;
|
||||
if(copy_from_user(table->data, buffer, len))
|
||||
return -EFAULT;
|
||||
((char *) table->data)[len] = 0;
|
||||
*ppos += *lenp;
|
||||
} else {
|
||||
len = strlen(table->data);
|
||||
if (len > table->maxlen)
|
||||
len = table->maxlen;
|
||||
if (len > *lenp)
|
||||
len = *lenp;
|
||||
if (len)
|
||||
if(copy_to_user(buffer, table->data, len))
|
||||
return -EFAULT;
|
||||
if (len < *lenp) {
|
||||
if(put_user('\n', ((char __user *) buffer) + len))
|
||||
return -EFAULT;
|
||||
len++;
|
||||
}
|
||||
*lenp = len;
|
||||
*ppos += len;
|
||||
}
|
||||
return 0;
|
||||
return _proc_do_string(table->data, table->maxlen, write, filp,
|
||||
buffer, lenp, ppos);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue