drivers/net: amd: Convert timers to use timer_setup()
authorKees Cook <keescook@chromium.org>
Fri, 27 Oct 2017 05:54:38 +0000 (22:54 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 28 Oct 2017 10:09:49 +0000 (19:09 +0900)
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Allen Pais <allen.lkml@gmail.com>
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/amd/a2065.c
drivers/net/ethernet/amd/am79c961a.c
drivers/net/ethernet/amd/am79c961a.h
drivers/net/ethernet/amd/declance.c
drivers/net/ethernet/amd/pcnet32.c
drivers/net/ethernet/amd/sunlance.c
drivers/net/ethernet/amd/xgbe/xgbe-drv.c

index 998d30e050a63ecb200a502e62a12794353b1bf7..212fe72a190bcca65e9b5e3c57c97110b2bd7662 100644 (file)
@@ -123,6 +123,7 @@ struct lance_private {
        int burst_sizes;              /* ledma SBus burst sizes */
 #endif
        struct timer_list         multicast_timer;
+       struct net_device         *dev;
 };
 
 #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
@@ -638,6 +639,13 @@ static void lance_set_multicast(struct net_device *dev)
        netif_wake_queue(dev);
 }
 
+static void lance_set_multicast_retry(struct timer_list *t)
+{
+       struct lance_private *lp = from_timer(lp, t, multicast_timer);
+
+       lance_set_multicast(lp->dev);
+}
+
 static int a2065_init_one(struct zorro_dev *z,
                          const struct zorro_device_id *ent);
 static void a2065_remove_one(struct zorro_dev *z);
