Skip to content

Commit

Permalink
cxgb4: smt: Add lock for atomic_dec_and_test
Browse files Browse the repository at this point in the history
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 <hslester96@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Chuhong Yuan authored and David S. Miller committed Aug 9, 2019
1 parent e858ef1 commit 4a8937b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/net/ethernet/chelsio/cxgb4/smt.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,9 @@ static struct smt_entry *find_or_alloc_smte(struct smt_data *s, u8 *smac)

static void t4_smte_free(struct smt_entry *e)
{
spin_lock_bh(&e->lock);
if (atomic_read(&e->refcnt) == 0) { /* hasn't been recycled */
e->state = SMT_STATE_UNUSED;
}
spin_unlock_bh(&e->lock);
}

/**
Expand All @@ -111,8 +109,10 @@ static void t4_smte_free(struct smt_entry *e)
*/
void cxgb4_smt_release(struct smt_entry *e)
{
spin_lock_bh(&e->lock);
if (atomic_dec_and_test(&e->refcnt))
t4_smte_free(e);
spin_unlock_bh(&e->lock);
}
EXPORT_SYMBOL(cxgb4_smt_release);

Expand Down

0 comments on commit 4a8937b

Please sign in to comment.