From: Joel Granados <joel.granados@kernel.org>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Kees Cook <kees@kernel.org>,
Joel Granados <joel.granados@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 11/11] sysctl: Create macro for user-to-kernel uint converter
Date: Thu, 16 Oct 2025 14:57:57 +0200 [thread overview]
Message-ID: <20251016-jag-sysctl_conv-v2-11-a2f16529acc4@kernel.org> (raw)
In-Reply-To: <20251016-jag-sysctl_conv-v2-0-a2f16529acc4@kernel.org>
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>
---
kernel/sysctl.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 750c94313c1fd23551e03f455585d2dd94f3c758..9b08573bbacdfa0ec036a8043561253c21300c9a 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)
{
--
2.50.1
prev parent reply other threads:[~2025-10-16 12:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-16 12:57 [PATCH v2 00/11] sysctl: Generalize proc handler converter creation Joel Granados
2025-10-16 12:57 ` [PATCH v2 01/11] sysctl: Replace void pointer with const pointer to ctl_table Joel Granados
2025-10-16 12:57 ` [PATCH v2 02/11] sysctl: Remove superfluous tbl_data param from "dovec" functions Joel Granados
2025-10-16 12:57 ` [PATCH v2 03/11] sysctl: Remove superfluous __do_proc_* indirection Joel Granados
2025-10-16 12:57 ` [PATCH v2 04/11] sysctl: Indicate the direction of operation with macro names Joel Granados
2025-10-16 12:57 ` [PATCH v2 05/11] sysctl: Discriminate between kernel and user converter params Joel Granados
2025-10-16 12:57 ` [PATCH v2 06/11] sysctl: Create converter functions with two new macros Joel Granados
2025-10-16 12:57 ` [PATCH v2 07/11] sysctl: Create integer converters with one macro Joel Granados
2025-10-16 12:57 ` [PATCH v2 08/11] sysctl: Add optional range checking to SYSCTL_INT_CONV_CUSTOM Joel Granados
2025-10-16 12:57 ` [PATCH v2 09/11] sysctl: Create unsigned int converter using new macro Joel Granados
2025-10-16 12:57 ` [PATCH v2 10/11] sysctl: Add optional range checking to SYSCTL_UINT_CONV_CUSTOM Joel Granados
2025-10-16 12:57 ` Joel Granados [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251016-jag-sysctl_conv-v2-11-a2f16529acc4@kernel.org \
--to=joel.granados@kernel.org \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).