* [PATCH] module: Clarify documentation of module_param_call()
@ 2023-09-05 19:13 Kees Cook
2023-09-05 19:36 ` Miguel Ojeda
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2023-09-05 19:13 UTC (permalink / raw)
To: Luis Chamberlain
Cc: Kees Cook, Johan Hovold, Jessica Yu, Sagi Grimberg,
Nick Desaulniers, Miguel Ojeda, Joe Perches, Azeem Shaikh,
linux-modules, linux-kernel, linux-hardening
Commit 9bbb9e5a3310 ("param: use ops in struct kernel_param, rather than
get and set fns directly") added the comment that module_param_call()
was deprecated, during a large scale refactoring to bring sanity to type
casting back then. In 2017 following more cleanups, it became useful
against as it wraps a common pattern of creating an ops struct for a
given get/set pair:
b2f270e87473 ("module: Prepare to convert all module_param_call() prototypes")
ece1996a21ee ("module: Do not paper over type mismatches in module_param_call()")
static const struct kernel_param_ops __param_ops_##name = \
{ .flags = 0, .set = _set, .get = _get }; \
__module_param_call(MODULE_PARAM_PREFIX, \
name, &__param_ops_##name, arg, perm, -1, 0)
__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0)
Many users of module_param_cb() appear to be almost universally
open-coding the same thing that module_param_call() does now. Don't
discourage[1] people from using module_param_call() but clarifying the
comment: module_param_cb() is useful if you repeatedly use the same pair
of get/set functions.
[1] https://lore.kernel.org/lkml/202308301546.5C789E5EC@keescook/
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Johan Hovold <johan@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: Nick Desaulniers <ndesaulniers@gooogle.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Joe Perches <joe@perches.com>
Cc: Azeem Shaikh <azeemshaikh38@gmail.com>
Cc: linux-modules@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Luis, I note that include/linux/moduleparam.h isn't in the MAINTAINERS
file pattern. Perhaps you want to use include/linux/module*.h?
---
include/linux/moduleparam.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 962cd41a2cb5..d32450583182 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -293,7 +293,7 @@ struct kparam_array
= { __param_str_##name, THIS_MODULE, ops, \
VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }
-/* Obsolete - use module_param_cb() */
+/* For repeated _set & _get usage use module_param_cb() */
#define module_param_call(name, _set, _get, arg, perm) \
static const struct kernel_param_ops __param_ops_##name = \
{ .flags = 0, .set = _set, .get = _get }; \
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] module: Clarify documentation of module_param_call()
2023-09-05 19:13 [PATCH] module: Clarify documentation of module_param_call() Kees Cook
@ 2023-09-05 19:36 ` Miguel Ojeda
0 siblings, 0 replies; 2+ messages in thread
From: Miguel Ojeda @ 2023-09-05 19:36 UTC (permalink / raw)
To: Kees Cook
Cc: Luis Chamberlain, Johan Hovold, Jessica Yu, Sagi Grimberg,
Nick Desaulniers, Miguel Ojeda, Joe Perches, Azeem Shaikh,
linux-modules, linux-kernel, linux-hardening
On Tue, Sep 5, 2023 at 9:13 PM Kees Cook <keescook@chromium.org> wrote:
>
> Commit 9bbb9e5a3310 ("param: use ops in struct kernel_param, rather than
> get and set fns directly") added the comment that module_param_call()
> was deprecated, during a large scale refactoring to bring sanity to type
> casting back then. In 2017 following more cleanups, it became useful
> against as it wraps a common pattern of creating an ops struct for a
s/against/again/
> Many users of module_param_cb() appear to be almost universally
> open-coding the same thing that module_param_call() does now. Don't
> discourage[1] people from using module_param_call() but clarifying the
> comment: module_param_cb() is useful if you repeatedly use the same pair
> of get/set functions.
s/clarifying/clarify/
I sampled some, and indeed many define the ops struct.
> [1] https://lore.kernel.org/lkml/202308301546.5C789E5EC@keescook/
Link: tag here? It is actually quite nicely explained there.
> -/* Obsolete - use module_param_cb() */
> +/* For repeated _set & _get usage use module_param_cb() */
Perhaps add "instead"? Or perhaps add a bit more detail, something like:
Useful for describing a set/get pair used only once (i.e. for this
parameter). For repeated set/get pairs (i.e. the same kernel_param_ops
struct), use module_param_cb() instead.
Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
Cheers,
Miguel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-05 19:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-05 19:13 [PATCH] module: Clarify documentation of module_param_call() Kees Cook
2023-09-05 19:36 ` Miguel Ojeda
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).