sysctl: Add size to register_net_sysctl function

This commit adds size to the register_net_sysctl indirection function to
facilitate the removal of the sentinel elements (last empty markers)
from the ctl_table arrays. Though we don't actually remove any sentinels
in this commit, register_net_sysctl* now has the capability of
forwarding table_size for when that happens.

We create a new function register_net_sysctl_sz with an extra size
argument. A macro replaces the existing register_net_sysctl. The size in
the macro is SIZE_MAX instead of ARRAY_SIZE to avoid compilation errors
while we systematically migrate to register_net_sysctl_sz. Will change
to ARRAY_SIZE in subsequent commits.

Care is taken to add table_size to the stopping criteria in such a way
that when we remove the empty sentinel element, it will continue
stopping in the last element of the ctl_table array.

Signed-off-by: Joel Granados <j.granados@samsung.com>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
This commit is contained in:
Joel Granados
2023-08-09 12:50:00 +02:00
committed by Luis Chamberlain
parent 3bc269cfd3
commit 95d4977876
2 changed files with 19 additions and 13 deletions

View File

@@ -469,15 +469,17 @@ void unregister_pernet_device(struct pernet_operations *);
struct ctl_table;
#define register_net_sysctl(net, path, table) \
register_net_sysctl_sz(net, path, table, SIZE_MAX)
#ifdef CONFIG_SYSCTL
int net_sysctl_init(void);
struct ctl_table_header *register_net_sysctl(struct net *net, const char *path,
struct ctl_table *table);
struct ctl_table_header *register_net_sysctl_sz(struct net *net, const char *path,
struct ctl_table *table, size_t table_size);
void unregister_net_sysctl_table(struct ctl_table_header *header);
#else
static inline int net_sysctl_init(void) { return 0; }
static inline struct ctl_table_header *register_net_sysctl(struct net *net,
const char *path, struct ctl_table *table)
static inline struct ctl_table_header *register_net_sysctl_sz(struct net *net,
const char *path, struct ctl_table *table, size_t table_size)
{
return NULL;
}