From: Dave Young Date: Wed, 3 Aug 2011 00:53:03 +0000 (+1000) Subject: Add a proc_dointvec_bool() sysctl handler for cases where the input value X-Git-Tag: next-20110816~1^2~8 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=572d34074e1332459aaaabc435e5bbbdf98d6215;p=karo-tx-linux.git Add a proc_dointvec_bool() sysctl handler for cases where the input value is limited to 0 and 1. Signed-off-by: Dave Young Cc: "Eric W. Biederman" Cc: Alexey Dobriyan Signed-off-by: Andrew Morton --- diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 11684d9e6bd2..991736ef9687 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -971,6 +971,8 @@ extern int proc_dointvec(struct ctl_table *, int, void __user *, size_t *, loff_t *); extern int proc_dointvec_minmax(struct ctl_table *, int, void __user *, size_t *, loff_t *); +extern int proc_dointvec_bool(struct ctl_table *, int, + void __user *, size_t *, loff_t *); extern int proc_dointvec_jiffies(struct ctl_table *, int, void __user *, size_t *, loff_t *); extern int proc_dointvec_userhz_jiffies(struct ctl_table *, int, diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 4f057f9c0c43..6c9414640f7c 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2477,6 +2477,33 @@ int proc_dointvec_minmax(struct ctl_table *table, int write, do_proc_dointvec_minmax_conv, ¶m); } +/** + * proc_dointvec_bool - read a vector of integers with 0/1 values + * @table: the sysctl table + * @write: %TRUE if this is a write to the sysctl file + * @buffer: the user buffer + * @lenp: the size of the user buffer + * @ppos: file position + * + * Reads/writes up to table->maxlen/sizeof(unsigned int) integer + * values from/to the user buffer, treated as an ASCII string. + * + * This routine will ensure the values are either 0 or 1. + * + * Returns 0 on success. + */ +int proc_dointvec_bool(struct ctl_table *table, int write, + void __user *buffer, size_t *lenp, loff_t *ppos) +{ + struct do_proc_dointvec_minmax_conv_param param = { + .min = &zero, + .max = &one, + }; + return do_proc_dointvec(table, write, buffer, lenp, ppos, + do_proc_dointvec_minmax_conv, ¶m); +} +EXPORT_SYMBOL(proc_dointvec_bool); + static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos,