]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sysctl: Replace void pointer with const pointer to ctl_table
authorJoel Granados <joel.granados@kernel.org>
Wed, 1 Oct 2025 13:46:36 +0000 (15:46 +0200)
committerJoel Granados <joel.granados@kernel.org>
Thu, 27 Nov 2025 14:43:20 +0000 (15:43 +0100)
* Replace void* data in the converter functions with a const struct
  ctl_table* table as it was only getting forwarding values from
  ctl_table->extra{1,2}.
* Remove the void* data in the do_proc_* functions as they already had a
  pointer to the ctl_table.
* Remove min/max structures do_proc_do{uint,int}vec_minmax_conv_param;
  the min/max values get passed directly in ctl_table.
* Keep min/max initialization in extra{1,2} in proc_dou8vec_minmax.
* The do_proc_douintvec was adjusted outside sysctl.c as it is exported
  to fs/pipe.c.

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

index 42fead1efe520491e5be8e1e4cf848cea4828fbb..9411d4fc2f4399eb30f1e8bf814a115b6d853721 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1482,8 +1482,8 @@ static struct file_system_type pipe_fs_type = {
 
 #ifdef CONFIG_SYSCTL
 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
-                                       unsigned int *valp,
-                                       int write, void *data)
+                                       unsigned int *valp, int write,
+                                       const struct ctl_table *table)
 {
        if (write) {
                unsigned int val;
@@ -1505,7 +1505,7 @@ static int proc_dopipe_max_size(const struct ctl_table *table, int write,
                                void *buffer, size_t *lenp, loff_t *ppos)
 {
        return do_proc_douintvec(table, write, buffer, lenp, ppos,
-                                do_proc_dopipe_max_size_conv, NULL);
+                                do_proc_dopipe_max_size_conv);
 }
 
 static const struct ctl_table fs_pipe_sysctls[] = {
index 28c4a997fd2175f23c304402faf8813b7a03d2b8..436191e569da1be6bb5a802e94a4ebde95defc54 100644 (file)
@@ -235,9 +235,8 @@ bool sysctl_is_alias(char *param);
 int do_proc_douintvec(const struct ctl_table *table, int write,
                      void *buffer, size_t *lenp, loff_t *ppos,
                      int (*conv)(unsigned long *lvalp,
-                                 unsigned int *valp,
-                                 int write, void *data),
-                     void *data);
+                                 unsigned int *valp, int write,
+                                 const struct ctl_table *table));
 
 extern int unaligned_enabled;
 extern int no_unaligned_warning;
index cb6196e3fa993daa21704d190baf366084e014f7..f0a691ffb29067a019a857a62fa56185aab06c61 100644 (file)
@@ -355,8 +355,8 @@ static void proc_put_char(void **buf, size_t *size, char c)
 }
 
 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
-                                int *valp,
-                                int write, void *data)
+                                int *valp, int write,
+                                const struct ctl_table *table)
 {
        if (write) {
                if (*negp) {
@@ -382,8 +382,8 @@ static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
 }
 
 static int do_proc_douintvec_conv(unsigned long *lvalp,
-                                 unsigned int *valp,
-                                 int write, void *data)
+                                 unsigned int *valp, int write,
+                                 const struct ctl_table *table)
 {
        if (write) {
                if (*lvalp > UINT_MAX)
@@ -402,8 +402,7 @@ static int __do_proc_dointvec(void *tbl_data, const struct ctl_table *table,
                  int write, void *buffer,
                  size_t *lenp, loff_t *ppos,
                  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
-                             int write, void *data),
-                 void *data)
+                             int write, const struct ctl_table *table))
 {
        int *i, vleft, first = 1, err = 0;
        size_t left;
@@ -444,12 +443,12 @@ static int __do_proc_dointvec(void *tbl_data, const struct ctl_table *table,
                                             sizeof(proc_wspace_sep), NULL);
                        if (err)
                                break;
-                       if (conv(&neg, &lval, i, 1, data)) {
+                       if (conv(&neg, &lval, i, 1, table)) {
                                err = -EINVAL;
                                break;
                        }
                } else {
-                       if (conv(&neg, &lval, i, 0, data)) {
+                       if (conv(&neg, &lval, i, 0, table)) {
                                err = -EINVAL;
                                break;
                        }
@@ -474,11 +473,10 @@ out:
 static int do_proc_dointvec(const struct ctl_table *table, int write,
                  void *buffer, size_t *lenp, loff_t *ppos,
                  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
-                             int write, void *data),
-                 void *data)
+                             int write, const struct ctl_table *table))
 {
        return __do_proc_dointvec(table->data, table, write,
-                       buffer, lenp, ppos, conv, data);
+                       buffer, lenp, ppos, conv);
 }
 
 static int do_proc_douintvec_w(unsigned int *tbl_data,
@@ -486,9 +484,8 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
                               void *buffer,
                               size_t *lenp, loff_t *ppos,
                               int (*conv)(unsigned long *lvalp,
-                                          unsigned int *valp,
-                                          int write, void *data),
-                              void *data)
+                                          unsigned int *valp, int write,
+                                          const struct ctl_table *table))
 {
        unsigned long lval;
        int err = 0;
@@ -518,7 +515,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
                goto out_free;
        }
 
