Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+11 -7
+11 -7
kernel/sysctl.c
··· 462 462 sysctl_user_to_kern_int_conv_ms, 463 463 sysctl_kern_to_user_int_conv_ms, true) 464 464 465 - static int sysctl_user_to_kern_uint_conv(const unsigned long *u_ptr, 466 - unsigned int *k_ptr) 467 - { 468 - if (*u_ptr > UINT_MAX) 469 - return -EINVAL; 470 - WRITE_ONCE(*k_ptr, *u_ptr); 471 - return 0; 465 + #define SYSCTL_USER_TO_KERN_UINT_CONV(name, u_ptr_op) \ 466 + int sysctl_user_to_kern_uint_conv##name(const unsigned long *u_ptr,\ 467 + unsigned int *k_ptr) \ 468 + { \ 469 + unsigned long u = u_ptr_op(*u_ptr); \ 470 + if (u > UINT_MAX) \ 471 + return -EINVAL; \ 472 + WRITE_ONCE(*k_ptr, u); \ 473 + return 0; \ 472 474 } 475 + 476 + static SYSCTL_USER_TO_KERN_UINT_CONV(, SYSCTL_CONV_IDENTITY) 473 477 474 478 static int sysctl_kern_to_user_uint_conv(unsigned long *u_ptr, 475 479 const unsigned int *k_ptr)