diff mbox series

[4/5] genetlink: factor skb preparation out of ctrl_dumppolicy()

Message ID 20201002110205.ce65a163aebd.I0e59ae414404a92143c6ed8b0b0caf7e0e0d11a0@changeid
State New
Headers show
Series genetlink: complete policy dumping | expand

Commit Message

Johannes Berg Oct. 2, 2020, 9:09 a.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

We'll need this later for the per-op policy index dump.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 net/netlink/genetlink.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

Comments

Jakub Kicinski Oct. 2, 2020, 3:42 p.m. UTC | #1
On Fri,  2 Oct 2020 11:09:43 +0200 Johannes Berg wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> We'll need this later for the per-op policy index dump.
> 
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>

Reviewed-by: Jakub Kicinski <kuba@kernel.org>

>  	while (netlink_policy_dump_loop(ctx->state)) {
> -		void *hdr;
> +		void *hdr = ctrl_dumppolicy_prep(skb, cb);
>  		struct nlattr *nest;
>  
> -		hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
> -				  cb->nlh->nlmsg_seq, &genl_ctrl,
> -				  NLM_F_MULTI, CTRL_CMD_GETPOLICY);
>  		if (!hdr)
>  			goto nla_put_failure;

bike shedding, but I find it less pretty when functions which require
error checking are called as variable init (if it's not the only
variable declared).
diff mbox series

Patch

diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 42777749d4d8..0ab9549e30ee 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -1168,23 +1168,35 @@  static int ctrl_dumppolicy_start(struct netlink_callback *cb)
 					      op.maxattr);
 }
 
+static void *ctrl_dumppolicy_prep(struct sk_buff *skb,
+				  struct netlink_callback *cb)
+{
+	struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
+	void *hdr;
+
+	hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
+			  cb->nlh->nlmsg_seq, &genl_ctrl,
+			  NLM_F_MULTI, CTRL_CMD_GETPOLICY);
+	if (!hdr)
+		return NULL;
+
+	if (nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, ctx->fam_id))
+		return NULL;
+
+	return hdr;
+}
+
 static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
 {
 	struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
 
 	while (netlink_policy_dump_loop(ctx->state)) {
-		void *hdr;
+		void *hdr = ctrl_dumppolicy_prep(skb, cb);
 		struct nlattr *nest;
 
-		hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
-				  cb->nlh->nlmsg_seq, &genl_ctrl,
-				  NLM_F_MULTI, CTRL_CMD_GETPOLICY);
 		if (!hdr)
 			goto nla_put_failure;
 
-		if (nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, ctx->fam_id))
-			goto nla_put_failure;
-
 		nest = nla_nest_start(skb, CTRL_ATTR_POLICY);
 		if (!nest)
 			goto nla_put_failure;