netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: netdev@vger.kernel.org
Cc: Johannes Berg <johannes.berg@intel.com>
Subject: [RFC 7/7] genetlink: allow making ops const
Date: Thu, 14 Nov 2013 10:14:46 +0100	[thread overview]
Message-ID: <1384420486-8713-8-git-send-email-johannes@sipsolutions.net> (raw)
In-Reply-To: <1384420486-8713-1-git-send-email-johannes@sipsolutions.net>

From: Johannes Berg <johannes.berg@intel.com>

Allow making the ops array const by not modifying the ops
flags on registration but rather only when ops are sent
out in the family information.

No users are updated yet.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 include/net/genetlink.h |  6 +++---
 net/netlink/genetlink.c | 23 +++++++++++++----------
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/include/net/genetlink.h b/include/net/genetlink.h
index abd4146..0b6b10b 100644
--- a/include/net/genetlink.h
+++ b/include/net/genetlink.h
@@ -57,7 +57,7 @@ struct genl_family {
 					     struct sk_buff *skb,
 					     struct genl_info *info);
 	struct nlattr **	attrbuf;	/* private */
-	struct genl_ops *	ops;
+	const struct genl_ops *	ops;
 	unsigned int		n_ops;
 	struct list_head	family_list;	/* private */
 	struct list_head	mcast_groups;	/* private */
@@ -130,10 +130,10 @@ static inline int genl_register_family(struct genl_family *family)
 }
 
 int __genl_register_family_with_ops(struct genl_family *family,
-				    struct genl_ops *ops, size_t n_ops);
+				    const struct genl_ops *ops, size_t n_ops);
 
 static inline int genl_register_family_with_ops(struct genl_family *family,
-	struct genl_ops *ops, size_t n_ops)
+	const struct genl_ops *ops, size_t n_ops)
 {
 	family->module = THIS_MODULE;
 	return __genl_register_family_with_ops(family, ops, n_ops);
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index d5a7f98..3ad151f 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -284,7 +284,8 @@ static void genl_unregister_mc_groups(struct genl_family *family)
 		__genl_unregister_mc_group(family, grp);
 }
 
-static int genl_validate_add_ops(struct genl_family *family, struct genl_ops *ops,
+static int genl_validate_add_ops(struct genl_family *family,
+				 const struct genl_ops *ops,
 				 unsigned int n_ops)
 {
 	int i, j;
@@ -299,12 +300,6 @@ static int genl_validate_add_ops(struct genl_family *family, struct genl_ops *op
 			if (ops[i].cmd == ops[j].cmd)
 				return -EINVAL;
 		}
-		if (ops[i].dumpit)
-			ops[i].flags |= GENL_CMD_CAP_DUMP;
-		if (ops[i].doit)
-			ops[i].flags |= GENL_CMD_CAP_DO;
-		if (ops[i].policy)
-			ops[i].flags |= GENL_CMD_CAP_HASPOL;
 	}
 
 	/* family is not registered yet, so no locking needed */
@@ -404,7 +399,7 @@ EXPORT_SYMBOL(__genl_register_family);
  * Return 0 on success or a negative error code.
  */
 int __genl_register_family_with_ops(struct genl_family *family,
-	struct genl_ops *ops, size_t n_ops)
+	const struct genl_ops *ops, size_t n_ops)
 {
 	int err;
 
@@ -674,14 +669,22 @@ static int ctrl_fill_info(struct genl_family *family, u32 portid, u32 seq,
 
 		for (i = 0; i < family->n_ops; i++) {
 			struct nlattr *nest;
-			struct genl_ops *ops = &family->ops[i];
+			const struct genl_ops *ops = &family->ops[i];
+			u32 flags = ops->flags;
+
+			if (ops->dumpit)
+				flags |= GENL_CMD_CAP_DUMP;
+			if (ops->doit)
+				flags |= GENL_CMD_CAP_DO;
+			if (ops->policy)
+				flags |= GENL_CMD_CAP_HASPOL;
 
 			nest = nla_nest_start(skb, i + 1);
 			if (nest == NULL)
 				goto nla_put_failure;
 
 			if (nla_put_u32(skb, CTRL_ATTR_OP_ID, ops->cmd) ||
-			    nla_put_u32(skb, CTRL_ATTR_OP_FLAGS, ops->flags))
+			    nla_put_u32(skb, CTRL_ATTR_OP_FLAGS, flags))
 				goto nla_put_failure;
 
 			nla_nest_end(skb, nest);
-- 
1.8.4.rc3

  parent reply	other threads:[~2013-11-14  9:14 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-14  9:14 [RFC 0/7] genetlink: reduce ops size and complexity Johannes Berg
2013-11-14  9:14 ` [RFC 1/7] taskstats: use genl_register_family_with_ops() Johannes Berg
2013-11-14  9:14 ` [RFC 2/7] hsr: " Johannes Berg
2013-11-14  9:14 ` [RFC 3/7] ieee802154: " Johannes Berg
2013-11-14  9:14 ` [RFC 4/7] wimax: " Johannes Berg
2013-11-14  9:14 ` [RFC 5/7] genetlink: remove genl_register_ops/genl_unregister_ops Johannes Berg
2013-11-14  9:14 ` [RFC 6/7] genetlink: register family ops as array Johannes Berg
2013-11-14  9:14 ` Johannes Berg [this message]
2013-11-14 13:41 ` [RFC 8/7] genetlink: make all genl_ops users const Johannes Berg
2013-11-14 14:01 ` [RFC 9/7] genetlink: make genl_ops flags a u8 and move to end Johannes Berg
2013-11-14 14:36 ` [RFC 0/7] genetlink: reduce ops size and complexity Johannes Berg
2013-11-14 16:02 ` Johannes Berg
2013-11-14 16:14 ` [PATCH 0/9] genetlink: reduce ops size and complexity (v2) Johannes Berg
2013-11-14 16:14   ` [PATCH 1/9] taskstats: use genl_register_family_with_ops() Johannes Berg
2013-11-14 16:14   ` [PATCH 2/9] hsr: " Johannes Berg
2013-11-14 16:14   ` [PATCH 3/9] ieee802154: " Johannes Berg
2013-11-14 16:14   ` [PATCH 4/9] wimax: " Johannes Berg
2013-11-14 16:14   ` [PATCH 5/9] genetlink: remove genl_register_ops/genl_unregister_ops Johannes Berg
2013-11-14 16:14   ` [PATCH 6/9] genetlink: register family ops as array Johannes Berg
2013-11-14 16:14   ` [PATCH 7/9] genetlink: allow making ops const Johannes Berg
2013-11-14 16:14   ` [PATCH 8/9] genetlink: make all genl_ops users const Johannes Berg
2013-11-14 16:14   ` [PATCH 9/9] genetlink: make genl_ops flags a u8 and move to end Johannes Berg
2013-11-14 22:12   ` [PATCH 0/9] genetlink: reduce ops size and complexity (v2) David Miller
2013-11-15 13:18     ` Johannes Berg
2013-11-15 13:23       ` Johannes Berg
2013-11-15 14:45         ` Jamal Hadi Salim
2013-11-16  1:54         ` David Miller
2013-11-16  1:53       ` David Miller
2013-11-17  9:12         ` Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1384420486-8713-8-git-send-email-johannes@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=johannes.berg@intel.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).