Skip to content

Commit e48b9b2

Browse files
kaberdavem330
authored andcommitted
[NETFILTER]: nfnetlink_queue: avoid unnecessary atomic operation
The sequence counter doesn't need to be an atomic_t, just move the increment inside the locked section. Signed-off-by: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f9c6399 commit e48b9b2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

net/netfilter/nfnetlink_queue.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct nfqnl_instance {
5656
unsigned int queue_dropped;
5757
unsigned int queue_user_dropped;
5858

59-
atomic_t id_sequence; /* 'sequence' of pkt ids */
59+
unsigned int id_sequence; /* 'sequence' of pkt ids */
6060

6161
u_int16_t queue_num; /* number of this queue */
6262
u_int8_t copy_mode;
@@ -139,7 +139,6 @@ instance_create(u_int16_t queue_num, int pid)
139139
inst->queue_maxlen = NFQNL_QMAX_DEFAULT;
140140
inst->copy_range = 0xfffff;
141141
inst->copy_mode = NFQNL_COPY_NONE;
142-
atomic_set(&inst->id_sequence, 0);
143142
/* needs to be two, since we _put() after creation */
144143
atomic_set(&inst->use, 2);
145144
spin_lock_init(&inst->lock);
@@ -340,6 +339,8 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
340339
return NULL;
341340
}
342341

342+
entry->id = queue->id_sequence++;
343+
343344
spin_unlock_bh(&queue->lock);
344345

345346
skb = alloc_skb(size, GFP_ATOMIC);
@@ -496,8 +497,6 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
496497
goto err_out_put;
497498
}
498499

499-
entry->id = atomic_inc_return(&queue->id_sequence);
500-
501500
nskb = nfqnl_build_packet_message(queue, entry, &status);
502501
if (nskb == NULL)
503502
goto err_out_put;
@@ -948,7 +947,7 @@ static int seq_show(struct seq_file *s, void *v)
948947
inst->peer_pid, inst->queue_total,
949948
inst->copy_mode, inst->copy_range,
950949
inst->queue_dropped, inst->queue_user_dropped,
951-
atomic_read(&inst->id_sequence),
950+
inst->id_sequence,
952951
atomic_read(&inst->use));
953952
}
954953

0 commit comments

Comments
 (0)