From cf0b4e2ea632fcff023a8be5f61f89aa4fb71f8d Mon Sep 17 00:00:00 2001 From: Chaithanya Garrepalli Date: Sat, 21 Sep 2019 23:01:21 +0530 Subject: [PATCH] qcacmn: avoid deadlock in ast create Fix to avoid race conditions between two locks a) soc->peer_ref_mutex b) soc->ast_lock Right order to for these two locks is to first acquire a) and then b) But in ast create path these locks are acquired in reverse order leading to deadlock. This change helps in fixing deadlock Change-Id: I02f802fa12d5f4e4ae3f584cdffe36c9bf717f84 --- dp/wifi3.0/dp_peer.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dp/wifi3.0/dp_peer.c b/dp/wifi3.0/dp_peer.c index 3d0a12623f53..ca5a122bd37f 100644 --- a/dp/wifi3.0/dp_peer.c +++ b/dp/wifi3.0/dp_peer.c @@ -580,6 +580,14 @@ int dp_peer_add_ast(struct dp_soc *soc, txrx_ast_free_cb cb = NULL; void *cookie = NULL; struct dp_peer *tmp_peer = NULL; + bool is_peer_found = false; + + tmp_peer = dp_peer_find_hash_find(soc, mac_addr, 0, + DP_VDEV_ALL); + if (tmp_peer) { + dp_peer_unref_delete(tmp_peer); + is_peer_found = true; + } qdf_spin_lock_bh(&soc->ast_lock); if (peer->delete_in_progress) { @@ -629,10 +637,7 @@ int dp_peer_add_ast(struct dp_soc *soc, qdf_spin_unlock_bh(&soc->ast_lock); return 0; } - tmp_peer = dp_peer_find_hash_find(soc, mac_addr, 0, - DP_VDEV_ALL); - if (tmp_peer) { - dp_peer_unref_delete(tmp_peer); + if (is_peer_found) { qdf_spin_unlock_bh(&soc->ast_lock); return 0; }