summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJoel Granados <joel.granados@kernel.org>2025-12-03 22:42:32 +0100
committerJoel Granados <joel.granados@kernel.org>2026-01-06 11:26:42 +0100
commitef153851af5b05c23b3484e7eebaadd18f2da6a9 (patch)
tree51af79667c55dbe49f0881221f7da7e78a9cba54 /include
parentb3af263b8a83f2ed033ae83fe008004b061b84f4 (diff)
sysctl: Replace unidirectional INT converter macros with functions
Replace SYSCTL_USER_TO_KERN_INT_CONV and SYSCTL_KERN_TO_USER_INT_CONV macros with function implementing the same logic.This makes debugging easier and aligns with the functions preference described in coding-style.rst. Update all jiffies converters to use explicit function implementations instead of macro-generated versions. Signed-off-by: Joel Granados <joel.granados@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/sysctl.h56
1 files changed, 7 insertions, 49 deletions
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index d712992789f0..655fb85ec292 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -74,40 +74,6 @@ extern const int sysctl_vals[];
#define SYSCTL_KERN_TO_USER(dir) (!dir)
#ifdef CONFIG_PROC_SYSCTL
-#define SYSCTL_USER_TO_KERN_INT_CONV(name, u_ptr_op) \
-int sysctl_user_to_kern_int_conv##name(const bool *negp, \
- const unsigned long *u_ptr,\
- int *k_ptr) \
-{ \
- unsigned long u = u_ptr_op(*u_ptr); \
- if (*negp) { \
- if (u > (unsigned long) INT_MAX + 1) \
- return -EINVAL; \
- WRITE_ONCE(*k_ptr, -u); \
- } else { \
- if (u > (unsigned long) INT_MAX) \
- return -EINVAL; \
- WRITE_ONCE(*k_ptr, u); \
- } \
- return 0; \
-}
-
-#define SYSCTL_KERN_TO_USER_INT_CONV(name, k_ptr_op) \
-int sysctl_kern_to_user_int_conv##name(bool *negp, \
- unsigned long *u_ptr, \
- const int *k_ptr) \
-{ \
- int val = READ_ONCE(*k_ptr); \
- if (val < 0) { \
- *negp = true; \
- *u_ptr = -k_ptr_op((unsigned long)val); \
- } else { \
- *negp = false; \
- *u_ptr = k_ptr_op((unsigned long)val); \
- } \
- return 0; \
-}
-
/**
* To range check on a converted value, use a temp k_ptr
* When checking range, value should be within (tbl->extra1, tbl->extra2)
@@ -135,22 +101,8 @@ int do_proc_int_conv##name(bool *negp, unsigned long *u_ptr, int *k_ptr,\
return user_to_kern(negp, u_ptr, k_ptr); \
return 0; \
}
-#else // CONFIG_PROC_SYSCTL
-#define SYSCTL_USER_TO_KERN_INT_CONV(name, u_ptr_op) \
-int sysctl_user_to_kern_int_conv##name(const bool *negp, \
- const unsigned long *u_ptr,\
- int *k_ptr) \
-{ \
- return -ENOSYS; \
-}
-#define SYSCTL_KERN_TO_USER_INT_CONV(name, k_ptr_op) \
-int sysctl_kern_to_user_int_conv##name(bool *negp, \
- unsigned long *u_ptr, \
- const int *k_ptr) \
-{ \
- return -ENOSYS; \
-}
+#else // CONFIG_PROC_SYSCTL
#define SYSCTL_INT_CONV_CUSTOM(name, user_to_kern, kern_to_user, \
k_ptr_range_check) \
@@ -170,6 +122,7 @@ typedef int proc_handler(const struct ctl_table *ctl, int write, void *buffer,
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_minmax(const struct ctl_table *table, int dir, void *buffer,
size_t *lenp, loff_t *ppos);
@@ -177,6 +130,11 @@ 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_int_k2u_conv_kop(ulong *u_ptr, const int *k_ptr, bool *negp,
+ ulong (*k_ptr_op)(const ulong));
+int proc_int_u2k_conv_uop(const ulong *u_ptr, int *k_ptr, const bool *negp,
+ ulong (*u_ptr_op)(const ulong));
+
int proc_douintvec(const struct ctl_table *, int, void *, size_t *, loff_t *);
int proc_douintvec_minmax(const struct ctl_table *table, int write, void *buffer,
size_t *lenp, loff_t *ppos);