audit: use time_after to compare time
authorwuchi <wuchi.zero@gmail.com>
Mon, 29 Aug 2022 16:26:09 +0000 (00:26 +0800)
committerPaul Moore <paul@paul-moore.com>
Mon, 29 Aug 2022 23:47:03 +0000 (19:47 -0400)
Using time_{*} macro to compare time is better

Signed-off-by: wuchi <wuchi.zero@gmail.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
kernel/audit.c

index a75978ae38ad7238a6565d3c902009d7bd802c98..9bc0b0301198c170ef794a02c95cfb5c5f576f73 100644 (file)
@@ -321,7 +321,6 @@ static inline int audit_rate_check(void)
        static DEFINE_SPINLOCK(lock);
        unsigned long           flags;
        unsigned long           now;
-       unsigned long           elapsed;
        int                     retval     = 0;
 
        if (!audit_rate_limit) return 1;
@@ -330,9 +329,8 @@ static inline int audit_rate_check(void)
        if (++messages < audit_rate_limit) {
                retval = 1;
        } else {
-               now     = jiffies;
-               elapsed = now - last_check;
-               if (elapsed > HZ) {
+               now = jiffies;
+               if (time_after(now, last_check + HZ)) {
                        last_check = now;
                        messages   = 0;
                        retval     = 1;
@@ -366,7 +364,7 @@ void audit_log_lost(const char *message)
        if (!print) {
                spin_lock_irqsave(&lock, flags);
                now = jiffies;
-               if (now - last_msg > HZ) {
+               if (time_after(now, last_msg + HZ)) {
                        print = 1;
                        last_msg = now;
                }