All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] percpu_counter: Use helper macro abs()
@ 2020-09-27 12:27 Miaohe Lin
  0 siblings, 0 replies; only message in thread
From: Miaohe Lin @ 2020-09-27 12:27 UTC (permalink / raw)
  To: akpm, feng.tang; +Cc: linux-kernel, linmiaohe

Use helper macro abs() to simplify the "x >= t || x <= -t" cmp.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 lib/percpu_counter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index a2345de90e93..35aba0bd2bed 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -85,7 +85,7 @@ void percpu_counter_add_batch(struct percpu_counter *fbc, s64 amount, s32 batch)
 
 	preempt_disable();
 	count = __this_cpu_read(*fbc->counters) + amount;
-	if (count >= batch || count <= -batch) {
+	if (abs(count) >= batch) {
 		unsigned long flags;
 		raw_spin_lock_irqsave(&fbc->lock, flags);
 		fbc->count += count;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-27 12:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-27 12:27 [PATCH] percpu_counter: Use helper macro abs() Miaohe Lin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.