skbuff/mac80211: introduce and use skb_put_zero()
authorJohannes Berg <johannes.berg@intel.com>
Wed, 24 May 2017 07:07:47 +0000 (09:07 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 30 May 2017 07:14:30 +0000 (09:14 +0200)
This pattern was introduced a number of times in mac80211 just now,
and since it's present in a number of other places it makes sense
to add a little helper for it.

This just adds the helper and transforms the mac80211 code, a later
patch will transform other places.

Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
include/linux/skbuff.h
net/mac80211/mesh.c
net/mac80211/mesh_plink.c

index bfc7892..d92056b 100644 (file)
@@ -1937,6 +1937,15 @@ static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len)
        return tmp;
 }
 
+static inline unsigned char *skb_put_zero(struct sk_buff *skb, unsigned int len)
+{
+       unsigned char *tmp = skb_put(skb, len);
+
+       memset(tmp, 0, len);
+
+       return tmp;
+}
+
 unsigned char *skb_push(struct sk_buff *skb, unsigned int len);
 static inline unsigned char *__skb_push(struct sk_buff *skb, unsigned int len)
 {
index 3d6b3d6..ad5d1cf 100644 (file)
@@ -744,8 +744,7 @@ ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
                int ie_len = 2 + sizeof(struct ieee80211_channel_sw_ie) +
                             2 + sizeof(struct ieee80211_mesh_chansw_params_ie);
 
-               pos = skb_put(skb, ie_len);
-               memset(pos, 0, ie_len);
+               pos = skb_put_zero(skb, ie_len);
                *pos++ = WLAN_EID_CHANNEL_SWITCH;
                *pos++ = 3;
                *pos++ = 0x0;
@@ -772,8 +771,7 @@ ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
                switch (csa->settings.chandef.width) {
                case NL80211_CHAN_WIDTH_40:
                        ie_len = 2 + sizeof(struct ieee80211_sec_chan_offs_ie);
-                       pos = skb_put(skb, ie_len);
-                       memset(pos, 0, ie_len);
+                       pos = skb_put_zero(skb, ie_len);
 
                        *pos++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET; /* EID */
                        *pos++ = 1;                                 /* len */
@@ -789,8 +787,7 @@ ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
                        /* Channel Switch Wrapper + Wide Bandwidth CSA IE */
                        ie_len = 2 + 2 +
                                 sizeof(struct ieee80211_wide_bw_chansw_ie);
-                       pos = skb_put(skb, ie_len);
-                       memset(pos, 0, ie_len);
+                       pos = skb_put_zero(skb, ie_len);
 
                        *pos++ = WLAN_EID_CHANNEL_SWITCH_WRAPPER; /* EID */
                        *pos++ = 5;                               /* len */
index 1131cd5..82cfd23 100644 (file)
@@ -264,8 +264,7 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
                band = sband->band;
 
                /* capability info */
-               pos = skb_put(skb, 2);
-               memset(pos, 0, 2);
+               pos = skb_put_zero(skb, 2);
                if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
                        /* AID */
                        pos = skb_put(skb, 2);