-       if (conv(&lval, tbl_data, 1, data)) {
+       if (conv(&lval, tbl_data, 1, table)) {
                err = -EINVAL;
                goto out_free;
        }
@@ -538,12 +535,12 @@ bail_early:
        return err;
 }
 
-static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
+static int do_proc_douintvec_r(unsigned int *tbl_data,
+                              const struct ctl_table *table, void *buffer,
                               size_t *lenp, loff_t *ppos,
                               int (*conv)(unsigned long *lvalp,
-                                          unsigned int *valp,
-                                          int write, void *data),
-                              void *data)
+                                          unsigned int *valp, int write,
+                                          const struct ctl_table *table))
 {
        unsigned long lval;
        int err = 0;
@@ -551,7 +548,7 @@ static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
 
        left = *lenp;
 
-       if (conv(&lval, tbl_data, 0, data)) {
+       if (conv(&lval, tbl_data, 0, table)) {
                err = -EINVAL;
                goto out;
        }
@@ -573,9 +570,8 @@ static int __do_proc_douintvec(void *tbl_data, const struct ctl_table *table,
                               int write, void *buffer,
                               size_t *lenp, loff_t *ppos,
                               int (*conv)(unsigned long *lvalp,
-                                          unsigned int *valp,
-                                          int write, void *data),
-                              void *data)
+                                          unsigned int *valp, int write,
+                                          const struct ctl_table *table))
 {
        unsigned int *i, vleft;
 
@@ -601,19 +597,18 @@ static int __do_proc_douintvec(void *tbl_data, const struct ctl_table *table,
 
        if (write)
                return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
-                                          conv, data);
-       return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
+                                          conv);
+       return do_proc_douintvec_r(i, table, buffer, lenp, ppos, conv);
 }
 
 int do_proc_douintvec(const struct ctl_table *table, int write,
                      void *buffer, size_t *lenp, loff_t *ppos,
                      int (*conv)(unsigned long *lvalp,
-                                 unsigned int *valp,
-                                 int write, void *data),
-                     void *data)
+                                 unsigned int *valp, int write,
+                                 const struct ctl_table *table))
 {
-       return __do_proc_douintvec(table->data, table, write,
-                                  buffer, lenp, ppos, conv, data);
+       return __do_proc_douintvec(table->data, table, write, buffer, lenp,
+                                  ppos, conv);
 }
 
 /**
@@ -672,7 +667,7 @@ int proc_dobool(const struct ctl_table *table, int write, void *buffer,
 int proc_dointvec(const struct ctl_table *table, int write, void *buffer,
                  size_t *lenp, loff_t *ppos)
 {
-       return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
+       return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL);
 }
 
 /**
@@ -692,42 +687,28 @@ int proc_douintvec(const struct ctl_table *table, int write, void *buffer,
                size_t *lenp, loff_t *ppos)
 {
        return do_proc_douintvec(table, write, buffer, lenp, ppos,
-                                do_proc_douintvec_conv, NULL);
+                                do_proc_douintvec_conv);
 }
 
-/**
- * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
- * @min: pointer to minimum allowable value
- * @max: pointer to maximum allowable value
- *
- * The do_proc_dointvec_minmax_conv_param structure provides the
- * minimum and maximum values for doing range checking for those sysctl
- * parameters that use the proc_dointvec_minmax() handler.
- */
-struct do_proc_dointvec_minmax_conv_param {
-       int *min;
-       int *max;
-};
-
 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
