From patchwork Tue Oct 18 23:22:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Linus_L=C3=BCssing?= X-Patchwork-Id: 16754 Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 486D0830AE; Wed, 19 Oct 2016 01:22:44 +0200 (CEST) Authentication-Results: open-mesh.org; dmarc=none header.from=c0d3.blue Received-SPF: None (no SPF record) identity=mailfrom; client-ip=138.201.29.205; helo=mail.aperture-lab.de; envelope-from=linus.luessing@c0d3.blue; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dmarc=none header.from=c0d3.blue Received: from mail.aperture-lab.de (mail.aperture-lab.de [138.201.29.205]) by open-mesh.org (Postfix) with ESMTPS id 08E11830AD for ; Wed, 19 Oct 2016 01:22:40 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.aperture-lab.de (Postfix) with ESMTP id 26B13E105F for ; Wed, 19 Oct 2016 01:22:40 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aperture-lab.de Received: from mail.aperture-lab.de ([127.0.0.1]) by localhost (mail.aperture-lab.de [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id MJrthNqReaZf for ; Wed, 19 Oct 2016 01:22:40 +0200 (CEST) Received: from localhost (unknown [IPv6:2001:67c:2d50:0:c85:8cff:fe0f:63fe]) (Authenticated sender: linus.luessing@c0d3.blue) by mail.aperture-lab.de (Postfix) with ESMTPSA for ; Wed, 19 Oct 2016 01:22:39 +0200 (CEST) Date: Wed, 19 Oct 2016 01:22:39 +0200 From: Linus =?utf-8?q?L=C3=BCssing?= To: The list for a Better Approach To Mobile Ad-hoc Networking Message-ID: <20161018232239.GI6366@otheros> References: <20161018212125.32010-1-linus.luessing@c0d3.blue> <1555062.TzeBilqSPn@sven-edge> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1555062.TzeBilqSPn@sven-edge> User-Agent: Mutt/1.5.24 (2015-08-30) Subject: Re: [B.A.T.M.A.N.] [PATCH] batman-adv: compat: Substitute compat code for netlink constification X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" 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 +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,