Skip to content

Commit 4ffa1d1

Browse files
edumazetdavem330
authored andcommitted
net: adopt try_cmpxchg() in napi_{enable|disable}()
This makes code a bit cleaner. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1462160 commit 4ffa1d1

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

net/core/dev.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6397,19 +6397,16 @@ void napi_disable(struct napi_struct *n)
63976397
might_sleep();
63986398
set_bit(NAPI_STATE_DISABLE, &n->state);
63996399

6400-
for ( ; ; ) {
6401-
val = READ_ONCE(n->state);
6400+
val = READ_ONCE(n->state);
6401+
do {
64026402
if (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) {
64036403
usleep_range(20, 200);
64046404
continue;
64056405
}
64066406

64076407
new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC;
64086408
new &= ~(NAPIF_STATE_THREADED | NAPIF_STATE_PREFER_BUSY_POLL);
6409-
6410-
if (cmpxchg(&n->state, val, new) == val)
6411-
break;
6412-
}
6409+
} while (!try_cmpxchg(&n->state, &val, new));
64136410

64146411
hrtimer_cancel(&n->timer);
64156412

@@ -6426,16 +6423,15 @@ EXPORT_SYMBOL(napi_disable);
64266423
*/
64276424
void napi_enable(struct napi_struct *n)
64286425
{
6429-
unsigned long val, new;
6426+
unsigned long new, val = READ_ONCE(n->state);
64306427

64316428
do {
6432-
val = READ_ONCE(n->state);
64336429
BUG_ON(!test_bit(NAPI_STATE_SCHED, &val));
64346430

64356431
new = val & ~(NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC);
64366432
if (n->dev->threaded && n->thread)
64376433
new |= NAPIF_STATE_THREADED;
6438-
} while (cmpxchg(&n->state, val, new) != val);
6434+
} while (!try_cmpxchg(&n->state, &val, new));
64396435
}
64406436
EXPORT_SYMBOL(napi_enable);
64416437

0 commit comments

Comments
 (0)