Re: [PATCH RFC 1/9] sysctl: Add struct ctl_table_tmpl as a distinct template type
From: Linus Torvalds
Date: Thu Nov 26 2026 - 12:05:10 EST
On Thu, 26 Nov 2026 at 03:47, Joel Granados <joel.granados@xxxxxxxxxx> wrote:
>
> +/* Template version of struct ctl_table. Used for registering ctl_table templates */
> +struct ctl_table_tmpl {
> + struct ctl_table t;
> +};
So I really don't like members named 't'.
I see why you are doing it, but maybe you aren't aware that we already
enabled ms-extensions, and you can actually use *unnamed* structs in
templates.
So you can do
struct ctl_table_tmpl { struct ctl_table; }
and that gives you a new type that you can use without any "t." kind
of thing, but is still distinct from 'struct ctl_table".
Note: being unnamed is very convenient in some situations, less so in
others. If you actually then want to access not the individual fields
(which is very easy), but get from the template to an actual "struct
ctl_table", you'd have to use some explicit helper wrapper, something
like
static inline struct ctl_table *template_to_inner(struct ctl_table_tmpl *a)
{ return container_of(&a->procname, struct ctl_table, procname); }
or whatever.
Honestly, right now you seem to do something really ugly: you have
that 'template', but then you hardly ever *use* it as anything but a
top-level interface, and you turn it into a 'struct ctl_table *' very
early. And that looks like it's done exactly to avoid the whole
messiness with the 't' member - but it also measn that internally that
"template" has lost almost all meaning, and it looks like a regular
ctl_table.
Maybe that's fine. But it feels like the template is less of a real
template than just a wrapper that is only used at the top-level
wrapper and then never again. That does *not* work well if you were to
add a few extra fields to the template (that is then *not* in the
struct ctl_table. because they are only used to set it up). Hmm?
Linus