diff options
| -rw-r--r-- | drivers/net/usb/kalmia.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c index d965fb1e013e..d4edeb2af9be 100644 --- a/drivers/net/usb/kalmia.c +++ b/drivers/net/usb/kalmia.c | |||
| @@ -100,27 +100,35 @@ kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len, | |||
| 100 | static int | 100 | static int |
| 101 | kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr) | 101 | kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr) |
| 102 | { | 102 | { |
| 103 | char init_msg_1[] = | 103 | const static char init_msg_1[] = |
| 104 | { 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, | 104 | { 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, |
| 105 | 0x00, 0x00 }; | 105 | 0x00, 0x00 }; |
| 106 | char init_msg_2[] = | 106 | const static char init_msg_2[] = |
| 107 | { 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4, | 107 | { 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4, |
| 108 | 0x00, 0x00 }; | 108 | 0x00, 0x00 }; |
| 109 | char receive_buf[28]; | 109 | const static int buflen = 28; |
| 110 | char *usb_buf; | ||
| 110 | int status; | 111 | int status; |
| 111 | 112 | ||
| 112 | status = kalmia_send_init_packet(dev, init_msg_1, sizeof(init_msg_1) | 113 | usb_buf = kmalloc(buflen, GFP_DMA | GFP_KERNEL); |
| 113 | / sizeof(init_msg_1[0]), receive_buf, 24); | 114 | if (!usb_buf) |
| 115 | return -ENOMEM; | ||
| 116 | |||
| 117 | memcpy(usb_buf, init_msg_1, 12); | ||
| 118 | status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_1) | ||
| 119 | / sizeof(init_msg_1[0]), usb_buf, 24); | ||
| 114 | if (status != 0) | 120 | if (status != 0) |
| 115 | return status; | 121 | return status; |
| 116 | 122 | ||
| 117 | status = kalmia_send_init_packet(dev, init_msg_2, sizeof(init_msg_2) | 123 | memcpy(usb_buf, init_msg_2, 12); |
| 118 | / sizeof(init_msg_2[0]), receive_buf, 28); | 124 | status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_2) |
| 125 | / sizeof(init_msg_2[0]), usb_buf, 28); | ||
| 119 | if (status != 0) | 126 | if (status != 0) |
| 120 | return status; | 127 | return status; |
| 121 | 128 | ||
| 122 | memcpy(ethernet_addr, receive_buf + 10, ETH_ALEN); | 129 | memcpy(ethernet_addr, usb_buf + 10, ETH_ALEN); |
| 123 | 130 | ||
| 131 | kfree(usb_buf); | ||
| 124 | return status; | 132 | return status; |
| 125 | } | 133 | } |
| 126 | 134 | ||
| @@ -190,7 +198,8 @@ kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) | |||
| 190 | dev_kfree_skb_any(skb); | 198 | dev_kfree_skb_any(skb); |
| 191 | skb = skb2; | 199 | skb = skb2; |
| 192 | 200 | ||
| 193 | done: header_start = skb_push(skb, KALMIA_HEADER_LENGTH); | 201 | done: |
| 202 | header_start = skb_push(skb, KALMIA_HEADER_LENGTH); | ||
| 194 | ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12]; | 203 | ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12]; |
| 195 | ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13]; | 204 | ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13]; |
| 196 | 205 | ||
| @@ -201,9 +210,8 @@ kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) | |||
| 201 | header_start[0] = 0x57; | 210 | header_start[0] = 0x57; |
| 202 | header_start[1] = 0x44; | 211 | header_start[1] = 0x44; |
| 203 | content_len = skb->len - KALMIA_HEADER_LENGTH; | 212 | content_len = skb->len - KALMIA_HEADER_LENGTH; |
| 204 | header_start[2] = (content_len & 0xff); /* low byte */ | ||
| 205 | header_start[3] = (content_len >> 8); /* high byte */ | ||
| 206 | 213 | ||
| 214 | put_unaligned_le16(content_len, &header_start[2]); | ||
| 207 | header_start[4] = ether_type_1; | 215 | header_start[4] = ether_type_1; |
| 208 | header_start[5] = ether_type_2; | 216 | header_start[5] = ether_type_2; |
| 209 | 217 | ||
| @@ -231,13 +239,13 @@ kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | |||
| 231 | * Our task here is to strip off framing, leaving skb with one | 239 | * Our task here is to strip off framing, leaving skb with one |
| 232 | * data frame for the usbnet framework code to process. | 240 | * data frame for the usbnet framework code to process. |
| 233 | */ | 241 | */ |
| 234 | const u8 HEADER_END_OF_USB_PACKET[] = | 242 | const static u8 HEADER_END_OF_USB_PACKET[] = |
| 235 | { 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 }; | 243 | { 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 }; |
| 236 | const u8 EXPECTED_UNKNOWN_HEADER_1[] = | 244 | const static u8 EXPECTED_UNKNOWN_HEADER_1[] = |
| 237 | { 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 }; | 245 | { 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 }; |
| 238 | const u8 EXPECTED_UNKNOWN_HEADER_2[] = | 246 | const static u8 EXPECTED_UNKNOWN_HEADER_2[] = |
| 239 | { 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 }; | 247 | { 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 }; |
| 240 | u8 i = 0; | 248 | int i = 0; |
| 241 | 249 | ||
| 242 | /* incomplete header? */ | 250 | /* incomplete header? */ |
| 243 | if (skb->len < KALMIA_HEADER_LENGTH) | 251 | if (skb->len < KALMIA_HEADER_LENGTH) |
| @@ -285,7 +293,7 @@ kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | |||
| 285 | 293 | ||
| 286 | /* subtract start header and end header */ | 294 | /* subtract start header and end header */ |
| 287 | usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH); | 295 | usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH); |
| 288 | ether_packet_length = header_start[2] + (header_start[3] << 8); | 296 | ether_packet_length = get_unaligned_le16(&header_start[2]); |
| 289 | skb_pull(skb, KALMIA_HEADER_LENGTH); | 297 | skb_pull(skb, KALMIA_HEADER_LENGTH); |
| 290 | 298 | ||
| 291 | /* Some small packets misses end marker */ | 299 | /* Some small packets misses end marker */ |
