openvswitch: Refactor action alloc and copy api.
There are two separate API to allocate and copy actions list. Anytime
OVS needs to copy action list, it needs to call both functions.
Following patch moves action allocation to copy function to avoid
code duplication.
Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c
index 1050b28..482a0cb 100644
--- a/net/openvswitch/flow_netlink.c
+++ b/net/openvswitch/flow_netlink.c
@@ -1284,7 +1284,7 @@
#define MAX_ACTIONS_BUFSIZE (32 * 1024)
-struct sw_flow_actions *ovs_nla_alloc_flow_actions(int size)
+static struct sw_flow_actions *nla_alloc_flow_actions(int size)
{
struct sw_flow_actions *sfa;
@@ -1329,7 +1329,7 @@
new_acts_size = MAX_ACTIONS_BUFSIZE;
}
- acts = ovs_nla_alloc_flow_actions(new_acts_size);
+ acts = nla_alloc_flow_actions(new_acts_size);
if (IS_ERR(acts))
return (void *)acts;
@@ -1396,7 +1396,7 @@
a->nla_len = sfa->actions_len - st_offset;
}
-static int ovs_nla_copy_actions__(const struct nlattr *attr,
+static int __ovs_nla_copy_actions(const struct nlattr *attr,
const struct sw_flow_key *key,
int depth, struct sw_flow_actions **sfa,
__be16 eth_type, __be16 vlan_tci);
@@ -1441,7 +1441,7 @@
if (st_acts < 0)
return st_acts;
- err = ovs_nla_copy_actions__(actions, key, depth + 1, sfa,
+ err = __ovs_nla_copy_actions(actions, key, depth + 1, sfa,
eth_type, vlan_tci);
if (err)
return err;
@@ -1684,7 +1684,7 @@
return 0;
}
-static int ovs_nla_copy_actions__(const struct nlattr *attr,
+static int __ovs_nla_copy_actions(const struct nlattr *attr,
const struct sw_flow_key *key,
int depth, struct sw_flow_actions **sfa,
__be16 eth_type, __be16 vlan_tci)
@@ -1846,8 +1846,18 @@
const struct sw_flow_key *key,
struct sw_flow_actions **sfa)
{
- return ovs_nla_copy_actions__(attr, key, 0, sfa, key->eth.type,
- key->eth.tci);
+ int err;
+
+ *sfa = nla_alloc_flow_actions(nla_len(attr));
+ if (IS_ERR(*sfa))
+ return PTR_ERR(*sfa);
+
+ err = __ovs_nla_copy_actions(attr, key, 0, sfa, key->eth.type,
+ key->eth.tci);
+ if (err)
+ kfree(*sfa);
+
+ return err;
}
static int sample_action_to_attr(const struct nlattr *attr, struct sk_buff *skb)