-                                       int *valp,
-                                       int write, void *data)
+                                       int *valp, int write,
+                                       const struct ctl_table *table)
 {
-       int tmp, ret;
-       struct do_proc_dointvec_minmax_conv_param *param = data;
+       int tmp, ret, *min, *max;
        /*
         * If writing, first do so via a temporary local int so we can
         * bounds-check it before touching *valp.
         */
        int *ip = write ? &tmp : valp;
 
-       ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
+       ret = do_proc_dointvec_conv(negp, lvalp, ip, write, table);
        if (ret)
                return ret;
 
        if (write) {
-               if ((param->min && *param->min > tmp) ||
-                   (param->max && *param->max < tmp))
+               min = (int *) table->extra1;
+               max = (int *) table->extra2;
+               if ((min && *min > tmp) || (max && *max < tmp))
                        return -EINVAL;
                WRITE_ONCE(*valp, tmp);
        }
@@ -754,45 +735,27 @@ static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
 int proc_dointvec_minmax(const struct ctl_table *table, int write,
                  void *buffer, size_t *lenp, loff_t *ppos)
 {
-       struct do_proc_dointvec_minmax_conv_param param = {
-               .min = (int *) table->extra1,
-               .max = (int *) table->extra2,
-       };
        return do_proc_dointvec(table, write, buffer, lenp, ppos,
-                               do_proc_dointvec_minmax_conv, &param);
+                               do_proc_dointvec_minmax_conv);
 }
 
-/**
- * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
- * @min: pointer to minimum allowable value
- * @max: pointer to maximum allowable value
- *
- * The do_proc_douintvec_minmax_conv_param structure provides the
- * minimum and maximum values for doing range checking for those sysctl
- * parameters that use the proc_douintvec_minmax() handler.
- */
-struct do_proc_douintvec_minmax_conv_param {
-       unsigned int *min;
-       unsigned int *max;
-};
-
 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
-                                        unsigned int *valp,
-                                        int write, void *data)
+                                        unsigned int *valp, int write,
+                                        const struct ctl_table *table)
 {
        int ret;
-       unsigned int tmp;
-       struct do_proc_douintvec_minmax_conv_param *param = data;
+       unsigned int tmp, *min, *max;
        /* write via temporary local uint for bounds-checking */
        unsigned int *up = write ? &tmp : valp;
 
-       ret = do_proc_douintvec_conv(lvalp, up, write, data);
+       ret = do_proc_douintvec_conv(lvalp, up, write, table);
        if (ret)
                return ret;
 
        if (write) {
-               if ((param->min && *param->min > tmp) ||
-                   (param->max && *param->max < tmp))
+               min = (unsigned int *) table->extra1;
+               max = (unsigned int *) table->extra2;
+               if ((min && *min > tmp) || (max && *max < tmp))
                        return -ERANGE;
 
                WRITE_ONCE(*valp, tmp);
@@ -823,12 +786,8 @@ static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
 int proc_douintvec_minmax(const struct ctl_table *table, int write,
                          void *buffer, size_t *lenp, loff_t *ppos)
 {
-       struct do_proc_douintvec_minmax_conv_param param = {
-               .min = (unsigned int *) table->extra1,
-               .max = (unsigned int *) table->extra2,
-       };
        return do_proc_douintvec(table, write, buffer, lenp, ppos,
-                                do_proc_douintvec_minmax_conv, &param);
+                                do_proc_douintvec_minmax_conv);
 }
 
 /**
@@ -854,28 +813,24 @@ int proc_dou8vec_minmax(const struct ctl_table *table, int write,
        struct ctl_table tmp;
        unsigned int min = 0, max = 255U, val;
        u8 *data = table->data;
-       struct do_proc_douintvec_minmax_conv_param param = {
-               .min = &min,
-               .max = &max,
-       };
        int res;
 
        /* Do not support arrays yet. */
        if (table->maxlen != sizeof(u8))
                return -EINVAL;
 
-       if (table->extra1)
-               min = *(unsigned int *) table->extra1;
-       if (table->extra2)
-               max = *(unsigned int *) table->extra2;
-
        tmp = *table;
 
        tmp.maxlen = sizeof(val);
        tmp.data = &val;
+       if (!tmp.extra1)
+               tmp.extra1 = (unsigned int *) &min;
+       if (!tmp.extra2)
+               tmp.extra2 = (unsigned int *) &max;
+
        val = READ_ONCE(*data);
        res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
-                               do_proc_douintvec_minmax_conv, &param);
+                               do_proc_douintvec_minmax_conv);
        if (res)
                return res;
        if (write)
