cfg80211: track time using boottime
authorArnd Bergmann <arnd@arndb.de>
Mon, 18 Jun 2018 15:11:14 +0000 (17:11 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Fri, 29 Jun 2018 07:49:28 +0000 (09:49 +0200)
The cfg80211 layer uses get_seconds() to read the current time
in its supend handling. 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 cfg80211
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>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/wireless/core.h
net/wireless/sysfs.c

index 63eb1b5fdd04561169618ca30110aea5225d92cc..7f52ef56932035fe0d0a503128a9e24f88c0dd22 100644 (file)
@@ -76,7 +76,7 @@ struct cfg80211_registered_device {
        struct cfg80211_scan_request *scan_req; /* protected by RTNL */
        struct sk_buff *scan_msg;
        struct list_head sched_scan_req_list;
-       unsigned long suspend_at;
+       time64_t suspend_at;
        struct work_struct scan_done_wk;
 
        struct genl_info *cur_cmd_info;
index 570a2b67ca1036796cc5021a0f0ce546811a4e6f..6ab32f6a19616e0825691ddfa684105b00f00c2c 100644 (file)
@@ -102,7 +102,7 @@ static int wiphy_suspend(struct device *dev)
        struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
        int ret = 0;
 
-       rdev->suspend_at = get_seconds();
+       rdev->suspend_at = ktime_get_boottime_seconds();
 
        rtnl_lock();
        if (rdev->wiphy.registered) {
@@ -130,7 +130,7 @@ static int wiphy_resume(struct device *dev)
        int ret = 0;
 
        /* Age scan results with time spent in suspend */
-       cfg80211_bss_age(rdev, get_seconds() - rdev->suspend_at);
+       cfg80211_bss_age(rdev, ktime_get_boottime_seconds() - rdev->suspend_at);
 
        rtnl_lock();
        if (rdev->wiphy.registered && rdev->ops->resume)