Skip to contentSkip to conversation

staging: vt6656: Use ether_addr_copy() in vnt_fill_ieee80211_rts.

PATCH In review Krzysztof Adamski 3 participants 4 messages Dec 16, 2014 – Jan 13, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: vt6656: Use ether_addr_copy() in vnt_fill_ieee80211_rts.

Both struct ieee80211_rts and struct ieee80211_hdr defined in linux/ieee80211.h are declared as __aligned(2) so it is safe to use ether_addr_copy() instead of memcpy().

---
  drivers/staging/vt6656/rxtx.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/vt6656/rxtx.c +3 -2
index ea5140a..280c923 100644
@@ -36,6 +36,7 @@
   *
   */
  
+#include <linux/etherdevice.h>
  #include "device.h"
  #include "rxtx.h"
  #include "card.h"
@@ -392,8 +393,8 @@ static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
  	rts->frame_control =
  		cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
  
-	memcpy(rts->ra, hdr->addr1, ETH_ALEN);
-	memcpy(rts->ta, hdr->addr2, ETH_ALEN);
+	ether_addr_copy(rts->ra, hdr->addr1);
+	ether_addr_copy(rts->ta, hdr->addr2);
  
  	return 0;
  }
Signature · 6 lines
1.9.3

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
#1 lore raw
Quoted 3 lines · Krzysztof Adamski

Both struct ieee80211_rts and struct ieee80211_hdr defined in linux/ieee80211.h are declared as __aligned(2) so it is safe to use ether_addr_copy() instead of memcpy().

Just fyi:

That the structure is declared __aligned(2) is not the important bit. What's necessary is that the members in the struct are __aligned(2).

In this case, all of these members are.

drivers/staging/vt6656/rxtx.c

Quoted 1 line
drivers/staging/vt6656/rxtx.c +0 -0

[]

Quoted 8 lines
drivers/staging/vt6656/rxtx.c +2 -2
@@ -392,8 +393,8 @@ static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
  	rts->frame_control =
  		cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
 
-	memcpy(rts->ra, hdr->addr1, ETH_ALEN);
-	memcpy(rts->ta, hdr->addr2, ETH_ALEN);
+	ether_addr_copy(rts->ra, hdr->addr1);
+	ether_addr_copy(rts->ta, hdr->addr2);
#2 lore raw
Quoted 5 lines · Joe Perches
Quoted 3 lines · Krzysztof Adamski

Both struct ieee80211_rts and struct ieee80211_hdr defined in linux/ieee80211.h are declared as __aligned(2) so it is safe to use ether_addr_copy() instead of memcpy().

Quoted 7 lines

Just fyi:

That the structure is declared __aligned(2) is not the important bit. What's necessary is that the members in the struct are __aligned(2).

In this case, all of these members are.

Hi,

Thank you for your feedback. Yes, you are right. It was a bit of a shortcut in my reasoning. Since struct is aligned and it's packed and both members preceding the array we want to copy are 16 bit large, the array address is guaranteed to be properly aligned.

Best regards,
Krzysztof Adamski

#3 lore raw
In reply to Krzysztof Adamski
Quoted 14 lines · Krzysztof Adamski

Both struct ieee80211_rts and struct ieee80211_hdr defined in linux/ieee80211.h are declared as __aligned(2) so it is safe to use ether_addr_copy() instead of memcpy().

---
  drivers/staging/vt6656/rxtx.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/vt6656/rxtx.c +0 -0
index ea5140a..280c923 100644

drivers/staging/vt6656/rxtx.c line 42

Quoted 7 lines
drivers/staging/vt6656/rxtx.c +1 -0
@@ -36,6 +36,7 @@
   *
   */
 
+#include <linux/etherdevice.h>
  #include "device.h"
  #include "rxtx.h"
  #include "card.h"

Something corrupted this patch :(