mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-09-18 23:19:34 +02:00
sysctl: Replace do_proc_do{int,ulong,uint}vec with do_proc_vec
Make do_proc_vec static and parametrize by proc_vec_type enum which
defines the type being processed and selects which converter is "live".
Signed-ness and size are calculated based on proc_vec_type and
table->data is now walked as raw bytes and advanced by the element size;
the converter still performs the actual typed load/store. Pass converter
as a union to avoid a cast from void*. The public
proc_do{int,uint,ulong}vec_conv() prototypes and all converter
signatures in kernel/, fs/ and the header are therefore unchanged.
Remove do_proc_doulongvec_minmax. proc_doulongvec_minmax_conv uses a
converter callback passed by the caller instead of conversions based on
conv{mul,div}. Create uni and bi-direction converters for milliseconds
to jiffies in proc_doulongvec_ms_jiffies_minmax; which is the only user
of proc_doulongvec_minmax_conv.
Replace do_proc_douintvec{,_w,_r} functions with a call to do_proc_vec.
Disallow vectors for uint by returning -EINVAL when more than one
element is detected.
Signed-off-by: Joel Granados <joel.granados@kernel.org>
This commit is contained in:
+10
-1
@@ -117,11 +117,20 @@ int proc_dou8vec_minmax(const struct ctl_table *table, int write, void *buffer,
|
||||
int proc_doulongvec_minmax(const struct ctl_table *, int, void *, size_t *, loff_t *);
|
||||
int proc_doulongvec_minmax_conv(const struct ctl_table *table, int dir,
|
||||
void *buffer, size_t *lenp, loff_t *ppos,
|
||||
unsigned long convmul, unsigned long convdiv);
|
||||
int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr,
|
||||
int dir, const struct ctl_table *table));
|
||||
int proc_do_large_bitmap(const struct ctl_table *, int, void *, size_t *, loff_t *);
|
||||
int proc_do_static_key(const struct ctl_table *table, int write, void *buffer,
|
||||
size_t *lenp, loff_t *ppos);
|
||||
|
||||
int proc_ulong_u2k_conv_uop(const ulong *u_ptr, ulong *k_ptr,
|
||||
ulong (*u_ptr_op)(const ulong));
|
||||
int proc_ulong_k2u_conv_kop(ulong *u_ptr, const ulong *k_ptr,
|
||||
ulong (*k_ptr_op)(const ulong));
|
||||
int proc_ulong_conv(ulong *u_ptr, ulong *k_ptr, int dir,
|
||||
const struct ctl_table *tbl, bool k_ptr_range_check,
|
||||
int (*user_to_kern)(const ulong *u_ptr, ulong *k_ptr),
|
||||
int (*kern_to_user)(ulong *u_ptr, const ulong *k_ptr));
|
||||
/*
|
||||
* Register a set of sysctl names by calling register_sysctl
|
||||
* with an initialised array of struct ctl_table's.
|
||||
|
||||
+218
-212
@@ -572,14 +572,80 @@ static int do_proc_int_conv_minmax(bool *negp, unsigned long *u_ptr, int *k_ptr,
|
||||
|
||||
static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
|
||||
|
||||
static int do_proc_dointvec(const struct ctl_table *table, int dir,
|
||||
void *buffer, size_t *lenp, loff_t *ppos,
|
||||
int (*conv)(bool *negp, unsigned long *u_ptr, int *k_ptr,
|
||||
int dir, const struct ctl_table *table))
|
||||
/*
|
||||
* Element type processed by do_proc_vec(). The tag selects the element size
|
||||
* and signedness, and it selects which member of union proc_vec_conv is live.
|
||||
*/
|
||||
enum proc_vec_type {
|
||||
PROC_VEC_INT,
|
||||
PROC_VEC_UINT,
|
||||
PROC_VEC_ULONG,
|
||||
};
|
||||
|
||||
/*
|
||||
* Converter passed to do_proc_vec(). Only the member matching the
|
||||
* enum proc_vec_type tag is ever read, so every dispatch stays fully typed and
|
||||
* no void * converter pointer is needed.
|
||||
*/
|
||||
union proc_vec_conv {
|
||||
int (*int_conv)(bool *negp, ulong *u_ptr, int *k_ptr,
|
||||
int dir, const struct ctl_table *table);
|
||||
int (*uint_conv)(bool *negp, ulong *u_ptr, uint *k_ptr,
|
||||
int dir, const struct ctl_table *table);
|
||||
int (*ulong_conv)(bool *negp, ulong *u_ptr, ulong *k_ptr,
|
||||
int dir, const struct ctl_table *table);
|
||||
};
|
||||
|
||||
/*
|
||||
* Dispatch to the converter member selected by @type. @k_ptr walks
|
||||
* table->data as raw bytes and is cast back to the element type here.
|
||||
*/
|
||||
static int proc_vec_conv(enum proc_vec_type type, union proc_vec_conv conv,
|
||||
bool *negp, ulong *u_ptr, char *k_ptr, int dir,
|
||||
const struct ctl_table *table)
|
||||
{
|
||||
int *i, vleft, first = 1, err = 0;
|
||||
size_t left;
|
||||
char *p;
|
||||
switch (type) {
|
||||
case PROC_VEC_INT:
|
||||
return conv.int_conv(negp, u_ptr, (int *)k_ptr, dir, table);
|
||||
case PROC_VEC_UINT:
|
||||
return conv.uint_conv(negp, u_ptr, (uint *)k_ptr, dir, table);
|
||||
case PROC_VEC_ULONG:
|
||||
return conv.ulong_conv(negp, u_ptr, (ulong *)k_ptr, dir, table);
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read/write a vector of @type elements. The element size and signedness are
|
||||
* derived from @type, so a single runtime function replaces the per-type
|
||||
* variants. table->data is walked as raw bytes (@i) advanced by @size; the
|
||||
* converter performs the actual typed load/store.
|
||||
*/
|
||||
static int do_proc_vec(const struct ctl_table *table, int dir,
|
||||
void *buffer, size_t *lenp, loff_t *ppos,
|
||||
enum proc_vec_type type, union proc_vec_conv conv)
|
||||
{
|
||||
int vleft, first = 1, err = 0;
|
||||
size_t left, size;
|
||||
bool is_unsigned;
|
||||
char *i, *p;
|
||||
|
||||
switch (type) {
|
||||
case PROC_VEC_INT:
|
||||
size = sizeof(int);
|
||||
is_unsigned = false;
|
||||
break;
|
||||
case PROC_VEC_UINT:
|
||||
size = sizeof(uint);
|
||||
is_unsigned = true;
|
||||
break;
|
||||
case PROC_VEC_ULONG:
|
||||
size = sizeof(ulong);
|
||||
is_unsigned = true;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!table->data || !table->maxlen || !*lenp ||
|
||||
(*ppos && SYSCTL_KERN_TO_USER(dir))) {
|
||||
@@ -587,10 +653,14 @@ static int do_proc_dointvec(const struct ctl_table *table, int dir,
|
||||
return 0;
|
||||
}
|
||||
|
||||
i = (int *) table->data;
|
||||
vleft = table->maxlen / sizeof(*i);
|
||||
i = table->data;
|
||||
vleft = table->maxlen / size;
|
||||
left = *lenp;
|
||||
|
||||
/* uint arrays are not supported, *Do not* add support for them. */
|
||||
if (type == PROC_VEC_UINT && vleft != 1)
|
||||
return -EINVAL;
|
||||
|
||||
if (SYSCTL_USER_TO_KERN(dir)) {
|
||||
if (proc_first_pos_non_zero_ignore(ppos, table))
|
||||
goto out;
|
||||
@@ -600,9 +670,9 @@ static int do_proc_dointvec(const struct ctl_table *table, int dir,
|
||||
p = buffer;
|
||||
}
|
||||
|
||||
for (; left && vleft--; i++, first=0) {
|
||||
for (; left && vleft--; i += size, first = 0) {
|
||||
unsigned long lval;
|
||||
bool neg;
|
||||
bool neg = false;
|
||||
|
||||
if (SYSCTL_USER_TO_KERN(dir)) {
|
||||
proc_skip_spaces(&p, &left);
|
||||
@@ -612,14 +682,16 @@ static int do_proc_dointvec(const struct ctl_table *table, int dir,
|
||||
err = proc_get_long(&p, &left, &lval, &neg,
|
||||
proc_wspace_sep,
|
||||
sizeof(proc_wspace_sep), NULL);
|
||||
if (!err && neg && is_unsigned)
|
||||
err = -EINVAL;
|
||||
if (err)
|
||||
break;
|
||||
if (conv(&neg, &lval, i, 1, table)) {
|
||||
if (proc_vec_conv(type, conv, &neg, &lval, i, dir, table)) {
|
||||
err = -EINVAL;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (conv(&neg, &lval, i, 0, table)) {
|
||||
if (proc_vec_conv(type, conv, &neg, &lval, i, dir, table)) {
|
||||
err = -EINVAL;
|
||||
break;
|
||||
}
|
||||
@@ -641,119 +713,6 @@ out:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int do_proc_douintvec_w(const struct ctl_table *table, void *buffer,
|
||||
size_t *lenp, loff_t *ppos,
|
||||
int (*conv)(bool *negp, unsigned long *u_ptr,
|
||||
unsigned int *k_ptr, int dir,
|
||||
const struct ctl_table *table))
|
||||
{
|
||||
unsigned long lval;
|
||||
int err = 0;
|
||||
size_t left;
|
||||
bool neg;
|
||||
char *p = buffer;
|
||||
|
||||
left = *lenp;
|
||||
|
||||
if (proc_first_pos_non_zero_ignore(ppos, table))
|
||||
goto bail_early;
|
||||
|
||||
if (left > PAGE_SIZE - 1)
|
||||
left = PAGE_SIZE - 1;
|
||||
|
||||
proc_skip_spaces(&p, &left);
|
||||
if (!left) {
|
||||
err = -EINVAL;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
err = proc_get_long(&p, &left, &lval, &neg,
|
||||
proc_wspace_sep,
|
||||
sizeof(proc_wspace_sep), NULL);
|
||||
if (err || neg) {
|
||||
err = -EINVAL;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
if (conv(&neg, &lval, (unsigned int *) table->data, 1, table)) {
|
||||
err = -EINVAL;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
if (!err && left)
|
||||
proc_skip_spaces(&p, &left);
|
||||
|
||||
out_free:
|
||||
if (err)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
|
||||
bail_early:
|
||||
*ppos += *lenp;
|
||||
return err;
|
||||
}
|
||||
|
||||
static int do_proc_douintvec_r(const struct ctl_table *table, void *buffer,
|
||||
size_t *lenp, loff_t *ppos,
|
||||
int (*conv)(bool *negp, unsigned long *u_ptr,
|
||||
unsigned int *k_ptr, int dir,
|
||||
const struct ctl_table *table))
|
||||
{
|
||||
unsigned long lval;
|
||||
int err = 0;
|
||||
size_t left;
|
||||
bool negp;
|
||||
|
||||
left = *lenp;
|
||||
|
||||
if (conv(&negp, &lval, (unsigned int *) table->data, 0, table)) {
|
||||
err = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
proc_put_long(&buffer, &left, lval, false);
|
||||
if (!left)
|
||||
goto out;
|
||||
|
||||
proc_put_char(&buffer, &left, '\n');
|
||||
|
||||
out:
|
||||
*lenp -= left;
|
||||
*ppos += *lenp;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int do_proc_douintvec(const struct ctl_table *table, int dir,
|
||||
void *buffer, size_t *lenp, loff_t *ppos,
|
||||
int (*conv)(bool *negp, ulong *u_ptr, uint *k_ptr,
|
||||
int dir, const struct ctl_table *table))
|
||||
{
|
||||
unsigned int vleft;
|
||||
|
||||
if (!table->data || !table->maxlen || !*lenp ||
|
||||
(*ppos && SYSCTL_KERN_TO_USER(dir))) {
|
||||
*lenp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
vleft = table->maxlen / sizeof(unsigned int);
|
||||
|
||||
/*
|
||||
* Arrays are not supported, keep this simple. *Do not* add
|
||||
* support for them.
|
||||
*/
|
||||
if (vleft != 1) {
|
||||
*lenp = 0;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (SYSCTL_USER_TO_KERN(dir))
|
||||
return do_proc_douintvec_w(table, buffer, lenp, ppos, conv);
|
||||
return do_proc_douintvec_r(table, buffer, lenp, ppos, conv);
|
||||
}
|
||||
|
||||
/**
|
||||
* proc_douintvec_conv - read a vector of unsigned ints with a custom converter
|
||||
*
|
||||
@@ -779,7 +738,8 @@ int proc_douintvec_conv(const struct ctl_table *table, int dir, void *buffer,
|
||||
if (!conv)
|
||||
conv = do_proc_uint_conv;
|
||||
|
||||
return do_proc_douintvec(table, dir, buffer, lenp, ppos, conv);
|
||||
return do_proc_vec(table, dir, buffer, lenp, ppos, PROC_VEC_UINT,
|
||||
(union proc_vec_conv){ .uint_conv = conv });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -838,7 +798,8 @@ int proc_dobool(const struct ctl_table *table, int dir, void *buffer,
|
||||
int proc_dointvec(const struct ctl_table *table, int dir, void *buffer,
|
||||
size_t *lenp, loff_t *ppos)
|
||||
{
|
||||
return do_proc_dointvec(table, dir, buffer, lenp, ppos, do_proc_int_conv);
|
||||
return do_proc_vec(table, dir, buffer, lenp, ppos, PROC_VEC_INT,
|
||||
(union proc_vec_conv){ .int_conv = do_proc_int_conv });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -857,8 +818,8 @@ int proc_dointvec(const struct ctl_table *table, int dir, void *buffer,
|
||||
int proc_douintvec(const struct ctl_table *table, int dir, void *buffer,
|
||||
size_t *lenp, loff_t *ppos)
|
||||
{
|
||||
return do_proc_douintvec(table, dir, buffer, lenp, ppos,
|
||||
do_proc_uint_conv);
|
||||
return do_proc_vec(table, dir, buffer, lenp, ppos, PROC_VEC_UINT,
|
||||
(union proc_vec_conv){ .uint_conv = do_proc_uint_conv });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -881,8 +842,8 @@ int proc_douintvec(const struct ctl_table *table, int dir, void *buffer,
|
||||
int proc_dointvec_minmax(const struct ctl_table *table, int dir,
|
||||
void *buffer, size_t *lenp, loff_t *ppos)
|
||||
{
|
||||
return do_proc_dointvec(table, dir, buffer, lenp, ppos,
|
||||
do_proc_int_conv_minmax);
|
||||
return do_proc_vec(table, dir, buffer, lenp, ppos, PROC_VEC_INT,
|
||||
(union proc_vec_conv){ .int_conv = do_proc_int_conv_minmax });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -908,8 +869,8 @@ int proc_dointvec_minmax(const struct ctl_table *table, int dir,
|
||||
int proc_douintvec_minmax(const struct ctl_table *table, int dir,
|
||||
void *buffer, size_t *lenp, loff_t *ppos)
|
||||
{
|
||||
return do_proc_douintvec(table, dir, buffer, lenp, ppos,
|
||||
do_proc_uint_conv_minmax);
|
||||
return do_proc_vec(table, dir, buffer, lenp, ppos, PROC_VEC_UINT,
|
||||
(union proc_vec_conv){ .uint_conv = do_proc_uint_conv_minmax });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -952,8 +913,8 @@ int proc_dou8vec_minmax(const struct ctl_table *table, int dir,
|
||||
tmp.extra2 = (unsigned int *) &max;
|
||||
|
||||
val = READ_ONCE(*data);
|
||||
res = do_proc_douintvec(&tmp, dir, buffer, lenp, ppos,
|
||||
do_proc_uint_conv_minmax);
|
||||
res = do_proc_vec(&tmp, dir, buffer, lenp, ppos, PROC_VEC_UINT,
|
||||
(union proc_vec_conv){ .uint_conv = do_proc_uint_conv_minmax });
|
||||
if (res)
|
||||
return res;
|
||||
if (SYSCTL_USER_TO_KERN(dir))
|
||||
@@ -962,87 +923,129 @@ int proc_dou8vec_minmax(const struct ctl_table *table, int dir,
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
|
||||
|
||||
static int do_proc_doulongvec_minmax(const struct ctl_table *table, int dir,
|
||||
void *buffer, size_t *lenp, loff_t *ppos,
|
||||
unsigned long convmul,
|
||||
unsigned long convdiv)
|
||||
/**
|
||||
* proc_ulong_conv - Change user or kernel pointer based on direction
|
||||
*
|
||||
* @u_ptr: pointer to user variable
|
||||
* @k_ptr: pointer to kernel variable
|
||||
* @dir: %TRUE if this is a write to the sysctl file
|
||||
* @tbl: the sysctl table
|
||||
* @k_ptr_range_check: Check range for k_ptr when %TRUE
|
||||
* @user_to_kern: Callback used to assign value from user to kernel var
|
||||
* @kern_to_user: Callback used to assign value from kernel to user var
|
||||
*
|
||||
* When direction is kernel to user, then the u_ptr is modified.
|
||||
* When direction is user to kernel, then the k_ptr is modified.
|
||||
*
|
||||
* Returns: 0 on success
|
||||
*/
|
||||
int proc_ulong_conv(ulong *u_ptr, ulong *k_ptr, int dir,
|
||||
const struct ctl_table *tbl, bool k_ptr_range_check,
|
||||
int (*user_to_kern)(const ulong *u_ptr, ulong *k_ptr),
|
||||
int (*kern_to_user)(ulong *u_ptr, const ulong *k_ptr))
|
||||
{
|
||||
unsigned long *i, *min, *max;
|
||||
int vleft, first = 1, err = 0;
|
||||
size_t left;
|
||||
char *p;
|
||||
if (SYSCTL_KERN_TO_USER(dir))
|
||||
return kern_to_user(u_ptr, k_ptr);
|
||||
|
||||
if (!table->data || !table->maxlen || !*lenp ||
|
||||
(*ppos && SYSCTL_KERN_TO_USER(dir))) {
|
||||
*lenp = 0;
|
||||
if (k_ptr_range_check) {
|
||||
ulong tmp_k;
|
||||
int ret;
|
||||
|
||||
if (!tbl)
|
||||
return -EINVAL;
|
||||
ret = user_to_kern(u_ptr, &tmp_k);
|
||||
if (ret)
|
||||
return ret;
|
||||
if ((tbl->extra1 && *(ulong *)tbl->extra1 > tmp_k) ||
|
||||
(tbl->extra2 && *(ulong *)tbl->extra2 < tmp_k))
|
||||
return -ERANGE;
|
||||
WRITE_ONCE(*k_ptr, tmp_k);
|
||||
} else
|
||||
return user_to_kern(u_ptr, k_ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
i = table->data;
|
||||
min = table->extra1;
|
||||
max = table->extra2;
|
||||
vleft = table->maxlen / sizeof(unsigned long);
|
||||
left = *lenp;
|
||||
|
||||
if (SYSCTL_USER_TO_KERN(dir)) {
|
||||
if (proc_first_pos_non_zero_ignore(ppos, table))
|
||||
goto out;
|
||||
|
||||
if (left > PAGE_SIZE - 1)
|
||||
left = PAGE_SIZE - 1;
|
||||
p = buffer;
|
||||
}
|
||||
|
||||
for (; left && vleft--; i++, first = 0) {
|
||||
unsigned long val;
|
||||
|
||||
if (SYSCTL_USER_TO_KERN(dir)) {
|
||||
bool neg;
|
||||
|
||||
proc_skip_spaces(&p, &left);
|
||||
if (!left)
|
||||
break;
|
||||
|
||||
err = proc_get_long(&p, &left, &val, &neg,
|
||||
proc_wspace_sep,
|
||||
sizeof(proc_wspace_sep), NULL);
|
||||
if (err || neg) {
|
||||
err = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
val = convmul * val / convdiv;
|
||||
if ((min && val < *min) || (max && val > *max)) {
|
||||
err = -EINVAL;
|
||||
break;
|
||||
}
|
||||
WRITE_ONCE(*i, val);
|
||||
} else {
|
||||
val = convdiv * READ_ONCE(*i) / convmul;
|
||||
if (!first)
|
||||
proc_put_char(&buffer, &left, '\t');
|
||||
proc_put_long(&buffer, &left, val, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (SYSCTL_KERN_TO_USER(dir) && !first && left && !err)
|
||||
proc_put_char(&buffer, &left, '\n');
|
||||
if (SYSCTL_USER_TO_KERN(dir) && !err)
|
||||
proc_skip_spaces(&p, &left);
|
||||
if (SYSCTL_USER_TO_KERN(dir) && first)
|
||||
return err ? : -EINVAL;
|
||||
*lenp -= left;
|
||||
out:
|
||||
*ppos += *lenp;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* proc_ulong_u2k_conv_uop - Assign user value to a kernel pointer
|
||||
*
|
||||
* @u_ptr: pointer to user space variable
|
||||
* @k_ptr: pointer to kernel variable
|
||||
* @u_ptr_op: execute this function before assigning to k_ptr
|
||||
*
|
||||
* Uses WRITE_ONCE to assign value to k_ptr. Executes u_ptr_op if
|
||||
* not NULL.
|
||||
*
|
||||
* returns: 0 on success.
|
||||
*/
|
||||
int proc_ulong_u2k_conv_uop(const ulong *u_ptr, ulong *k_ptr,
|
||||
ulong (*u_ptr_op)(const ulong))
|
||||
{
|
||||
ulong u = u_ptr_op ? u_ptr_op(*u_ptr) : *u_ptr;
|
||||
|
||||
WRITE_ONCE(*k_ptr, u);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int proc_ulong_u2k_conv(const ulong *u_ptr, ulong *k_ptr)
|
||||
{
|
||||
return proc_ulong_u2k_conv_uop(u_ptr, k_ptr, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* proc_ulong_k2u_conv_kop - Assign kernel value to a user space pointer
|
||||
*
|
||||
* @u_ptr: pointer to user space variable
|
||||
* @k_ptr: pointer to kernel variable
|
||||
* @k_ptr_op: Operation applied to k_ptr before assignment
|
||||
*
|
||||
* Uses READ_ONCE to assign value to u_ptr. Executes k_ptr_op if
|
||||
* not NULL.
|
||||
*
|
||||
* returns: 0 on success.
|
||||
*/
|
||||
int proc_ulong_k2u_conv_kop(ulong *u_ptr, const ulong *k_ptr,
|
||||
ulong (*k_ptr_op)(const ulong))
|
||||
{
|
||||
ulong val = k_ptr_op ? k_ptr_op(READ_ONCE(*k_ptr)) : READ_ONCE(*k_ptr);
|
||||
*u_ptr = (ulong)val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int proc_ulong_k2u_conv(ulong *u_ptr, const ulong *k_ptr)
|
||||
{
|
||||
return proc_ulong_k2u_conv_kop(u_ptr, k_ptr, NULL);
|
||||
}
|
||||
|
||||
static int do_proc_ulong_conv(bool *negp, ulong *u_ptr, ulong *k_ptr, int dir,
|
||||
const struct ctl_table *tbl)
|
||||
{
|
||||
return proc_ulong_conv(u_ptr, k_ptr, dir, tbl, true,
|
||||
proc_ulong_u2k_conv, proc_ulong_k2u_conv);
|
||||
}
|
||||
|
||||
/**
|
||||
* proc_doulongvec_minmax_conv - read a vector of unsigned longs with a custom converter
|
||||
*
|
||||
* @table: the sysctl table
|
||||
* @dir: %TRUE if this is a write to the sysctl file
|
||||
* @buffer: the user buffer
|
||||
* @lenp: the size of the user buffer
|
||||
* @ppos: file position
|
||||
* @conv: Custom converter call back
|
||||
*
|
||||
* Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
|
||||
* values from/to the user buffer, treated as an ASCII string. Negative
|
||||
* strings are not allowed.
|
||||
*
|
||||
* Returns: 0 on success
|
||||
*/
|
||||
int proc_doulongvec_minmax_conv(const struct ctl_table *table, int dir,
|
||||
void *buffer, size_t *lenp, loff_t *ppos,
|
||||
unsigned long convmul, unsigned long convdiv)
|
||||
int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr,
|
||||
int dir, const struct ctl_table *table))
|
||||
{
|
||||
return do_proc_doulongvec_minmax(table, dir, buffer, lenp, ppos,
|
||||
convmul, convdiv);
|
||||
return do_proc_vec(table, dir, buffer, lenp, ppos, PROC_VEC_ULONG,
|
||||
(union proc_vec_conv){ .ulong_conv = conv });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1064,7 +1067,8 @@ int proc_doulongvec_minmax_conv(const struct ctl_table *table, int dir,
|
||||
int proc_doulongvec_minmax(const struct ctl_table *table, int dir,
|
||||
void *buffer, size_t *lenp, loff_t *ppos)
|
||||
{
|
||||
return proc_doulongvec_minmax_conv(table, dir, buffer, lenp, ppos, 1l, 1l);
|
||||
return do_proc_vec(table, dir, buffer, lenp, ppos, PROC_VEC_ULONG,
|
||||
(union proc_vec_conv){ .ulong_conv = do_proc_ulong_conv });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1090,7 +1094,8 @@ int proc_dointvec_conv(const struct ctl_table *table, int dir, void *buffer,
|
||||
{
|
||||
if (!conv)
|
||||
conv = do_proc_int_conv;
|
||||
return do_proc_dointvec(table, dir, buffer, lenp, ppos, conv);
|
||||
return do_proc_vec(table, dir, buffer, lenp, ppos, PROC_VEC_INT,
|
||||
(union proc_vec_conv){ .int_conv = conv });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1319,7 +1324,8 @@ int proc_doulongvec_minmax(const struct ctl_table *table, int dir,
|
||||
|
||||
int proc_doulongvec_minmax_conv(const struct ctl_table *table, int dir,
|
||||
void *buffer, size_t *lenp, loff_t *ppos,
|
||||
unsigned long convmul, unsigned long convdiv)
|
||||
int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr,
|
||||
int dir, const struct ctl_table *table))
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
+25
-1
@@ -185,6 +185,24 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr,
|
||||
sysctl_u2k_int_conv_ms, sysctl_k2u_int_conv_ms);
|
||||
}
|
||||
|
||||
static int sysctl_u2k_ulong_conv_ms(const ulong *u_ptr, ulong *k_ptr)
|
||||
{
|
||||
return proc_ulong_u2k_conv_uop(u_ptr, k_ptr, sysctl_msecs_to_jiffies);
|
||||
}
|
||||
|
||||
static int sysctl_k2u_ulong_conv_ms(ulong *u_ptr, const ulong *k_ptr)
|
||||
{
|
||||
return proc_ulong_k2u_conv_kop(u_ptr, k_ptr, sysctl_jiffies_to_msecs);
|
||||
}
|
||||
|
||||
static int do_proc_ulong_conv_ms_jiffies(bool *negp, ulong *u_ptr, ulong *k_ptr,
|
||||
int dir, const struct ctl_table *tbl)
|
||||
{
|
||||
return proc_ulong_conv(u_ptr, k_ptr, dir, tbl, false,
|
||||
sysctl_u2k_ulong_conv_ms, sysctl_k2u_ulong_conv_ms);
|
||||
}
|
||||
|
||||
|
||||
#else // CONFIG_PROC_SYSCTL
|
||||
static int do_proc_int_conv_jiffies(bool *negp, ulong *u_ptr, int *k_ptr,
|
||||
int dir, const struct ctl_table *tbl)
|
||||
@@ -211,6 +229,12 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr,
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
static int do_proc_ulong_conv_ms_jiffies(bool *negp, ulong *u_ptr, ulong *k_ptr,
|
||||
int dir, const struct ctl_table *tbl)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -310,7 +334,7 @@ int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int dir,
|
||||
void *buffer, size_t *lenp, loff_t *ppos)
|
||||
{
|
||||
return proc_doulongvec_minmax_conv(table, dir, buffer, lenp, ppos,
|
||||
HZ, 1000l);
|
||||
do_proc_ulong_conv_ms_jiffies);
|
||||
}
|
||||
EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user