<!DOCTYPE html>
<!-- BaNnErBlUrFlE-BoDy-start -->
<!-- Preheader Text : BEGIN -->
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;max-height:0px;opacity:0;overflow:hidden;">
Add a MODULE_SYSCTL_TABLE call into register_sysctl() for existing callers to automatically use it. Add optional 'template arguments' to support a dynamic table/path defined at run-time based on a 'template' table/path available at build-time. </div>
<!-- Preheader Text : END -->
<!-- Email Banner : BEGIN -->
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;max-height:0px;opacity:0;overflow:hidden;"></div>
<!-- Email Banner : END -->
<!-- BaNnErBlUrFlE-BoDy-end -->
<html>
<head><!-- BaNnErBlUrFlE-HeAdEr-start -->
<style>
#pfptBannere4tjs6v { all: revert !important; display: block !important;
visibility: visible !important; opacity: 1 !important;
background-color: #c2d4d4 !important;
max-width: none !important; max-height: none !important }
.pfptPrimaryButtone4tjs6v:hover, .pfptPrimaryButtone4tjs6v:focus {
background-color: #a2b1b1 !important; }
.pfptPrimaryButtone4tjs6v:active {
background-color: #828e8e !important; }
html:root, html:root>body { all: revert !important; display: block !important;
visibility: visible !important; opacity: 1 !important; }
</style>
<!-- BaNnErBlUrFlE-HeAdEr-end -->
</head><body><pre style="font-family: sans-serif; font-size: 100%; white-space: pre-wrap; word-wrap: break-word">Add a MODULE_SYSCTL_TABLE call into register_sysctl() for existing callers
to automatically use it.
Add optional 'template arguments' to support a dynamic table/path defined
at run-time based on a 'template' table/path available at build-time.
Split the update of callers with template arguments into another commit for
clarity, disabling them for now.
Note: there is no register_sysctl_sz() wrapper, as it is used in even more
dynamic cases (e.g., table generated at run-time not based on a template).
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
---
drivers/parport/procfs.c | 2 ++
include/linux/sysctl.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
index 3880460e67f25a7d8708a734c6f4d9e6c363c726..cda3221e386ed7a4afc898b3d0313081dee5b49b 100644
--- a/drivers/parport/procfs.c
+++ b/drivers/parport/procfs.c
@@ -13,6 +13,8 @@
* Cleaned up include files - Russell King <linux@arm.uk.linux.org>
*/
+#define SYSCTL_MODULE_ALIASES_DISABLE
+
#include <linux/string.h>
#include <linux/init.h>
#include <linux/module.h>
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 0adc056ff54d895500c376361fe966bfa5126a3e..b808fbc1d964f453db8e354825fd8800db1eecd3 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -335,8 +335,58 @@ struct ctl_table_root {
#define MODULE_SYSCTL_TABLE(path, table)
#endif
-#define register_sysctl(path, table) \
- register_sysctl_sz(path, table, ARRAY_SIZE(table))
+/*
+ * The register_sysctl() wrapper for the MODULE_SYSCTL_TABLE macro
+ * automatically creates symbols in sysctl table registration sites.
+ *
+ * Usage:
+ * - register_sysctl(path, table);
+ * - register_sysctl(path, table, table_tmpl);
+ * - register_sysctl(path, table, table_tmpl, path_tmpl);
+ *
+ * The optional 'template arguments' ('table_tmpl' and 'path_tmpl')
+ * can support callers with non-static variables: dynamic table/path
+ * defined at run-time based on a 'template' available at build-time.
+ *
+ * For example, a sysctl table, or table and path, which is/are:
+ *
+ * - per-namespace: different tables based on a template table
+ * (i.e., same files in each namespace) with identical path
+ * (i.e., same path in each namespace).
+ *
+ * - per-device: different tables based on a template table
+ * (i.e., same files for each device) with different paths
+ * (i.e., diff paths for each device) based on a template path.
+ *
+ * The wrapper passes the build-time parameters (templates) to the macro
+ * and the dynamic/run-time parameters (instances) to the wrapped function.
+ *
+ * The wrapper reduces to the wrapped function when either the macro or the
+ * config option is disabled.
+ */
+#define _register_sysctl(path, table, table_tmpl, path_tmpl) \
+({ \
+ MODULE_SYSCTL_TABLE(path_tmpl, table_tmpl); \
+ register_sysctl_sz(path, table, ARRAY_SIZE(table)); \
+})
+
+#define register_sysctl(path, table, tmpl_args...) \
+ _register_sysctl(path, table, \
+ __sysctl_table_tmpl_or_default(table, ## tmpl_args), \
+ __sysctl_path_tmpl_or_default(path, ## tmpl_args))
+
+/* Helper macros for optional template arguments */
+#define __sysctl_table_tmpl(skip, table_tmpl, ...) \
+ table_tmpl
+
+#define __sysctl_path_tmpl(skip, table_tmpl, path_tmpl, ...) \
+ path_tmpl
+
+#define __sysctl_table_tmpl_or_default(default, tmpl_args...) \
+ __sysctl_table_tmpl(, ## tmpl_args, default)
+
+#define __sysctl_path_tmpl_or_default(default, tmpl_args...) \
+ __sysctl_path_tmpl(, ## tmpl_args, default, default)
#ifdef CONFIG_SYSCTL
--
2.47.3
</pre></body></html>