Re: [syzbot] Re: [syzbot] [net?] possible deadlock in team_device_event (3)

syzbot
2024-08-01T09:57:43Z

drivers/net/team/team_core.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/net/team/team_core.c b/drivers/net/team/team_core.c
index ab1935a4aa2c..44c709015007 100644
--- a/drivers/net/team/team_core.c
+++ b/drivers/net/team/team_core.c
@@ -2946,10 +2946,22 @@ static void __team_port_change_port_removed(struct team_port *port)
static void team_port_change_check(struct team_port *port, bool linkup)
{
struct team *team = port->team;
+ bool flag = true;

- mutex_lock(&team->lock);
+ if (mutex_is_locked(&team->lock)){
+ unsigned owner, curr = (unsigned long)current;
+ owner = atomic_long_read(&team->lock.owner);
+ if (owner != curr)
+ mutex_lock(&team->lock);
+ else
+ flag = false;
+ }
+ else{
+ mutex_lock(&team->lock);
+ }
__team_port_change_check(port, linkup);
- mutex_unlock(&team->lock);
+ if (flag)
+ mutex_unlock(&team->lock);
}

--