]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sysctl: Allow custom converters from outside sysctl
authorJoel Granados <joel.granados@kernel.org>
Wed, 8 Oct 2025 14:12:37 +0000 (16:12 +0200)
committerJoel Granados <joel.granados@kernel.org>
Thu, 27 Nov 2025 14:45:37 +0000 (15:45 +0100)
The new non-static proc_dointvec_conv forwards a custom converter
function to do_proc_dointvec from outside the sysctl scope. Rename the
do_proc_dointvec call points so any future changes to proc_dointvec_conv
are propagated in sysctl.c This is a preparation commit that allows the
integer jiffie converter functions to move out of kernel/sysctl.c.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
include/linux/sysctl.h
kernel/sysctl.c

index 436191e569da1be6bb5a802e94a4ebde95defc54..a48273757c99f2bb183b602a72439ea35c986c40 100644 (file)
@@ -68,6 +68,10 @@ int proc_dostring(const struct ctl_table *, int, void *, size_t *, loff_t *);
 int proc_dobool(const struct ctl_table *table, int write, void *buffer,
                size_t *lenp, loff_t *ppos);
 int proc_dointvec(const struct ctl_table *, int, void *, size_t *, loff_t *);
+int proc_dointvec_conv(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));
 int proc_douintvec(const struct ctl_table *, int, void *, size_t *, loff_t *);
 int proc_dointvec_minmax(const struct ctl_table *, int, void *, size_t *, loff_t *);
 int proc_douintvec_minmax(const struct ctl_table *table, int write, void *buffer,
index 00595b84beacb61a46c4f427e48bcfa1dd986b16..833ed04f52dc47a533f58a4f460f00e9e9213815 100644 (file)
@@ -1005,6 +1005,14 @@ int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int dir,
                                         lenp, ppos, HZ, 1000l);
 }
 
+int proc_dointvec_conv(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))
+{
+       return do_proc_dointvec(table, dir, buffer, lenp, ppos, conv);
+}
+
 /**
  * proc_dointvec_jiffies - read a vector of integers as seconds
  * @table: the sysctl table
@@ -1023,15 +1031,15 @@ int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int dir,
 int proc_dointvec_jiffies(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_jiffies);
+       return proc_dointvec_conv(table, dir, buffer, lenp, ppos,
+                                 do_proc_int_conv_jiffies);
 }
 
 int proc_dointvec_ms_jiffies_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_ms_jiffies_minmax);
+       return proc_dointvec_conv(table, dir, buffer, lenp, ppos,
+                                 do_proc_int_conv_ms_jiffies_minmax);
 }
 
 /**
@@ -1054,8 +1062,8 @@ int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int dir,
 {
        if (SYSCTL_USER_TO_KERN(dir) && USER_HZ < HZ)
                return -EINVAL;
-       return do_proc_dointvec(table, dir, buffer, lenp, ppos,
-                               do_proc_int_conv_userhz_jiffies);
+       return proc_dointvec_conv(table, dir, buffer, lenp, ppos,
+                                 do_proc_int_conv_userhz_jiffies);
 }
 
 /**
@@ -1076,8 +1084,8 @@ int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int dir,
 int proc_dointvec_ms_jiffies(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_ms_jiffies);
+       return proc_dointvec_conv(table, dir, buffer, lenp, ppos,
+                                 do_proc_int_conv_ms_jiffies);
 }
 
 /**
@@ -1307,6 +1315,14 @@ int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int dir,
        return -ENOSYS;
 }
 
+int proc_dointvec_conv(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))
+{
+       return -ENOSYS;
+}
+
 int proc_do_large_bitmap(const struct ctl_table *table, int dir,
                         void *buffer, size_t *lenp, loff_t *ppos)
 {