Skip to content

Commit

Permalink
audit: use time_after to compare time
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ChiWu-Zero authored and pcmoore committed Aug 29, 2022
1 parent c3f3ea8 commit 501e4bb
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions kernel/audit.c
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 501e4bb

Please sign in to comment.