ipw2x00: track time using boottime
authorArnd Bergmann <arnd@arndb.de>
Mon, 18 Jun 2018 15:11:16 +0000 (17:11 +0200)
committerKalle Valo <kvalo@codeaurora.org>
Wed, 27 Jun 2018 16:10:25 +0000 (19:10 +0300)
The ipw2x00 driver family uses get_seconds() to read the current time
for various purposes. This function is deprecated because of the 32-bit
time_t overflow, and it can cause unexpected behavior when the time
changes due to settimeofday() calls or leap second updates.

In many cases, we want to use monotonic time instead, however ipw2x00
explicitly tracks the time spent in suspend, so this changes the
driver over to use ktime_get_boottime_seconds(), which is slightly
slower, but not used in a fastpath here.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Stanislav Yakovlev <stas.yakovlev@gmail.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/intel/ipw2x00/ipw2100.c
drivers/net/wireless/intel/ipw2x00/ipw2100.h
drivers/net/wireless/intel/ipw2x00/ipw2200.c
drivers/net/wireless/intel/ipw2x00/ipw2200.h

index b8fd3cc90634d116af789caeae309444fffae42b..1ad83ef5f202e0f2d7ae6f1919d2b11aa21b52b2 100644 (file)
@@ -692,7 +692,7 @@ static void printk_buf(int level, const u8 * data, u32 len)
 
 static void schedule_reset(struct ipw2100_priv *priv)
 {
-       unsigned long now = get_seconds();
+       time64_t now = ktime_get_boottime_seconds();
 
        /* If we haven't received a reset request within the backoff period,
         * then we can reset the backoff interval so this reset occurs
@@ -701,10 +701,10 @@ static void schedule_reset(struct ipw2100_priv *priv)
            (now - priv->last_reset > priv->reset_backoff))
                priv->reset_backoff = 0;
 
-       priv->last_reset = get_seconds();
+       priv->last_reset = now;
 
        if (!(priv->status & STATUS_RESET_PENDING)) {
-               IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n",
+               IPW_DEBUG_INFO("%s: Scheduling firmware restart (%llds).\n",
                               priv->net_dev->name, priv->reset_backoff);
                netif_carrier_off(priv->net_dev);
                netif_stop_queue(priv->net_dev);
@@ -2079,7 +2079,7 @@ static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
        memcpy(priv->bssid, bssid, ETH_ALEN);
 
        priv->status |= STATUS_ASSOCIATING;
-       priv->connect_start = get_seconds();
+       priv->connect_start = ktime_get_boottime_seconds();
 
        schedule_delayed_work(&priv->wx_event_work, HZ / 10);
 }
@@ -4070,8 +4070,8 @@ static ssize_t show_internals(struct device *d, struct device_attribute *attr,
 #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" y "\n", priv-> x)
 
        if (priv->status & STATUS_ASSOCIATED)
-               len += sprintf(buf + len, "connected: %lu\n",
-                              get_seconds() - priv->connect_start);
+               len += sprintf(buf + len, "connected: %llu\n",
+                              ktime_get_boottime_seconds() - priv->connect_start);
        else
                len += sprintf(buf + len, "not connected\n");
 
@@ -4108,7 +4108,7 @@ static ssize_t show_internals(struct device *d, struct device_attribute *attr,
        DUMP_VAR(txq_stat.lo, "d");
 
        DUMP_VAR(ieee->scans, "d");
-       DUMP_VAR(reset_backoff, "d");
+       DUMP_VAR(reset_backoff, "lld");
 
        return len;
 }
@@ -6437,7 +6437,7 @@ static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
        pci_disable_device(pci_dev);
        pci_set_power_state(pci_dev, PCI_D3hot);
 
-       priv->suspend_at = get_seconds();
+       priv->suspend_at = ktime_get_boottime_seconds();
 
        mutex_unlock(&priv->action_mutex);
 
@@ -6482,7 +6482,7 @@ static int ipw2100_resume(struct pci_dev *pci_dev)
         * the queue of needed */
        netif_device_attach(dev);
 
-       priv->suspend_time = get_seconds() - priv->suspend_at;
+       priv->suspend_time = ktime_get_boottime_seconds() - priv->suspend_at;
 
        /* Bring the device back up */
        if (!(priv->status & STATUS_RF_KILL_SW))
index ce3e35f6b60f485faec5b0a9ba2ba9b35a435f8c..8c11c7fa2eefe2bb3c1108a8655272aad6b2d26e 100644 (file)
@@ -491,7 +491,7 @@ struct ipw2100_priv {
 
        /* Statistics */
        int resets;
-       int reset_backoff;
+       time64_t reset_backoff;
 
        /* Context */
        u8 essid[IW_ESSID_MAX_SIZE];
@@ -500,8 +500,8 @@ struct ipw2100_priv {
        u8 channel;
        int last_mode;
 
-       unsigned long connect_start;
-       unsigned long last_reset;
+       time64_t connect_start;
+       time64_t last_reset;
 
        u32 channel_mask;
        u32 fatal_error;
@@ -581,9 +581,9 @@ struct ipw2100_priv {
 
        int user_requested_scan;
 
-       /* Track time in suspend */
-       unsigned long suspend_at;
-       unsigned long suspend_time;
+       /* Track time in suspend, using CLOCK_BOOTTIME */
+       time64_t suspend_at;
+       time64_t suspend_time;
 
        u32 interrupts;
        int tx_interrupts;
index 62140109d2acc8d533f32bf679d137f6cbb71f58..9644e7b93645f510394b1deb3accf6976fc87a78 100644 (file)
@@ -11888,7 +11888,7 @@ static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
        pci_disable_device(pdev);
        pci_set_power_state(pdev, pci_choose_state(pdev, state));
 
-       priv->suspend_at = get_seconds();
+       priv->suspend_at = ktime_get_boottime_seconds();
 
        return 0;
 }
@@ -11925,7 +11925,7 @@ static int ipw_pci_resume(struct pci_dev *pdev)
         * the queue of needed */
        netif_device_attach(dev);
 
-       priv->suspend_time = get_seconds() - priv->suspend_at;
+       priv->suspend_time = ktime_get_boottime_seconds() - priv->suspend_at;
 
        /* Bring the device back up */
        schedule_work(&priv->up);
index aa301d1eee3cbe50435e48f6fdf5ba84ed7f22d4..f98ab1f71edd9c3d5c2465baf38da56d2b0d9e26 100644 (file)
@@ -1343,9 +1343,9 @@ struct ipw_priv {
 
        s8 tx_power;
 
-       /* Track time in suspend */
-       unsigned long suspend_at;
-       unsigned long suspend_time;
+       /* Track time in suspend using CLOCK_BOOTIME */
+       time64_t suspend_at;
+       time64_t suspend_time;
 
 #ifdef CONFIG_PM
        u32 pm_state[16];