diff mbox series

[ovs-dev,13/23] datapath: simplify the ovs_dp_cmd_new

Message ID 1597963790-12362-14-git-send-email-gvrose8192@gmail.com
State Superseded
Headers show
Series Add support for Linux kernels up to 5.9.x | expand

Commit Message

Gregory Rose Aug. 20, 2020, 10:49 p.m. UTC
From: Tonghao Zhang <xiangxia.m.yue@gmail.com>

Upstream commit:
    commit eec62eadd1d757b0743ccbde55973814f3ad396e
    Author: Tonghao Zhang <xiangxia.m.yue@gmail.com>
    Date:   Fri Nov 1 22:23:54 2019 +0800

    net: openvswitch: simplify the ovs_dp_cmd_new

    use the specified functions to init resource.

    Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
    Tested-by: Greg Rose <gvrose8192@gmail.com>
    Acked-by: Pravin B Shelar <pshelar@ovn.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Cc: Tonghao Zhang <xiangxia.m.yue@gmail.com>
Signed-off-by: Greg Rose <gvrose8192@gmail.com>
---
 datapath/datapath.c | 60 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 38 insertions(+), 22 deletions(-)

Comments

Tonghao Zhang Aug. 25, 2020, 4 a.m. UTC | #1
On Fri, Aug 21, 2020 at 6:50 AM Greg Rose <gvrose8192@gmail.com> wrote:
>
> From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
>
> Upstream commit:
>     commit eec62eadd1d757b0743ccbde55973814f3ad396e
>     Author: Tonghao Zhang <xiangxia.m.yue@gmail.com>
>     Date:   Fri Nov 1 22:23:54 2019 +0800
>
>     net: openvswitch: simplify the ovs_dp_cmd_new
>
>     use the specified functions to init resource.
>
>     Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
>     Tested-by: Greg Rose <gvrose8192@gmail.com>
>     Acked-by: Pravin B Shelar <pshelar@ovn.org>
>     Signed-off-by: David S. Miller <davem@davemloft.net>
>
> Cc: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> Signed-off-by: Greg Rose <gvrose8192@gmail.com>
Reviewed-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> ---
>  datapath/datapath.c | 60 +++++++++++++++++++++++++++++++++--------------------
>  1 file changed, 38 insertions(+), 22 deletions(-)
>
> diff --git a/datapath/datapath.c b/datapath/datapath.c
> index c222ef8..f04ce21 100644
> --- a/datapath/datapath.c
> +++ b/datapath/datapath.c
> @@ -1665,6 +1665,31 @@ static int ovs_dp_change(struct datapath *dp, struct nlattr *a[])
>         return 0;
>  }
>
> +static int ovs_dp_stats_init(struct datapath *dp)
> +{
> +       dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu);
> +       if (!dp->stats_percpu)
> +               return -ENOMEM;
> +
> +       return 0;
> +}
> +
> +static int ovs_dp_vport_init(struct datapath *dp)
> +{
> +       int i;
> +
> +       dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS,
> +                                 sizeof(struct hlist_head),
> +                                 GFP_KERNEL);
> +       if (!dp->ports)
> +               return -ENOMEM;
> +
> +       for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++)
> +               INIT_HLIST_HEAD(&dp->ports[i]);
> +
> +       return 0;
> +}
> +
>  static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
>  {
>         struct nlattr **a = info->attrs;
> @@ -1673,7 +1698,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
>         struct datapath *dp;
>         struct vport *vport;
>         struct ovs_net *ovs_net;
> -       int err, i;
> +       int err;
>
>         err = -EINVAL;
>         if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID])
> @@ -1686,35 +1711,26 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
>         err = -ENOMEM;
>         dp = kzalloc(sizeof(*dp), GFP_KERNEL);
>         if (dp == NULL)
> -               goto err_free_reply;
> +               goto err_destroy_reply;
>
>         ovs_dp_set_net(dp, sock_net(skb->sk));
>
>         /* Allocate table. */
>         err = ovs_flow_tbl_init(&dp->table);
>         if (err)
> -               goto err_free_dp;
> +               goto err_destroy_dp;
>
> -       dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu);
> -       if (!dp->stats_percpu) {
> -               err = -ENOMEM;
> +       err = ovs_dp_stats_init(dp);
> +       if (err)
>                 goto err_destroy_table;
> -       }
>
> -       dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS,
> -                                 sizeof(struct hlist_head),
> -                                 GFP_KERNEL);
> -       if (!dp->ports) {
> -               err = -ENOMEM;
> -               goto err_destroy_percpu;
> -       }
> -
> -       for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++)
> -               INIT_HLIST_HEAD(&dp->ports[i]);
> +       err = ovs_dp_vport_init(dp);
> +       if (err)
> +               goto err_destroy_stats;
>
>         err = ovs_meters_init(dp);
>         if (err)
> -               goto err_destroy_ports_array;
> +               goto err_destroy_ports;
>
>         /* Set up our datapath device. */
>         parms.name = nla_data(a[OVS_DP_ATTR_NAME]);
> @@ -1764,15 +1780,15 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
>
>  err_destroy_meters:
>         ovs_meters_exit(dp);
> -err_destroy_ports_array:
> +err_destroy_ports:
>         kfree(dp->ports);
> -err_destroy_percpu:
> +err_destroy_stats:
>         free_percpu(dp->stats_percpu);
>  err_destroy_table:
>         ovs_flow_tbl_destroy(&dp->table);
> -err_free_dp:
> +err_destroy_dp:
>         kfree(dp);
> -err_free_reply:
> +err_destroy_reply:
>         kfree_skb(reply);
>  err:
>         return err;
> --
> 1.8.3.1
>
diff mbox series

