Skip to content

Commit 4a8937b

Browse files
WillLesterdavem330
authored andcommitted
cxgb4: smt: Add lock for atomic_dec_and_test
The atomic_dec_and_test() is not safe because it is outside of locks. Move the locks of t4_smte_free() to its caller, cxgb4_smt_release() to protect the atomic decrement. Fixes: 3bdb376 ("cxgb4: introduce SMT ops to prepare for SMAC rewrite support") Signed-off-by: Chuhong Yuan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e858ef1 commit 4a8937b

File tree

1 file changed

+2
-2
lines changed
  • drivers/net/ethernet/chelsio/cxgb4

1 file changed

+2
-2
lines changed

drivers/net/ethernet/chelsio/cxgb4/smt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ static struct smt_entry *find_or_alloc_smte(struct smt_data *s, u8 *smac)
9797

9898
static void t4_smte_free(struct smt_entry *e)
9999
{
100-
spin_lock_bh(&e->lock);
101100
if (atomic_read(&e->refcnt) == 0) { /* hasn't been recycled */
102101
e->state = SMT_STATE_UNUSED;
103102
}
104-
spin_unlock_bh(&e->lock);
105103
}
106104

107105
/**
@@ -111,8 +109,10 @@ static void t4_smte_free(struct smt_entry *e)
111109
*/
112110
void cxgb4_smt_release(struct smt_entry *e)
113111
{
112+
spin_lock_bh(&e->lock);
114113
if (atomic_dec_and_test(&e->refcnt))
115114
t4_smte_free(e);
115+
spin_unlock_bh(&e->lock);
116116
}
117117
EXPORT_SYMBOL(cxgb4_smt_release);
118118

0 commit comments

Comments
 (0)