[2/3] batman-adv: elp: skb network header API instead of skb->data access

Message ID 20160821032534.11074-2-linus.luessing@c0d3.blue (mailing list archive)
State Deferred, archived
Delegated to: Marek Lindner
Headers

Commit Message

Linus Lüssing Aug. 21, 2016, 3:25 a.m. UTC
  Instead of playing with skb attributes directly, let's use the
appropriate, more descriptive API instead.

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
---
 net/batman-adv/bat_v_elp.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
  

Comments

Linus Lüssing Aug. 21, 2016, 3:35 a.m. UTC | #1
On Sun, Aug 21, 2016 at 05:25:33AM +0200, Linus Lüssing wrote:
> Instead of playing with skb attributes directly, let's use the
> appropriate, more descriptive API instead.
> 
> Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
> ---

Sorry, was on the maint branch when writing and
git-format-patch'ing this. While "git am *.patch" fails,
"git am --3way *.patch" works and looks good to me.
  
Linus Lüssing Aug. 23, 2016, 1:17 a.m. UTC | #2
On Sun, Aug 21, 2016 at 05:25:33AM +0200, Linus Lüssing wrote:
> Instead of playing with skb attributes directly, let's use the
> appropriate, more descriptive API instead.
> 
> Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
> ---

Hm, wanted to fix up the aligment issues Sven mentioned in PATCH
1/3 wis this patch. But actually skb_put() assigment without
skb->data access works directly, let's go for this two bytes fix.

And ignore this [PATCH 2/3] for now, please.
  

Patch

diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
index ea463bf..af414b0 100644
--- a/net/batman-adv/bat_v_elp.c
+++ b/net/batman-adv/bat_v_elp.c
@@ -263,7 +263,7 @@  static void batadv_v_elp_periodic_work(struct work_struct *work)
 	if (!skb)
 		goto restart_timer;
 
-	elp_packet = (struct batadv_elp_packet *)skb->data;
+	elp_packet = (struct batadv_elp_packet *)skb_network_header(skb);
 	elp_packet->seqno = htonl(atomic_read(&hard_iface->bat_v.elp_seqno));
 	elp_interval = atomic_read(&hard_iface->bat_v.elp_interval);
 	elp_packet->elp_interval = htonl(elp_interval);
@@ -323,19 +323,23 @@  out:
 int batadv_v_elp_iface_enable(struct batadv_hard_iface *hard_iface)
 {
 	struct batadv_elp_packet *elp_packet;
+	struct sk_buff *skb;
 	u32 random_seqno;
 	size_t size;
 	int res = -ENOMEM;
 
 	size = ETH_HLEN + NET_IP_ALIGN + BATADV_ELP_HLEN;
-	hard_iface->bat_v.elp_skb = dev_alloc_skb(size);
-	if (!hard_iface->bat_v.elp_skb)
+	skb = dev_alloc_skb(size);
+	hard_iface->bat_v.elp_skb = skb;
+
+	if (!skb)
 		goto out;
 
 	skb_reserve(hard_iface->bat_v.elp_skb, ETH_HLEN + NET_IP_ALIGN);
+	skb_reset_network_header(skb);
 	skb_put(hard_iface->bat_v.elp_skb, BATADV_ELP_HLEN);
-	elp_packet = (struct batadv_elp_packet *)
-			hard_iface->bat_v.elp_skb->data;
+
+	elp_packet = (struct batadv_elp_packet *)skb_network_header(skb);
 	memset(elp_packet, 0, BATADV_ELP_HLEN);
 
 	elp_packet->packet_type = BATADV_ELP;
@@ -392,7 +396,7 @@  void batadv_v_elp_iface_activate(struct batadv_hard_iface *primary_iface,
 		return;
 
 	skb = hard_iface->bat_v.elp_skb;
-	elp_packet = (struct batadv_elp_packet *)skb->data;
+	elp_packet = (struct batadv_elp_packet *)skb_network_header(skb);
 	ether_addr_copy(elp_packet->orig,
 			primary_iface->net_dev->dev_addr);
 }
@@ -506,7 +510,7 @@  int batadv_v_elp_packet_recv(struct sk_buff *skb,
 	if (strcmp(bat_priv->bat_algo_ops->name, "BATMAN_V") != 0)
 		return NET_RX_DROP;
 
-	elp_packet = (struct batadv_elp_packet *)skb->data;
+	elp_packet = (struct batadv_elp_packet *)skb_network_header(skb);
 
 	batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
 		   "Received ELP packet from %pM seqno %u ORIG: %pM\n",