Skip to contentSkip to conversation

ieee802154: fix skb get fc on big endian

PATCH In review Alexander Aring 2 participants 2 messages Jun 18, 2016 – Jun 22, 2016

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

PATCH 1/1 ieee802154: fix skb get fc on big endian

This patch fixes ieee802154_get_fc_from_skb function on big endian machines. The function get_unaligned_le16 converts the byte order to host byte order but we want to keep the byte order like in mac header.

---
 include/net/mac802154.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
include/net/mac802154.h +7 -5
index df34187..3d7fa73 100644
@@ -247,14 +247,16 @@ struct ieee802154_ops {
  */
 static inline __le16 ieee802154_get_fc_from_skb(const struct sk_buff *skb)
 {
+	__le16 fc;
+
 	/* check if we can fc at skb_mac_header of sk buffer */
-	if (unlikely(!skb_mac_header_was_set(skb) ||
-		     (skb_tail_pointer(skb) - skb_mac_header(skb)) < 2)) {
-		WARN_ON(1);
+	if (WARN_ON(!skb_mac_header_was_set(skb) ||
+		    (skb_tail_pointer(skb) -
+		     skb_mac_header(skb)) < IEEE802154_FC_LEN))
 		return cpu_to_le16(0);
-	}
 
-	return get_unaligned_le16(skb_mac_header(skb));
+	memcpy(&fc, skb_mac_header(skb), IEEE802154_FC_LEN);
+	return fc;
 }
 
 /**
Signature · 1 line
2.8.3
#1 lore raw

Hello.

Quoted 18 lines · Alexander Aring

This patch fixes ieee802154_get_fc_from_skb function on big endian machines. The function get_unaligned_le16 converts the byte order to host byte order but we want to keep the byte order like in mac header.

---
  include/net/mac802154.h | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
include/net/mac802154.h +1 -0
index df34187..3d7fa73 100644
@@ -247,14 +247,16 @@ struct ieee802154_ops {
   */
  static inline __le16 ieee802154_get_fc_from_skb(const struct sk_buff *skb)
  {
+	__le16 fc;

include/net/mac802154.h struct ieee802154_ops { · line 255

Quoted 10 lines
include/net/mac802154.h +4 -4
+
  	/* check if we can fc at skb_mac_header of sk buffer */
-	if (unlikely(!skb_mac_header_was_set(skb) ||
-		     (skb_tail_pointer(skb) - skb_mac_header(skb)) < 2)) {
-		WARN_ON(1);
+	if (WARN_ON(!skb_mac_header_was_set(skb) ||
+		    (skb_tail_pointer(skb) -
+		     skb_mac_header(skb)) < IEEE802154_FC_LEN))
  		return cpu_to_le16(0);
-	}

The hunk above is totally unrelated to the change you describe in your commit messages and should imho be split off into a different patch.

include/net/mac802154.h struct ieee802154_ops { · line 262

Quoted 7 lines
include/net/mac802154.h +2 -1
-	return get_unaligned_le16(skb_mac_header(skb));
+	memcpy(&fc, skb_mac_header(skb), IEEE802154_FC_LEN);
+	return fc;
  }
 
  /**

The actual fix for big endian looks fine to me.

regards
Stefan Schmidt