* [PATCH 1/2] cxgb4: smt: Add lock for atomic_dec_and_test
@ 2019-08-06 2:58 Chuhong Yuan
2019-08-09 1:12 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Chuhong Yuan @ 2019-08-06 2:58 UTC (permalink / raw)
Cc: Vishal Kulkarni, David S . Miller, netdev, linux-kernel, Chuhong Yuan
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: 3bdb376e6944 ("cxgb4: introduce SMT ops to prepare for SMAC rewrite support")
Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
drivers/net/ethernet/chelsio/cxgb4/smt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/chelsio/cxgb4/smt.c b/drivers/net/ethernet/chelsio/cxgb4/smt.c
index eaf1fb74689c..d6e84c8b5554 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/smt.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/smt.c
@@ -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);
}
/**
@@ -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);
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/2] cxgb4: smt: Add lock for atomic_dec_and_test
2019-08-06 2:58 [PATCH 1/2] cxgb4: smt: Add lock for atomic_dec_and_test Chuhong Yuan
@ 2019-08-09 1:12 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-08-09 1:12 UTC (permalink / raw)
To: hslester96; +Cc: vishal, netdev, linux-kernel
From: Chuhong Yuan <hslester96@gmail.com>
Date: Tue, 6 Aug 2019 10:58:46 +0800
> 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: 3bdb376e6944 ("cxgb4: introduce SMT ops to prepare for SMAC rewrite support")
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
Applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-08-09 1:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-06 2:58 [PATCH 1/2] cxgb4: smt: Add lock for atomic_dec_and_test Chuhong Yuan
2019-08-09 1:12 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).