From 0150539f7780d599ea73c9d897628b5b8fee7e58 Mon Sep 17 00:00:00 2001 From: Ioana Radulescu Date: Wed, 28 Aug 2013 18:24:34 +0300 Subject: dpaa_eth: Fix kernel crash with timestamp support on Recent changes in the driver moved the allocation of the skb on Rx past the point where the timestamp/1588 code used the skb. Reorder a bit the code to avoid NULL pointer dereferencing. Signed-off-by: Ioana Radulescu Change-Id: I09929c13bc88048be77c8678c1fb9956fec41039 Reviewed-on: http://git.am.freescale.net:8181/4443 Tested-by: Review Code-CDREVIEW Reviewed-by: Bucur Madalin-Cristian-B32716 Reviewed-by: Sovaiala Cristian-Constantin-B39531 Reviewed-by: Rivera Jose-B46482 diff --git a/drivers/net/ethernet/freescale/dpa/dpaa_eth_sg.c b/drivers/net/ethernet/freescale/dpa/dpaa_eth_sg.c index f93c346..af5a08b 100644 --- a/drivers/net/ethernet/freescale/dpa/dpaa_eth_sg.c +++ b/drivers/net/ethernet/freescale/dpa/dpaa_eth_sg.c @@ -265,17 +265,17 @@ static struct sk_buff *__hot contig_fd_to_skb(const struct dpa_priv_s *priv, vaddr = phys_to_virt(addr); + /* Build the skb and adjust data and tail pointers */ + skb = build_skb(vaddr, dpa_bp->size + DPA_SKB_TAILROOM); + if (unlikely(!skb)) + return NULL; + /* do we need the timestamp for bad frames? */ #ifdef CONFIG_FSL_DPAA_1588 if (priv->tsu && priv->tsu->valid && priv->tsu->hwts_rx_en_ioctl) dpa_ptp_store_rxstamp(priv, skb, vaddr); #endif - /* Build the skb and adjust data and tail pointers */ - skb = build_skb(vaddr, dpa_bp->size + DPA_SKB_TAILROOM); - if (unlikely(!skb)) - return NULL; - /* Make sure forwarded skbs will have enough space on Tx, * if extra headers are added. */ @@ -318,15 +318,6 @@ static struct sk_buff *__hot sg_fd_to_skb(const struct dpa_priv_s *priv, int *count_ptr; vaddr = phys_to_virt(addr); -#ifdef CONFIG_FSL_DPAA_1588 - if (priv->tsu && priv->tsu->valid && priv->tsu->hwts_rx_en_ioctl) - dpa_ptp_store_rxstamp(priv, skb, vaddr); -#endif - -#ifdef CONFIG_FSL_DPAA_TS - if (priv->ts_rx_en) - dpa_get_ts(priv, RX, skb_hwtstamps(skb), vaddr); -#endif /* CONFIG_FSL_DPAA_TS */ /* Iterate through the SGT entries and add data buffers to the skb */ sgt = vaddr + dpa_fd_offset(fd); @@ -360,6 +351,17 @@ static struct sk_buff *__hot sg_fd_to_skb(const struct dpa_priv_s *priv, */ return NULL; +#ifdef CONFIG_FSL_DPAA_1588 + if (priv->tsu && priv->tsu->valid && + priv->tsu->hwts_rx_en_ioctl) + dpa_ptp_store_rxstamp(priv, skb, vaddr); +#endif + +#ifdef CONFIG_FSL_DPAA_TS + if (priv->ts_rx_en) + dpa_get_ts(priv, RX, skb_hwtstamps(skb), vaddr); +#endif /* CONFIG_FSL_DPAA_TS */ + dma_unmap_single(dpa_bp->dev, sg_addr, dpa_bp->size, DMA_BIDIRECTIONAL); -- cgit v0.10.2