summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Granados <joel.granados@kernel.org>2025-10-16 10:22:16 +0200
committerJoel Granados <joel.granados@kernel.org>2025-11-27 15:43:20 +0100
commitc3102febf43ba8a9ce5512a49103f42661659a16 (patch)
treec2afa7aced9acfbd980e23f23db06b14b5e2e51d
parent0c1d2dc7cce78445f723d32b57f430c42316cab0 (diff)
sysctl: Create macro for user-to-kernel uint converter
Replace sysctl_user_to_kern_uint_conv function with SYSCTL_USER_TO_KERN_UINT_CONV macro that accepts u_ptr_op parameter for value transformation. Replacing sysctl_kern_to_user_uint_conv is not needed as it will only be used from within sysctl.c. This is a preparation commit for creating a custom converter in fs/pipe.c. No Functional changes are intended. Signed-off-by: Joel Granados <joel.granados@kernel.org>
-rw-r--r--kernel/sysctl.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 1e8d330a773d..00595b84beac 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -462,15 +462,19 @@ static SYSCTL_INT_CONV_CUSTOM(_ms_jiffies_minmax,
sysctl_user_to_kern_int_conv_ms,
sysctl_kern_to_user_int_conv_ms, true)
-static int sysctl_user_to_kern_uint_conv(const unsigned long *u_ptr,
- unsigned int *k_ptr)
-{
- if (*u_ptr > UINT_MAX)
- return -EINVAL;
- WRITE_ONCE(*k_ptr, *u_ptr);
- return 0;
+#define SYSCTL_USER_TO_KERN_UINT_CONV(name, u_ptr_op) \
+int sysctl_user_to_kern_uint_conv##name(const unsigned long *u_ptr,\
+ unsigned int *k_ptr) \
+{ \
+ unsigned long u = u_ptr_op(*u_ptr); \
+ if (u > UINT_MAX) \
+ return -EINVAL; \
+ WRITE_ONCE(*k_ptr, u); \
+ return 0; \
}
+static SYSCTL_USER_TO_KERN_UINT_CONV(, SYSCTL_CONV_IDENTITY)
+
static int sysctl_kern_to_user_uint_conv(unsigned long *u_ptr,
const unsigned int *k_ptr)
{