Skip to contentSkip to conversation

sysctl: add proc_dointvec_unsigned handler

PATCH In review Dave Young 1 participant 1 message Mar 3, 2011 Proc sysctl

lore
Share & tools
lore

Dave Young

author
#0 lore raw

PATCH 4/5 sysctl: add proc_dointvec_unsigned handler

Add proc_dointvec_unsigned sysctl handler for positive value cases

---
 include/linux/sysctl.h |    2 ++
 kernel/sysctl.c        |   26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
kernel/sysctl.c +26 -0
@@ -2459,6 +2459,32 @@ int proc_dointvec_bool(struct ctl_table 
 }
 EXPORT_SYMBOL(proc_dointvec_bool);
 
+/**
+ * proc_dointvec_unsigned - read a vector of integers with positive 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 positive.
+ *
+ * Returns 0 on success.
+ */
+int proc_dointvec_unsigned(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,
+	};
+	return do_proc_dointvec(table, write, buffer, lenp, ppos,
+				do_proc_dointvec_minmax_conv, &param);
+}
+EXPORT_SYMBOL(proc_dointvec_unsigned);
+
 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
 				     void __user *buffer,
 				     size_t *lenp, loff_t *ppos,
include/linux/sysctl.h +2 -0
@@ -972,6 +972,8 @@ extern int proc_dointvec_minmax(struct c
 				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_unsigned(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,