]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Add a proc_dointvec_bool() sysctl handler for cases where the input value
authorDave Young <hidave.darkstar@gmail.com>
Wed, 3 Aug 2011 00:53:03 +0000 (10:53 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 16 Aug 2011 05:00:42 +0000 (15:00 +1000)
is limited to 0 and 1.

Signed-off-by: Dave Young <hidave.darkstar@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/sysctl.h
kernel/sysctl.c

index 11684d9e6bd2391374f2cc3fd9ff7d4f9df4e11d..991736ef96876a4227f2b7447f43c9bd174f95e0 100644 (file)
@@ -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,
index 4f057f9c0c4302d01d647f026410d9b77c781cf5..6c9414640f7cbb9cc9577d852e4704850913599f 100644 (file)
@@ -2477,6 +2477,33 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
                                do_proc_dointvec_minmax_conv, &param);
 }
 
+/**
+ * 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, &param);
+}
+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,