Skip to contentSkip to conversation

genetlink: remove superfluous assignment

PATCH In review Cheng Renquan 2 participants 4 messages May 29, 2014 – Jun 2, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 genetlink: remove superfluous assignment

the local variable ops and n_ops were just read out from family, and not changed, why need to assign back?

Validation functions should operate on const parameters and not change anything.

---
 net/netlink/genetlink.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
net/netlink/genetlink.c +1 -5
Index: linux-3.14.3/net/netlink/genetlink.c
===================================================================
@@ -307,39 +307,35 @@
 		genl_ctrl_event(CTRL_CMD_DELMCAST_GRP, family,
 				&family->mcgrps[i], grp_id);
 	}
 }
 
-static int genl_validate_ops(struct genl_family *family)
+static int genl_validate_ops(const struct genl_family *family)
 {
 	const struct genl_ops *ops = family->ops;
 	unsigned int n_ops = family->n_ops;
 	int i, j;
 
 	if (WARN_ON(n_ops && !ops))
 		return -EINVAL;
 
 	if (!n_ops)
 		return 0;
 
 	for (i = 0; i < n_ops; i++) {
 		if (ops[i].dumpit == NULL && ops[i].doit == NULL)
 			return -EINVAL;
 		for (j = i + 1; j < n_ops; j++)
 			if (ops[i].cmd == ops[j].cmd)
 				return -EINVAL;
 	}
 
-	/* family is not registered yet, so no locking needed */
-	family->ops = ops;
-	family->n_ops = n_ops;
-
 	return 0;
 }
maintainer
#1 lore raw

From: Cheng Renquan <[email protected]>
Date: Wed, 28 May 2014 23:54:08 -0700

Quoted 7 lines

the local variable ops and n_ops were just read out from family, and not changed, why need to assign back?

Validation functions should operate on const parameters and not change anything.

This patch was corrupted by your email client, please fix this up and resubmit.

#2 lore raw

PATCH 1/1 genetlink: remove superfluous assignment

In reply to Cheng Renquan

the local variable ops and n_ops were just read out from family, and not changed, hence no need to assign back.

Validation functions should operate on const parameters and not change anything.

---
 net/netlink/genetlink.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
net/netlink/genetlink.c +1 -5
index a3ba3ca..76393f2 100644
@@ -309,46 +309,42 @@ static void genl_unregister_mc_groups(struct genl_family *family)
 
 	for (i = 0; i < family->n_mcgrps; i++) {
 		int grp_id = family->mcgrp_offset + i;
 
 		if (grp_id != 1)
 			clear_bit(grp_id, mc_groups);
 		genl_ctrl_event(CTRL_CMD_DELMCAST_GRP, family,
 				&family->mcgrps[i], grp_id);
 	}
 }
 
-static int genl_validate_ops(struct genl_family *family)
+static int genl_validate_ops(const struct genl_family *family)
 {
 	const struct genl_ops *ops = family->ops;
 	unsigned int n_ops = family->n_ops;
 	int i, j;
 
 	if (WARN_ON(n_ops && !ops))
 		return -EINVAL;
 
 	if (!n_ops)
 		return 0;
 
 	for (i = 0; i < n_ops; i++) {
 		if (ops[i].dumpit == NULL && ops[i].doit == NULL)
 			return -EINVAL;
 		for (j = i + 1; j < n_ops; j++)
 			if (ops[i].cmd == ops[j].cmd)
 				return -EINVAL;
 	}
 
-	/* family is not registered yet, so no locking needed */
-	family->ops = ops;
-	family->n_ops = n_ops;
-
 	return 0;
 }
 
 /**
  * __genl_register_family - register a generic netlink family
  * @family: generic netlink family
  *
  * Registers the specified family after validating it first. Only one
  * family may be registered with the same family name or identifier.
  * The family id may equal GENL_ID_GENERATE causing an unique id to
  * be automatically generated and assigned.
maintainer Applied
#3 lore raw

From: [email protected]
Date: Mon, 2 Jun 2014 01:18:01 -0700

Quoted 7 lines

the local variable ops and n_ops were just read out from family, and not changed, hence no need to assign back.

Validation functions should operate on const parameters and not change anything.

Applied, thanks Cheng.