KS8851: Correct RX packet allocation

Use netdev_alloc_skb_ip_align() helper and do correct allocation

Tested-by: Abraham Arce <x0066660@ti.com>
Signed-off-by: Abraham Arce <x0066660@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Eric Dumazet and committed by
David S. Miller
972c40b5 719f8358

+26 -23
+26 -23
drivers/net/ks8851.c
··· 503 503 ks8851_wrreg16(ks, KS_RXQCR, 504 504 ks->rc_rxqcr | RXQCR_SDA | RXQCR_ADRFE); 505 505 506 - if (rxlen > 0) { 507 - skb = netdev_alloc_skb(ks->netdev, rxlen + 2 + 8); 508 - if (!skb) { 509 - /* todo - dump frame and move on */ 506 + if (rxlen > 4) { 507 + unsigned int rxalign; 508 + 509 + rxlen -= 4; 510 + rxalign = ALIGN(rxlen, 4); 511 + skb = netdev_alloc_skb_ip_align(ks->netdev, rxalign); 512 + if (skb) { 513 + 514 + /* 4 bytes of status header + 4 bytes of 515 + * garbage: we put them before ethernet 516 + * header, so that they are copied, 517 + * but ignored. 518 + */ 519 + 520 + rxpkt = skb_put(skb, rxlen) - 8; 521 + 522 + ks8851_rdfifo(ks, rxpkt, rxalign + 8); 523 + 524 + if (netif_msg_pktdata(ks)) 525 + ks8851_dbg_dumpkkt(ks, rxpkt); 526 + 527 + skb->protocol = eth_type_trans(skb, ks->netdev); 528 + netif_rx(skb); 529 + 530 + ks->netdev->stats.rx_packets++; 531 + ks->netdev->stats.rx_bytes += rxlen; 510 532 } 511 - 512 - /* two bytes to ensure ip is aligned, and four bytes 513 - * for the status header and 4 bytes of garbage */ 514 - skb_reserve(skb, 2 + 4 + 4); 515 - 516 - rxpkt = skb_put(skb, rxlen - 4) - 8; 517 - 518 - /* align the packet length to 4 bytes, and add 4 bytes 519 - * as we're getting the rx status header as well */ 520 - ks8851_rdfifo(ks, rxpkt, ALIGN(rxlen, 4) + 8); 521 - 522 - if (netif_msg_pktdata(ks)) 523 - ks8851_dbg_dumpkkt(ks, rxpkt); 524 - 525 - skb->protocol = eth_type_trans(skb, ks->netdev); 526 - netif_rx(skb); 527 - 528 - ks->netdev->stats.rx_packets++; 529 - ks->netdev->stats.rx_bytes += rxlen - 4; 530 533 } 531 534 532 535 ks8851_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr);