Subject: Re: [PATCH 3/5] genetlink: statically initialize families

From: Johannes Berg <[email-masked]>
Date: Tue, 25 Oct 2016 13:38:28 +0200

On Tue, 2016-10-25 at 11:25 +0000, David Laight wrote:

> > Actually, with the new system where it's not const, I could even
> > split this up and submit per subsystem, i.e. the fourth patch
> > doesn't depend on it. I thought it would, since I wanted to make it
> > const, but since I failed it doesn't actually have that dependency.
> 
> Actually, why aren't the structures 'const' ?
> 
> You could use a #define to set the .ops and .n_ops fields.
> (and maybe .module = THIS_MODULE as well).

This stuff isn't the problem - after this patch these are of course
statically initialized and const.

The problem is that the struct members family->id, family->mcgrp_offset 
and family->attrbuf, are only determined at genl_register_family().

I considered simply moving them into a new struct, that contains just
those along with a pointer to the family, but then I have essentially
two choices:

1) look up the registration struct by the family every time I need the
   family ID, which is all the time; that would be rather inefficient

2) change *all* genetlink code to not pass the family but rather pass a
   pointer returned by genl_register_family(); that's a massive change

So on the whole, I decided that __ro_after_init was entirely reasonable
and then even this patch isn't really necessary, but since I had it
anyway it still seemed to make sense, even if I had to add all those
forward declarations.

johannes