]> Gentwo Git Trees - linux/.git/commit
sysctl: Create converter functions with two new macros
authorJoel Granados <joel.granados@kernel.org>
Mon, 6 Oct 2025 12:40:01 +0000 (14:40 +0200)
committerJoel Granados <joel.granados@kernel.org>
Thu, 27 Nov 2025 14:43:20 +0000 (15:43 +0100)
commit2dc164a48e6fdb03066614e2b82464b9b7c790ca
treee03d7aedc2450941d9a2754d2644e4ff9ab5cbf6
parent551bf1845027650ff6c9da598fb270ba362e9218
sysctl: Create converter functions with two new macros

Eight converter functions are created using two new macros
(SYSCTL_USER_TO_KERN_INT_CONV & SYSCTL_KERN_TO_USER_INT_CONV); they are
called from four pre-existing converter functions: do_proc_dointvec_conv
and do_proc_dointvec{,_userhz,_ms}_jiffies_conv. The function names
generated by the macros are differentiated by a string suffix passed as
the first macro argument.

The SYSCTL_USER_TO_KERN_INT_CONV macro first executes the u_ptr_op
operation, then checks for overflow, assigns sign (-, +) and finally
writes to the kernel var with WRITE_ONCE; it always returns an -EINVAL
when an overflow is detected. The SYSCTL_KERN_TO_USER_INT_CONV uses
READ_ONCE, casts to unsigned long, then executes the k_ptr_op before
assigning the value to the user space buffer.

The overflow check is always done against MAX_INT after applying
{k,u}_ptr_op. This approach avoids rounding or precision errors that
might occur when using the inverse operations.

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