Skip to content

Commit 99343cf

Browse files
HoratiuVulturkuba-moo
authored andcommitted
net: lan966x: Fix usage of lan966x->mac_lock when entry is removed
To remove an entry to the MAC table, it is required first to setup the entry and then issue a command for the MAC to forget the entry. So if it happens for two threads to remove simultaneously an entry in MAC table then it would be a race condition. Fix this by using lan966x->mac_lock to protect the HW access. Fixes: e18aba8 ("net: lan966x: add mactable support") Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com> Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 43243bb commit 99343cf

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

drivers/net/ethernet/microchip/lan966x/lan966x_mac.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,13 @@ int lan966x_mac_learn(struct lan966x *lan966x, int port,
119119
return __lan966x_mac_learn(lan966x, port, false, mac, vid, type);
120120
}
121121

122-
int lan966x_mac_forget(struct lan966x *lan966x,
123-
const unsigned char mac[ETH_ALEN],
124-
unsigned int vid,
125-
enum macaccess_entry_type type)
122+
static int lan966x_mac_forget_locked(struct lan966x *lan966x,
123+
const unsigned char mac[ETH_ALEN],
124+
unsigned int vid,
125+
enum macaccess_entry_type type)
126126
{
127+
lockdep_assert_held(&lan966x->mac_lock);
128+
127129
lan966x_mac_select(lan966x, mac, vid);
128130

129131
/* Issue a forget command */
@@ -134,6 +136,20 @@ int lan966x_mac_forget(struct lan966x *lan966x,
134136
return lan966x_mac_wait_for_completion(lan966x);
135137
}
136138

139+
int lan966x_mac_forget(struct lan966x *lan966x,
140+
const unsigned char mac[ETH_ALEN],
141+
unsigned int vid,
142+
enum macaccess_entry_type type)
143+
{
144+
int ret;
145+
146+
spin_lock(&lan966x->mac_lock);
147+
ret = lan966x_mac_forget_locked(lan966x, mac, vid, type);
148+
spin_unlock(&lan966x->mac_lock);
149+
150+
return ret;
151+
}
152+
137153
int lan966x_mac_cpu_learn(struct lan966x *lan966x, const char *addr, u16 vid)
138154
{
139155
return lan966x_mac_learn(lan966x, PGID_CPU, addr, vid, ENTRYTYPE_LOCKED);

0 commit comments

Comments
 (0)