]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net: hsr: introduce common code for skb initialization
authorMurali Karicheri <m-karicheri2@ti.com>
Wed, 22 Jul 2020 14:40:17 +0000 (10:40 -0400)
committerDavid S. Miller <davem@davemloft.net>
Mon, 27 Jul 2020 19:20:40 +0000 (12:20 -0700)
As a preparatory patch to introduce PRP protocol support in the
driver, refactor the skb init code to a separate function.

Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/hsr/hsr_device.c

index 40ac45123a62118eff294e68eb9b7e9c7f9a63ef..bfe2d1449dbd835b785ba8d434ab909587cad08a 100644 (file)
@@ -230,15 +230,11 @@ static const struct header_ops hsr_header_ops = {
        .parse   = eth_header_parse,
 };
 
-static void send_hsr_supervision_frame(struct hsr_port *master,
-                                      u8 type, u8 hsr_ver)
+static struct sk_buff *hsr_init_skb(struct hsr_port *master, u8 hsr_ver)
 {
+       struct hsr_priv *hsr = master->hsr;
        struct sk_buff *skb;
        int hlen, tlen;
-       struct hsr_tag *hsr_tag;
-       struct hsr_sup_tag *hsr_stag;
-       struct hsr_sup_payload *hsr_sp;
-       unsigned long irqflags;
 
        hlen = LL_RESERVED_SPACE(master->dev);
        tlen = master->dev->needed_tailroom;
@@ -247,22 +243,44 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
                            sizeof(struct hsr_sup_payload) + hlen + tlen);
 
        if (!skb)
-               return;
+               return skb;
 
        skb_reserve(skb, hlen);
-
        skb->dev = master->dev;
        skb->protocol = htons(hsr_ver ? ETH_P_HSR : ETH_P_PRP);
        skb->priority = TC_PRIO_CONTROL;
 
        if (dev_hard_header(skb, skb->dev, (hsr_ver ? ETH_P_HSR : ETH_P_PRP),
-                           master->hsr->sup_multicast_addr,
+                           hsr->sup_multicast_addr,
                            skb->dev->dev_addr, skb->len) <= 0)
                goto out;
+
        skb_reset_mac_header(skb);
        skb_reset_network_header(skb);
        skb_reset_transport_header(skb);
 
+       return skb;
+out:
+       kfree_skb(skb);
+
+       return NULL;
+}
+
+static void send_hsr_supervision_frame(struct hsr_port *master,
+                                      u8 type, u8 hsr_ver)
+{
+       struct hsr_sup_payload *hsr_sp;
+       struct hsr_sup_tag *hsr_stag;
+       struct hsr_tag *hsr_tag;
+       unsigned long irqflags;
+       struct sk_buff *skb;
+
+       skb = hsr_init_skb(master, hsr_ver);
+       if (!skb) {
+               WARN_ONCE(1, "HSR: Could not send supervision frame\n");
+               return;
+       }
+
        if (hsr_ver > 0) {
                hsr_tag = skb_put(skb, sizeof(struct hsr_tag));
                hsr_tag->encap_proto = htons(ETH_P_PRP);
@@ -299,11 +317,8 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
                return;
 
        hsr_forward_skb(skb, master);
-       return;
 
-out:
-       WARN_ONCE(1, "HSR: Could not send supervision frame\n");
-       kfree_skb(skb);
+       return;
 }
 
 /* Announce (supervision frame) timer function