@@ -728,14 +736,13 @@ static int a2065_init_one(struct zorro_dev *z,
        priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
        priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
        priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
+       priv->dev = dev;
 
        dev->netdev_ops = &lance_netdev_ops;
        dev->watchdog_timeo = 5*HZ;
        dev->dma = 0;
 
-       setup_timer(&priv->multicast_timer,
-                   (void(*)(unsigned long))lance_set_multicast,
-                   (unsigned long)dev);
+       timer_setup(&priv->multicast_timer, lance_set_multicast_retry, 0);
 
        err = register_netdev(dev);
        if (err) {
index 0612dbee00d2037e9e1a4c85107048901d01dfae..01d132c02ff9039e31bcc9c4e10b1cbaeb315150 100644 (file)
@@ -302,10 +302,10 @@ am79c961_init_for_open(struct net_device *dev)
        write_rreg (dev->base_addr, CSR0, CSR0_IENA|CSR0_STRT);
 }
 
-static void am79c961_timer(unsigned long data)
+static void am79c961_timer(struct timer_list *t)
 {
-       struct net_device *dev = (struct net_device *)data;
-       struct dev_priv *priv = netdev_priv(dev);
+       struct dev_priv *priv = from_timer(priv, t, timer);
+       struct net_device *dev = priv->dev;
        unsigned int lnkstat, carrier;
        unsigned long flags;
 
@@ -728,7 +728,8 @@ static int am79c961_probe(struct platform_device *pdev)
        am79c961_banner();
 
        spin_lock_init(&priv->chip_lock);
-       setup_timer(&priv->timer, am79c961_timer, (unsigned long)dev);
+       priv->dev = dev;
+       timer_setup(&priv->timer, am79c961_timer, 0);
 
        if (am79c961_hw_init(dev))
                goto release;
index 9f384b79507bd9e43cf377eeeb3e7b26c5324664..fc5088c707316bd07f79b0440d7f4906ebbfbc85 100644 (file)
@@ -140,6 +140,7 @@ struct dev_priv {
     unsigned long      txhdr;
     spinlock_t         chip_lock;
     struct timer_list  timer;
+    struct net_device   *dev;
 };
 
 #endif
index 9bdf81c2cd00c1e504131966ebc8c0664fa9d093..116997a8b5930600f57f330b140785f2acd411ad 100644 (file)
@@ -260,6 +260,7 @@ struct lance_private {
        unsigned short busmaster_regval;
 
        struct timer_list       multicast_timer;
+       struct net_device       *dev;
 
        /* Pointers to the ring buffers as seen from the CPU */
        char *rx_buf_ptr_cpu[RX_RING_SIZE];
@@ -1000,9 +1001,10 @@ static void lance_set_multicast(struct net_device *dev)
        netif_wake_queue(dev);
 }
 
-static void lance_set_multicast_retry(unsigned long _opaque)
+static void lance_set_multicast_retry(struct timer_list *t)
 {
-       struct net_device *dev = (struct net_device *) _opaque;
+       struct lance_private *lp = from_timer(lp, t, multicast_timer);
+       struct net_device *dev = lp->dev;
 
        lance_set_multicast(dev);
 }
@@ -1246,8 +1248,8 @@ static int dec_lance_probe(struct device *bdev, const int type)
         * can occur from interrupts (ex. IPv6).  So we
         * use a timer to try again later when necessary. -DaveM
         */
-       setup_timer(&lp->multicast_timer, lance_set_multicast_retry,
-                   (unsigned long)dev);
+       lp->dev = dev;
+       timer_setup(&lp->multicast_timer, lance_set_multicast_retry, 0);
 
 
        ret = register_netdev(dev);
index e4615365401646ad94f1c5d389bfcfbef168a417..a561705f232cd89dbf26c8907a7de31591907a50 100644 (file)
@@ -321,7 +321,7 @@ static struct net_device_stats *pcnet32_get_stats(struct net_device *);
 static void pcnet32_load_multicast(struct net_device *dev);
 static void pcnet32_set_multicast_list(struct net_device *);
 static int pcnet32_ioctl(struct net_device *, struct ifreq *, int);
-static void pcnet32_watchdog(struct net_device *);
+static void pcnet32_watchdog(struct timer_list *);
 static int mdio_read(struct net_device *dev, int phy_id, int reg_num);
 static void mdio_write(struct net_device *dev, int phy_id, int reg_num,
                       int val);
@@ -1970,8 +1970,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
                        lp->options |= PCNET32_PORT_MII;
        }
 
-       setup_timer(&lp->watchdog_timer, (void *)&pcnet32_watchdog,
-                   (unsigned long)dev);
+       timer_setup(&lp->watchdog_timer, pcnet32_watchdog, 0);
 
        /* The PCNET32-specific entries in the device structure. */
        dev->netdev_ops = &pcnet32_netdev_ops;
@@ -2901,9 +2900,10 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
  * Could possibly be changed to use mii_check_media instead.
  */
 
-static void pcnet32_watchdog(struct net_device *dev)
+static void pcnet32_watchdog(struct timer_list *t)
 {
-       struct pcnet32_private *lp = netdev_priv(dev);
+       struct pcnet32_private *lp = from_timer(lp, t, watchdog_timer);
+       struct net_device *dev = lp->dev;
        unsigned long flags;
 
        /* Print the link status if it has changed */
index 0183ffb9d3ba24a4cc015e0b11affc2654ec9b4e..cdd7a611479b27f4c59b15bffc42a73a9a7229ee 100644 (file)
@@ -1248,9 +1248,10 @@ static void lance_set_multicast(struct net_device *dev)
        netif_wake_queue(dev);
 }
 
-static void lance_set_multicast_retry(unsigned long _opaque)
+static void lance_set_multicast_retry(struct timer_list *t)
 {
-       struct net_device *dev = (struct net_device *) _opaque;
+       struct lance_private *lp = from_timer(lp, t, multicast_timer);
+       struct net_device *dev = lp->dev;
 
        lance_set_multicast(dev);
 }
@@ -1459,8 +1460,7 @@ no_link_test:
         * can occur from interrupts (ex. IPv6).  So we
         * use a timer to try again later when necessary. -DaveM
         */
-       setup_timer(&lp->multicast_timer, lance_set_multicast_retry,
-                   (unsigned long)dev);
+       timer_setup(&lp->multicast_timer, lance_set_multicast_retry, 0);
 
        if (register_netdev(dev)) {
                printk(KERN_ERR "SunLance: Cannot register device.\n");
index 608693d11bd7f7f2a7b6c3eeaeaf20dbacf859e4..3d53153ce7515b5992eb9e1e96ff5157db2c6319 100644 (file)
@@ -642,9 +642,9 @@ static irqreturn_t xgbe_dma_isr(int irq, void *data)
        return IRQ_HANDLED;
 }
 
-static void xgbe_tx_timer(unsigned long data)
+static void xgbe_tx_timer(struct timer_list *t)
 {
-       struct xgbe_channel *channel = (struct xgbe_channel *)data;
+       struct xgbe_channel *channel = from_timer(channel, t, tx_timer);
        struct xgbe_prv_data *pdata = channel->pdata;
        struct napi_struct *napi;
 
@@ -680,9 +680,9 @@ static void xgbe_service(struct work_struct *work)
        pdata->phy_if.phy_status(pdata);
 }
 
-static void xgbe_service_timer(unsigned long data)
+static void xgbe_service_timer(struct timer_list *t)
 {
-       struct xgbe_prv_data *pdata = (struct xgbe_prv_data *)data;
+       struct xgbe_prv_data *pdata = from_timer(pdata, t, service_timer);
 
        queue_work(pdata->dev_workqueue, &pdata->service_work);
 
@@ -694,16 +694,14 @@ static void xgbe_init_timers(struct xgbe_prv_data *pdata)
        struct xgbe_channel *channel;
        unsigned int i;
 
-       setup_timer(&pdata->service_timer, xgbe_service_timer,
-                   (unsigned long)pdata);
+       timer_setup(&pdata->service_timer, xgbe_service_timer, 0);
 
        for (i = 0; i < pdata->channel_count; i++) {
                channel = pdata->channel[i];
                if (!channel->tx_ring)
                        break;
 
-               setup_timer(&channel->tx_timer, xgbe_tx_timer,
-                           (unsigned long)channel);
+               timer_setup(&channel->tx_timer, xgbe_tx_timer, 0);
        }
 }