All of lore.kernel.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH] batman-adv: compat: Substitute compat code for netlink constification
@ 2016-10-18 21:21 Linus Lüssing
  2016-10-18 21:24 ` Linus Lüssing
  2016-10-18 21:28 ` Sven Eckelmann
  0 siblings, 2 replies; 6+ messages in thread
From: Linus Lüssing @ 2016-10-18 21:21 UTC (permalink / raw)
  To: b.a.t.m.a.n

Substitutes the compat-patches approach for the netlink const changes to
the prefered way of using compat-includes.

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
---
 compat-include/net/genetlink.h | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/compat-include/net/genetlink.h b/compat-include/net/genetlink.h
index 72a8991..b195b47 100644
--- a/compat-include/net/genetlink.h
+++ b/compat-include/net/genetlink.h
@@ -28,6 +28,15 @@
 
 #include <linux/export.h>
 
+/* multicast groups */
+enum __batadv_netlink_multicast_groups {
+	__BATADV_NL_MCGRP_TPMETER,
+};
+
+static struct genl_multicast_group __batadv_netlink_mcgrps[] = {
+	[__BATADV_NL_MCGRP_TPMETER] = { .name = BATADV_NL_MCAST_GROUP_TPMETER },
+};
+
 struct batadv_genl_family {
 	/* data handled by the actual kernel */
 	struct genl_family family;
@@ -140,12 +149,14 @@ static inline int batadv_genl_register_family(struct genl_family *family)
 static inline int
 batadv_genl_register_family_with_ops_grps(struct genl_family *family,
 					  struct genl_ops *ops, size_t n_ops,
-					  struct genl_multicast_group *mcgrps,
+					  const struct genl_multicast_group *mcgrps,
 					  size_t n_mcgrps)
 {
+	BUILD_BUG_ON(ARRAY_SIZE(__batadv_netlink_mcgrps) != n_mcgrps);
+
 	family->ops = ops;
 	family->n_ops = n_ops;
-	family->mcgrps = mcgrps;
+	family->mcgrps = __batadv_netlink_mcgrps;
 	family->n_mcgrps = n_mcgrps;
 	family->module = THIS_MODULE;
 
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: compat: Substitute compat code for netlink constification
  2016-10-18 21:21 [B.A.T.M.A.N.] [PATCH] batman-adv: compat: Substitute compat code for netlink constification Linus Lüssing
@ 2016-10-18 21:24 ` Linus Lüssing
  2016-10-18 21:28 ` Sven Eckelmann
  1 sibling, 0 replies; 6+ messages in thread
From: Linus Lüssing @ 2016-10-18 21:24 UTC (permalink / raw)
  To: b.a.t.m.a.n

On Tue, Oct 18, 2016 at 11:21:25PM +0200, Linus Lüssing wrote:
> Substitutes the compat-patches approach for the netlink const changes to
> the prefered way of using compat-includes.
> 
> Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
> ---

Actually, it isn't a substitution yet, the compat-patches thing is
still there.

Let me know what you think about this approach and if you like it
what I should do about the replacements.sh.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: compat: Substitute compat code for netlink constification
  2016-10-18 21:21 [B.A.T.M.A.N.] [PATCH] batman-adv: compat: Substitute compat code for netlink constification Linus Lüssing
  2016-10-18 21:24 ` Linus Lüssing
@ 2016-10-18 21:28 ` Sven Eckelmann
  2016-10-18 23:22   ` Linus Lüssing
  1 sibling, 1 reply; 6+ messages in thread
From: Sven Eckelmann @ 2016-10-18 21:28 UTC (permalink / raw)
  To: b.a.t.m.a.n

[-- Attachment #1: Type: text/plain, Size: 1098 bytes --]

On Dienstag, 18. Oktober 2016 23:21:25 CEST Linus Lüssing wrote:
> Substitutes the compat-patches approach for the netlink const changes to
> the prefered way of using compat-includes.
> 
> Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
> ---
>  compat-include/net/genetlink.h | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/compat-include/net/genetlink.h b/compat-include/net/genetlink.h
> index 72a8991..b195b47 100644
> --- a/compat-include/net/genetlink.h
> +++ b/compat-include/net/genetlink.h
> @@ -28,6 +28,15 @@
>  
>  #include <linux/export.h>
>  
> +/* multicast groups */
> +enum __batadv_netlink_multicast_groups {
> +	__BATADV_NL_MCGRP_TPMETER,
> +};
> +
> +static struct genl_multicast_group __batadv_netlink_mcgrps[] = {
> +	[__BATADV_NL_MCGRP_TPMETER] = { .name = BATADV_NL_MCAST_GROUP_TPMETER },
> +};
> +

Doesn't seem to scale. Especially when we think about batadv_netlink_ops
which should also be const. It is currently not const because of the
Linux <= 3.13 workaround.

Kind regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: compat: Substitute compat code for netlink constification
  2016-10-18 21:28 ` Sven Eckelmann
@ 2016-10-18 23:22   ` Linus Lüssing
  2016-10-19  6:31     ` Sven Eckelmann
  0 siblings, 1 reply; 6+ messages in thread
From: Linus Lüssing @ 2016-10-18 23:22 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Tue, Oct 18, 2016 at 11:28:23PM +0200, Sven Eckelmann wrote:
> Doesn't seem to scale. Especially when we think about batadv_netlink_ops
> which should also be const. It is currently not const because of the
> Linux <= 3.13 workaround.

Hm, okay, batadv_netlink_ops is a little more tricky/larger, yes.
What about a memcpy'ing approach with BUILD_BUG_ON()'s as
safe-guards like this:


diff --git a/compat-include/net/genetlink.h b/compat-include/net/genetlink.h
index 72a8991..f16bf35 100644
--- a/compat-include/net/genetlink.h
+++ b/compat-include/net/genetlink.h
@@ -28,6 +28,9 @@
 
 #include <linux/export.h>
 
+static struct genl_ops __batadv_netlink_ops[12];
+static struct genl_multicast_group __batadv_netlink_mcgrps[1];
+
 struct batadv_genl_family {
 	/* data handled by the actual kernel */
 	struct genl_family family;
@@ -137,15 +140,23 @@ static inline int batadv_genl_register_family(struct genl_family *family)
 	return ret;
 }
 
-static inline int
+static inline int __init
 batadv_genl_register_family_with_ops_grps(struct genl_family *family,
-					  struct genl_ops *ops, size_t n_ops,
-					  struct genl_multicast_group *mcgrps,
+					  const struct genl_ops *ops, size_t n_ops,
+					  const struct genl_multicast_group *mcgrps,
 					  size_t n_mcgrps)
 {
-	family->ops = ops;
+	BUILD_BUG_ON(ARRAY_SIZE(__batadv_netlink_ops) != n_ops);
+	BUILD_BUG_ON(ARRAY_SIZE(__batadv_netlink_mcgrps) != n_mcgrps);
+	BUILD_BUG_ON(sizeof(__batadv_netlink_ops) != sizeof(*ops) * n_ops);
+	BUILD_BUG_ON(sizeof(__batadv_netlink_mcgrps) != sizeof(*mcgrps) * n_mcgrps);
+
+	memcpy(__batadv_netlink_ops, ops, sizeof(__batadv_netlink_ops));
+	memcpy(__batadv_netlink_mcgrps, mcgrps, sizeof(__batadv_netlink_mcgrps));
+
+	family->ops = __batadv_netlink_ops;
 	family->n_ops = n_ops;
-	family->mcgrps = mcgrps;
+	family->mcgrps = __batadv_netlink_mcgrps;
 	family->n_mcgrps = n_mcgrps;
 	family->module = THIS_MODULE;
 
diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c
index 64cb6ac..aee20a3 100644
--- a/net/batman-adv/netlink.c
+++ b/net/batman-adv/netlink.c
@@ -534,7 +534,7 @@ batadv_netlink_dump_hardifs(struct sk_buff *msg, struct netlink_callback *cb)
 	return msg->len;
 }
 
-static struct genl_ops batadv_netlink_ops[] = {
+static const struct genl_ops batadv_netlink_ops[] = {
 	{
 		.cmd = BATADV_CMD_GET_MESH_INFO,
 		.flags = GENL_ADMIN_PERM,

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: compat: Substitute compat code for netlink constification
  2016-10-18 23:22   ` Linus Lüssing
@ 2016-10-19  6:31     ` Sven Eckelmann
  2016-10-20 18:33       ` Linus Lüssing
  0 siblings, 1 reply; 6+ messages in thread
From: Sven Eckelmann @ 2016-10-19  6:31 UTC (permalink / raw)
  To: b.a.t.m.a.n

[-- Attachment #1: Type: text/plain, Size: 1287 bytes --]

On Mittwoch, 19. Oktober 2016 01:22:39 CEST Linus Lüssing wrote:
> On Tue, Oct 18, 2016 at 11:28:23PM +0200, Sven Eckelmann wrote:
> > Doesn't seem to scale. Especially when we think about batadv_netlink_ops
> > which should also be const. It is currently not const because of the
> > Linux <= 3.13 workaround.
> 
> Hm, okay, batadv_netlink_ops is a little more tricky/larger, yes.
> What about a memcpy'ing approach with BUILD_BUG_ON()'s as
> safe-guards like this:

Yes, this would also be an idea. But I would personally just use the 
coccinelle approach because it needs less extra hacks. Or do you have any 
problems with coccinelle? My personal preferences are (at the moment):

1. code which doesn't need compat code
2. code which can supported with clean (not too hacky) compat-include
3. code which can be supported with coccinelle
4. code which can be supported with compat.h hacks
5. code which can be supported with small patches

The replace.sh was just a quick way to make sure we can ship 2016.4 without to 
many extra modifications.

Btw. this is right now only something for later. It is more important to get 
your other changes in master. And also to get the patchwork queue smaller - so 
reviews are more than welcome.

Kind regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: compat: Substitute compat code for netlink constification
  2016-10-19  6:31     ` Sven Eckelmann
@ 2016-10-20 18:33       ` Linus Lüssing
  0 siblings, 0 replies; 6+ messages in thread
From: Linus Lüssing @ 2016-10-20 18:33 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Wed, Oct 19, 2016 at 08:31:03AM +0200, Sven Eckelmann wrote:
> On Mittwoch, 19. Oktober 2016 01:22:39 CEST Linus Lüssing wrote:
> > On Tue, Oct 18, 2016 at 11:28:23PM +0200, Sven Eckelmann wrote:
> > > Doesn't seem to scale. Especially when we think about batadv_netlink_ops
> > > which should also be const. It is currently not const because of the
> > > Linux <= 3.13 workaround.
> > 
> > Hm, okay, batadv_netlink_ops is a little more tricky/larger, yes.
> > What about a memcpy'ing approach with BUILD_BUG_ON()'s as
> > safe-guards like this:
> 
> Yes, this would also be an idea. But I would personally just use the 
> coccinelle approach because it needs less extra hacks. Or do you have any 
> problems with coccinelle?

Hm, no, dunno. Just haven't really looked at coccinelle yet and
thought your point 3. (cocinelle) were on place 4. instead.
Besides, I had fun creating this compat patch and was marvelled
that the BUILD_BUG_ON() worked even with function parameters :D
(maybe, actually because they were const now? You clever compiler
:D).

Also, it looks like the whole compat infrastructure is growing and
I'm wondering whether it is easier to maintain slightly larger
compat-includes vs. then two more places where compat changes
could come from.


But I don't feel strongly about it, if others think coccinelle is
easier to review and maintain, then I'm fine with it and will have
a closer look at coccinelle :).

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-10-20 18:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-18 21:21 [B.A.T.M.A.N.] [PATCH] batman-adv: compat: Substitute compat code for netlink constification Linus Lüssing
2016-10-18 21:24 ` Linus Lüssing
2016-10-18 21:28 ` Sven Eckelmann
2016-10-18 23:22   ` Linus Lüssing
2016-10-19  6:31     ` Sven Eckelmann
2016-10-20 18:33       ` Linus Lüssing

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.