Move in memory all the frames with an incorrect alignment.
This is to prevent unaligned memory accesses into the upper layers.
Note 1: this is a penalty for some architecture like SH.
Note 2: indeed, this patch restores an old one posted three years ago
(http://marc.info/?l=linux-usb-devel&m=116578791817830&w=2).
Signed-off-by: Giuseppe Cavallaro <peppe.cavallaro@st.com>
---
drivers/net/usb/asix.c | 42 ++++++++++++++++++++++++------------------
1 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c
index 396f821..cea98be 100644
--- a/drivers/net/usb/asix.c
+++ b/drivers/net/usb/asix.c
@@ -298,26 +298,37 @@ asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
static int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
{
- u8 *head;
- u32 header;
- char *packet;
- struct sk_buff *ax_skb;
- u16 size;
-
- head = (u8 *) skb->data;
- memcpy(&header, head, sizeof(header));
+ unsigned int header;
+
+ memcpy(&header, skb->data, sizeof(header));
le32_to_cpus(&header);
- packet = head + sizeof(header);
skb_pull(skb, 4);
while (skb->len > 0) {
+ struct sk_buff *ax_skb;
+ unsigned int size;
+ int offset;
+
if ((short)(header & 0x0000ffff) !=
~((short)((header & 0xffff0000) >> 16))) {
deverr(dev,"asix_rx_fixup() Bad Header Length");
}
+
/* get the packet length */
- size = (u16) (header & 0x0000ffff);
+ size = header & 0x0000ffff;
+
+ /* Move in memory frames with incorrect alignment.
+ * This is to prevent unaligned memory accesses into
+ * the upper layers. */
+ offset = NET_IP_ALIGN ? ((unsigned long)skb->data -
+ NET_IP_ALIGN) & 3 : 0;
+
+ if (offset) {
+ skb->data -= offset;
+ skb->tail -= offset;
+ memmove(skb->data - offset, skb->data, skb->len);
+ }
if ((skb->len) - ((size + 1) & 0xfffe) == 0)
return 2;
@@ -327,23 +338,18 @@ static int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
}
...