Re: [PATCH RFC 1/9] sysctl: Add struct ctl_table_tmpl as a distinct template type

From: Alexey Gladkov

Date: Sat Dec 05 2026 - 06:34:56 EST


On Wed, Dec 02, 2026 at 10:36:39AM +0100, Joel Granados wrote:
> On Thu, Nov 26, 2026 at 09:04:40AM -0800, Linus Torvalds wrote:
> > 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".
>
> That looks cleaner; I'll try to use it for the V1.
>
> >
> > 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.
>
> I used the ctl_table_tmpl type as a way for the caller to signal the
> type of registration. I agree, it is superficial. And the caller already
> signals it buy using the template registration function.
>
> >
> > 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
>
> Thx for the review.
>
> I'll either remove the template altogether and just have a ""context"
> registration function that accepts two ctl_table and inits the context
> or I'll make more use of the template in sysctl core as I might have
> missed an advantage to having the template within the sysctl core.
>
> Best
>

I just wanted to ask. Should we go back to my patches [1], or do they
still not make sense to you?

They do not have void pointers to pointers, and no memory is allocated for
customizing the ctl_table.

[1] https://lore.kernel.org/all/cover.1790439358.git.legion@xxxxxxxxxx/

--
Rgrds, legion