Skip to contentSkip to conversation

net: Constify struct genl_small_ops

PATCH Applied Rikard Falkeborn 2 participants 4 messages Oct 4, 2020 – Oct 5, 2020

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

v2 cover net: Constify struct genl_small_ops

Make a couple of static struct genl_small_ops const to allow the compiler to put them in read-only memory. Patches are independent.

v2: Rebase on net-next, genl_ops -> genl_small_ops

Rikard Falkeborn (2):
mptcp: Constify mptcp_pm_ops
net: openvswitch: Constify static struct genl_small_ops

 net/mptcp/pm_netlink.c      | 2 +-
 net/openvswitch/conntrack.c | 2 +-
 net/openvswitch/meter.c     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.28.0
#1 lore raw

PATCH v2 1/2 mptcp: Constify mptcp_pm_ops

The only usages of mptcp_pm_ops is to assign its address to the small_ops field of the genl_family struct, which is a const pointer, and applying ARRAY_SIZE() on it. Make it const to allow the compiler to put it in read-only memory.

Signed-off-by Rikard Falkeborn <rikard.falkeborn(a)gmail.com>
---
 net/mptcp/pm_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mptcp/pm_netlink.c +1 -1
index 9f9cd41b7733..0d6f3d912891 100644
@@ -1054,7 +1054,7 @@ mptcp_nl_cmd_get_limits(struct sk_buff *skb, struct genl_info *info)
 	return -EMSGSIZE;
 }
 
-static struct genl_small_ops mptcp_pm_ops[] = {
+static const struct genl_small_ops mptcp_pm_ops[] = {
 	{
 		.cmd    = MPTCP_PM_CMD_ADD_ADDR,
 		.doit   = mptcp_nl_cmd_add_addr,
Signature · 1 line
2.28.0
#2 lore raw

PATCH v2 2/2 net: openvswitch: Constify static struct genl_small_ops

In reply to Rikard Falkeborn

The only usage of these is to assign their address to the small_ops field in the genl_family struct, which is a const pointer, and applying ARRAY_SIZE() on them. Make them const to allow the compiler to put them in read-only memory.

---
 net/openvswitch/conntrack.c | 2 +-
 net/openvswitch/meter.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/openvswitch/conntrack.c +1 -1
index 18af10b7ef0e..e6fe26a9c892 100644
@@ -2231,7 +2231,7 @@ static int ovs_ct_limit_cmd_get(struct sk_buff *skb, struct genl_info *info)
 	return err;
 }
 
-static struct genl_small_ops ct_limit_genl_ops[] = {
+static const struct genl_small_ops ct_limit_genl_ops[] = {
 	{ .cmd = OVS_CT_LIMIT_CMD_SET,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
 		.flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN
net/openvswitch/meter.c +1 -1
index 50541e874726..8fbefd52af7f 100644
@@ -672,7 +672,7 @@ bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb,
 	return false;
 }
 
-static struct genl_small_ops dp_meter_genl_ops[] = {
+static const struct genl_small_ops dp_meter_genl_ops[] = {
 	{ .cmd = OVS_METER_CMD_FEATURES,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
 		.flags = 0,		  /* OK for unprivileged users. */
Signature · 1 line
2.28.0
maintainer Applied
#3 lore raw
In reply to Rikard Falkeborn

From: Rikard Falkeborn <rikard.falkeborn(a)gmail.com>
Date: Mon, 5 Oct 2020 01:44:15 +0200

Quoted 4 lines

Make a couple of static struct genl_small_ops const to allow the compiler to put them in read-only memory. Patches are independent.

v2: Rebase on net-next, genl_ops -> genl_small_ops

Applied, thank you.