Patch

diff --git a/datapath/datapath.c b/datapath/datapath.c
index c222ef8..f04ce21 100644
--- a/datapath/datapath.c
+++ b/datapath/datapath.c
@@ -1665,6 +1665,31 @@  static int ovs_dp_change(struct datapath *dp, struct nlattr *a[])
 	return 0;
 }
 
+static int ovs_dp_stats_init(struct datapath *dp)
+{
+	dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu);
+	if (!dp->stats_percpu)
+		return -ENOMEM;
+
+	return 0;
+}
+
+static int ovs_dp_vport_init(struct datapath *dp)
+{
+	int i;
+
+	dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS,
+				  sizeof(struct hlist_head),
+				  GFP_KERNEL);
+	if (!dp->ports)
+		return -ENOMEM;
+
+	for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++)
+		INIT_HLIST_HEAD(&dp->ports[i]);
+
+	return 0;
+}
+
 static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
 {
 	struct nlattr **a = info->attrs;
@@ -1673,7 +1698,7 @@  static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
 	struct datapath *dp;
 	struct vport *vport;
 	struct ovs_net *ovs_net;
-	int err, i;
+	int err;
 
 	err = -EINVAL;
 	if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID])
@@ -1686,35 +1711,26 @@  static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
 	err = -ENOMEM;
 	dp = kzalloc(sizeof(*dp), GFP_KERNEL);
 	if (dp == NULL)
-		goto err_free_reply;
+		goto err_destroy_reply;
 
 	ovs_dp_set_net(dp, sock_net(skb->sk));
 
 	/* Allocate table. */
 	err = ovs_flow_tbl_init(&dp->table);
 	if (err)
-		goto err_free_dp;
+		goto err_destroy_dp;
 
-	dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu);
-	if (!dp->stats_percpu) {
-		err = -ENOMEM;
+	err = ovs_dp_stats_init(dp);
+	if (err)
 		goto err_destroy_table;
-	}
 
-	dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS,
-				  sizeof(struct hlist_head),
-				  GFP_KERNEL);
-	if (!dp->ports) {
-		err = -ENOMEM;
-		goto err_destroy_percpu;
-	}
-
-	for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++)
-		INIT_HLIST_HEAD(&dp->ports[i]);
+	err = ovs_dp_vport_init(dp);
+	if (err)
+		goto err_destroy_stats;
 
 	err = ovs_meters_init(dp);
 	if (err)
-		goto err_destroy_ports_array;
+		goto err_destroy_ports;
 
 	/* Set up our datapath device. */
 	parms.name = nla_data(a[OVS_DP_ATTR_NAME]);
@@ -1764,15 +1780,15 @@  static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
 
 err_destroy_meters:
 	ovs_meters_exit(dp);
-err_destroy_ports_array:
+err_destroy_ports:
 	kfree(dp->ports);
-err_destroy_percpu:
+err_destroy_stats:
 	free_percpu(dp->stats_percpu);
 err_destroy_table:
 	ovs_flow_tbl_destroy(&dp->table);
-err_free_dp:
+err_destroy_dp:
 	kfree(dp);
-err_free_reply:
+err_destroy_reply:
 	kfree_skb(reply);
 err:
 	return err;