]> Pileus Git - ~andy/linux/blobdiff - drivers/net/ethernet/broadcom/tg3.c
tg3: Validate hwtstamp_config completely before applying it
[~andy/linux] / drivers / net / ethernet / broadcom / tg3.c
index 819d87c281bfba633d19628e47237bdf84cf03d3..a9e068423ba0651414cc0c5b23f0eda6937a6c23 100644 (file)
@@ -6862,12 +6862,6 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
                        pci_unmap_single(tp->pdev, dma_addr, skb_size,
                                         PCI_DMA_FROMDEVICE);
 
-                       skb = build_skb(data, frag_size);
-                       if (!skb) {
-                               tg3_frag_free(frag_size != 0, data);
-                               goto drop_it_no_recycle;
-                       }
-                       skb_reserve(skb, TG3_RX_OFFSET(tp));
                        /* Ensure that the update to the data happens
                         * after the usage of the old DMA mapping.
                         */
@@ -6875,6 +6869,12 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
 
                        ri->data = NULL;
 
+                       skb = build_skb(data, frag_size);
+                       if (!skb) {
+                               tg3_frag_free(frag_size != 0, data);
+                               goto drop_it_no_recycle;
+                       }
+                       skb_reserve(skb, TG3_RX_OFFSET(tp));
                } else {
                        tg3_recycle_rx(tnapi, tpr, opaque_key,
                                       desc_idx, *post_ptr);
@@ -13618,16 +13618,9 @@ static int tg3_hwtstamp_ioctl(struct net_device *dev,
        if (stmpconf.flags)
                return -EINVAL;
 
-       switch (stmpconf.tx_type) {
-       case HWTSTAMP_TX_ON:
-               tg3_flag_set(tp, TX_TSTAMP_EN);
-               break;
-       case HWTSTAMP_TX_OFF:
-               tg3_flag_clear(tp, TX_TSTAMP_EN);
-               break;
-       default:
+       if (stmpconf.tx_type != HWTSTAMP_TX_ON &&
+           stmpconf.tx_type != HWTSTAMP_TX_OFF)
                return -ERANGE;
-       }
 
        switch (stmpconf.rx_filter) {
        case HWTSTAMP_FILTER_NONE:
@@ -13689,6 +13682,11 @@ static int tg3_hwtstamp_ioctl(struct net_device *dev,
                tw32(TG3_RX_PTP_CTL,
                     tp->rxptpctl | TG3_RX_PTP_CTL_HWTS_INTERLOCK);
 
+       if (stmpconf.tx_type == HWTSTAMP_TX_ON)
+               tg3_flag_set(tp, TX_TSTAMP_EN);
+       else
+               tg3_flag_clear(tp, TX_TSTAMP_EN);
+
        return copy_to_user(ifr->ifr_data, &stmpconf, sizeof(stmpconf)) ?
                -EFAULT : 0;
 }