@@ -1014,8 +969,8 @@ int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int write,
 
 
 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
-                                        int *valp,
-                                        int write, void *data)
+                                        int *valp, int write,
+                                        const struct ctl_table *table)
 {
        if (write) {
                if (*lvalp > INT_MAX / HZ)
@@ -1040,8 +995,8 @@ static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
 }
 
 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
-                                               int *valp,
-                                               int write, void *data)
+                                               int *valp, int write,
+                                               const struct ctl_table *table)
 {
        if (write) {
                if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
@@ -1063,8 +1018,8 @@ static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp
 }
 
 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
-                                           int *valp,
-                                           int write, void *data)
+                                           int *valp, int write,
+                                           const struct ctl_table *table)
 {
        if (write) {
                unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
@@ -1088,23 +1043,24 @@ static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
 }
 
 static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *lvalp,
-                                               int *valp, int write, void *data)
+                                               int *valp, int write,
+                                               const struct ctl_table *table)
 {
-       int tmp, ret;
-       struct do_proc_dointvec_minmax_conv_param *param = data;
+       int tmp, ret, *min, *max;
        /*
         * If writing, first do so via a temporary local int so we can
         * bounds-check it before touching *valp.
         */
        int *ip = write ? &tmp : valp;
 
-       ret = do_proc_dointvec_ms_jiffies_conv(negp, lvalp, ip, write, data);
+       ret = do_proc_dointvec_ms_jiffies_conv(negp, lvalp, ip, write, table);
        if (ret)
                return ret;
 
        if (write) {
-               if ((param->min && *param->min > tmp) ||
-                               (param->max && *param->max < tmp))
+               min = (int *) table->extra1;
+               max = (int *) table->extra2;
+               if ((min && *min > tmp) || (max && *max < tmp))
                        return -EINVAL;
                *valp = tmp;
        }
@@ -1130,18 +1086,14 @@ int proc_dointvec_jiffies(const struct ctl_table *table, int write,
                          void *buffer, size_t *lenp, loff_t *ppos)
 {
     return do_proc_dointvec(table,write,buffer,lenp,ppos,
-                           do_proc_dointvec_jiffies_conv,NULL);
+                           do_proc_dointvec_jiffies_conv);
 }
 
 int proc_dointvec_ms_jiffies_minmax(const struct ctl_table *table, int write,
                          void *buffer, size_t *lenp, loff_t *ppos)
 {
-       struct do_proc_dointvec_minmax_conv_param param = {
-               .min = (int *) table->extra1,
-               .max = (int *) table->extra2,
-       };
        return do_proc_dointvec(table, write, buffer, lenp, ppos,
-                       do_proc_dointvec_ms_jiffies_minmax_conv, &param);
+                       do_proc_dointvec_ms_jiffies_minmax_conv);
 }
 
 /**
@@ -1163,7 +1115,7 @@ int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int write,
                                 void *buffer, size_t *lenp, loff_t *ppos)
 {
        return do_proc_dointvec(table, write, buffer, lenp, ppos,
-                               do_proc_dointvec_userhz_jiffies_conv, NULL);
+                               do_proc_dointvec_userhz_jiffies_conv);
 }
 
 /**
@@ -1185,7 +1137,7 @@ int proc_dointvec_ms_jiffies(const struct ctl_table *table, int write, void *buf
                size_t *lenp, loff_t *ppos)
 {
        return do_proc_dointvec(table, write, buffer, lenp, ppos,
-                               do_proc_dointvec_ms_jiffies_conv, NULL);
+                               do_proc_dointvec_ms_jiffies_conv);
 }
 
 /**