aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorshemminger@osdl.org <shemminger@osdl.org>2006-08-28 13:00:46 -0400
committerJeff Garzik <jeff@garzik.org>2006-08-29 17:18:29 -0400
commit497d7c8681dec5084b2e79193c2aaeddc789477f (patch)
treecf0063f49e00f8eda26d95cceef7696fdcf15808 /drivers/net
parentfba5008cda606488cf42b60de60b4414cc2276ad (diff)
[PATCH] sky2: use netdev_alloc_skb
Use netdev_alloc_skb for buffer allocation to allow for headroom. This prevents bugs in code paths that assume extra space at the front and makes sky2 behave like other drivers. Signed-off-by: Stephen Hemminger <shemminger@osdl.org> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/sky2.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index 67ebc05d9d19..8d541bbc5e64 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -954,14 +954,16 @@ static void sky2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
954/* 954/*
955 * It appears the hardware has a bug in the FIFO logic that 955 * It appears the hardware has a bug in the FIFO logic that
956 * cause it to hang if the FIFO gets overrun and the receive buffer 956 * cause it to hang if the FIFO gets overrun and the receive buffer
957 * is not aligned. ALso alloc_skb() won't align properly if slab 957 * is not 64 byte aligned. The buffer returned from netdev_alloc_skb is
958 * debugging is enabled. 958 * aligned except if slab debugging is enabled.
959 */ 959 */
960static inline struct sk_buff *sky2_alloc_skb(unsigned int size, gfp_t gfp_mask) 960static inline struct sk_buff *sky2_alloc_skb(struct net_device *dev,
961 unsigned int length,
962 gfp_t gfp_mask)
961{ 963{
962 struct sk_buff *skb; 964 struct sk_buff *skb;
963 965
964 skb = alloc_skb(size + RX_SKB_ALIGN, gfp_mask); 966 skb = __netdev_alloc_skb(dev, length + RX_SKB_ALIGN, gfp_mask);
965 if (likely(skb)) { 967 if (likely(skb)) {
966 unsigned long p = (unsigned long) skb->data; 968 unsigned long p = (unsigned long) skb->data;
967 skb_reserve(skb, ALIGN(p, RX_SKB_ALIGN) - p); 969 skb_reserve(skb, ALIGN(p, RX_SKB_ALIGN) - p);
@@ -997,7 +999,8 @@ static int sky2_rx_start(struct sky2_port *sky2)
997 for (i = 0; i < sky2->rx_pending; i++) { 999 for (i = 0; i < sky2->rx_pending; i++) {
998 struct ring_info *re = sky2->rx_ring + i; 1000 struct ring_info *re = sky2->rx_ring + i;
999 1001
1000 re->skb = sky2_alloc_skb(sky2->rx_bufsize, GFP_KERNEL); 1002 re->skb = sky2_alloc_skb(sky2->netdev, sky2->rx_bufsize,
1003 GFP_KERNEL);
1001 if (!re->skb) 1004 if (!re->skb)
1002 goto nomem; 1005 goto nomem;
1003 1006
@@ -1829,15 +1832,16 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
1829 * For small packets or errors, just reuse existing skb. 1832 * For small packets or errors, just reuse existing skb.
1830 * For larger packets, get new buffer. 1833 * For larger packets, get new buffer.
1831 */ 1834 */
1832static struct sk_buff *sky2_receive(struct sky2_port *sky2, 1835static struct sk_buff *sky2_receive(struct net_device *dev,
1833 u16 length, u32 status) 1836 u16 length, u32 status)
1834{ 1837{
1838 struct sky2_port *sky2 = netdev_priv(dev);
1835 struct ring_info *re = sky2->rx_ring + sky2->rx_next; 1839 struct ring_info *re = sky2->rx_ring + sky2->rx_next;
1836 struct sk_buff *skb = NULL; 1840 struct sk_buff *skb = NULL;
1837 1841
1838 if (unlikely(netif_msg_rx_status(sky2))) 1842 if (unlikely(netif_msg_rx_status(sky2)))
1839 printk(KERN_DEBUG PFX "%s: rx slot %u status 0x%x len %d\n", 1843 printk(KERN_DEBUG PFX "%s: rx slot %u status 0x%x len %d\n",
1840 sky2->netdev->name, sky2->rx_next, status, length); 1844 dev->name, sky2->rx_next, status, length);
1841 1845
1842 sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending; 1846 sky2->rx_next = (sky2->rx_next + 1) % sky2->rx_pending;
1843 prefetch(sky2->rx_ring + sky2->rx_next); 1847 prefetch(sky2->rx_ring + sky2->rx_next);
@@ -1848,11 +1852,11 @@ static struct sk_buff *sky2_receive(struct sky2_port *sky2,
1848 if (!(status & GMR_FS_RX_OK)) 1852 if (!(status & GMR_FS_RX_OK))
1849 goto resubmit; 1853 goto resubmit;
1850 1854
1851 if (length > sky2->netdev->mtu + ETH_HLEN) 1855 if (length > dev->mtu + ETH_HLEN)
1852 goto oversize; 1856 goto oversize;
1853 1857
1854 if (length < copybreak) { 1858 if (length < copybreak) {
1855 skb = alloc_skb(length + 2, GFP_ATOMIC); 1859 skb = netdev_alloc_skb(dev, length + 2);
1856 if (!skb) 1860 if (!skb)
1857 goto resubmit; 1861 goto resubmit;
1858 1862
@@ -1867,7 +1871,7 @@ static struct sk_buff *sky2_receive(struct sky2_port *sky2,
1867 } else { 1871 } else {
1868 struct sk_buff *nskb; 1872 struct sk_buff *nskb;
1869 1873
1870 nskb = sky2_alloc_skb(sky2->rx_bufsize, GFP_ATOMIC); 1874 nskb = sky2_alloc_skb(dev, sky2->rx_bufsize, GFP_ATOMIC);
1871 if (!nskb) 1875 if (!nskb)
1872 goto resubmit; 1876 goto resubmit;
1873 1877
@@ -1897,7 +1901,7 @@ error:
1897 1901
1898 if (netif_msg_rx_err(sky2) && net_ratelimit()) 1902 if (netif_msg_rx_err(sky2) && net_ratelimit())
1899 printk(KERN_INFO PFX "%s: rx error, status 0x%x length %d\n", 1903 printk(KERN_INFO PFX "%s: rx error, status 0x%x length %d\n",
1900 sky2->netdev->name, status, length); 1904 dev->name, status, length);
1901 1905
1902 if (status & (GMR_FS_LONG_ERR | GMR_FS_UN_SIZE)) 1906 if (status & (GMR_FS_LONG_ERR | GMR_FS_UN_SIZE))
1903 sky2->net_stats.rx_length_errors++; 1907 sky2->net_stats.rx_length_errors++;
@@ -1951,11 +1955,10 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do)
1951 1955
1952 switch (le->opcode & ~HW_OWNER) { 1956 switch (le->opcode & ~HW_OWNER) {
1953 case OP_RXSTAT: 1957 case OP_RXSTAT:
1954 skb = sky2_receive(sky2, length, status); 1958 skb = sky2_receive(dev, length, status);
1955 if (!skb) 1959 if (!skb)
1956 break; 1960 break;
1957 1961
1958 skb->dev = dev;
1959 skb->protocol = eth_type_trans(skb, dev); 1962 skb->protocol = eth_type_trans(skb, dev);
1960 dev->last_rx = jiffies; 1963 dev->last_rx = jiffies;
1961 1964