public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v3 0/2] sysctl: refactor ctl_table initialization
@ 2026-03-02  6:32 wen.yang
  2026-03-02  6:32 ` [RFC PATCH v3 1/2] sysctl: introduce CTLTBL_ENTRY_XXX() helper macros wen.yang
  2026-03-02  6:32 ` [RFC PATCH v3 2/2] sysctl: convert kernel/sysctl-test.c to use CTLTBL_ENTRY_XXX() wen.yang
  0 siblings, 2 replies; 3+ messages in thread
From: wen.yang @ 2026-03-02  6:32 UTC (permalink / raw)
  To: Joel Granados; +Cc: linux-kernel, Wen Yang

From: Wen Yang <wen.yang@linux.dev>

The main motivation for this series is to avoid treewide patch series.
Historically, changes to how struct ctl_table entries are initialized
(e.g. removing the child field, const-qualifying ctl_table) required
touching hundreds of files across all subsystems. Such series require
the attention of many maintainers, sometimes need to be pulled into
mainline in a special way, and create lots of unnecessary churn.

By introducing a family of CTLTBL_ENTRY_XXX() helper macros in
<linux/sysctl.h>, any future structural changes to struct ctl_table can
be handled in one place — the macro definition — without requiring a
treewide sweep of all callers. Individual subsystem maintainers can also
migrate their sysctl tables to use the macros at their own pace, without
any coordinated effort.

This series:
 1. Introduces the CTLTBL_ENTRY_XXX() macros in include/linux/sysctl.h,
    allowing callers to initialize struct ctl_table entries indirectly
    via the macro instead of assigning each field directly. The macros
    use _Generic() for automatic type detection and proc_handler
    selection, provide smart defaults (auto address-of, auto maxlen via
    sizeof), and include compile-time validation of name, mode, and
    handler.
 2. Converts kernel/sysctl-test.c to use the new macros as a
    demonstration, replacing direct struct ctl_table field assignments
    with CTLTBL_ENTRY_XXX() calls. Four new tests are added to cover the
    previously untested variants (CTLTBL_ENTRY_V, VN, VNM, VNMH), bringing
    the total to 16 passing tests.

Thanks Joel's suggestions and guidance:
[1] https://sysctl-dev-rtd.readthedocs.io/en/latest/notes/ctltable_entry_macro.html#table-entry-macro
[2] https://lore.kernel.org/all/psot4oeauxi3yyj2w4ajm3tfgtcsvao4rhv5sgd5s6ymmjgojk@p3vrj3qluban/


Wen Yang (2):
  sysctl: introduce CTLTBL_ENTRY_XXX() helper macros
  sysctl: convert kernel/sysctl-test.c to use CTLTBL_ENTRY_XXX()

 include/linux/sysctl.h | 302 +++++++++++++++++++++++++++++++++++++++++
 kernel/sysctl-test.c   | 240 ++++++++++++++++++--------------
 kernel/sysctl.c        |   2 +
 3 files changed, 445 insertions(+), 99 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-02  6:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-02  6:32 [RFC PATCH v3 0/2] sysctl: refactor ctl_table initialization wen.yang
2026-03-02  6:32 ` [RFC PATCH v3 1/2] sysctl: introduce CTLTBL_ENTRY_XXX() helper macros wen.yang
2026-03-02  6:32 ` [RFC PATCH v3 2/2] sysctl: convert kernel/sysctl-test.c to use CTLTBL_ENTRY_XXX() wen.yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox