wifi: iwlwifi: mvm: fold the ref++ into iwl_mvm_phy_ctxt_add
authorEmmanuel Grumbach <emmanuel.grumbach@intel.com>
Wed, 11 Oct 2023 10:07:25 +0000 (13:07 +0300)
committerJohannes Berg <johannes.berg@intel.com>
Mon, 23 Oct 2023 10:26:27 +0000 (12:26 +0200)
When we want to add a phy_ctxt, we need to increase the ref.
Note that all the WARN_ONs are already in place:
* We check that we don't add a context with ref != 0
* We check that we don't modify a context with ref = 0

Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: Gregory Greenman <gregory.greenman@intel.com>
Link: https://lore.kernel.org/r/20231011130030.c19c07746b26.I5b0cbe0760811631a320218a10b88870b5bf0897@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c
drivers/net/wireless/intel/iwlwifi/mvm/phy-ctxt.c

index 0d78a9efbe2fb7a85b60391109488d8bc511dd14..d161e2ea1ac55eb26a6e78847da106e089129e75 100644 (file)
@@ -4716,7 +4716,6 @@ int iwl_mvm_roc_common(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
                        goto out_unlock;
                }
 
-               iwl_mvm_phy_ctxt_ref(mvm, mvmvif->deflink.phy_ctxt);
                goto link_and_start_p2p_roc;
        }
 
@@ -4812,7 +4811,6 @@ static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
                goto out;
        }
 
-       iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
        *phy_ctxt_id = phy_ctxt->id;
 out:
        return ret;
index c3c1b57a05ce139767c3673ead688197281a2f9a..8baf261888a7cb94be2d1a83036c3c84e24b6eed 100644 (file)
@@ -265,6 +265,8 @@ int iwl_mvm_phy_ctxt_add(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
                         struct cfg80211_chan_def *chandef,
                         u8 chains_static, u8 chains_dynamic)
 {
+       int ret;
+
        WARN_ON(!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
                ctxt->ref);
        lockdep_assert_held(&mvm->mutex);
@@ -273,9 +275,16 @@ int iwl_mvm_phy_ctxt_add(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
        ctxt->width = chandef->width;
        ctxt->center_freq1 = chandef->center_freq1;
 
-       return iwl_mvm_phy_ctxt_apply(mvm, ctxt, chandef,
-                                     chains_static, chains_dynamic,
-                                     FW_CTXT_ACTION_ADD);
+       ret = iwl_mvm_phy_ctxt_apply(mvm, ctxt, chandef,
+                                    chains_static, chains_dynamic,
+                                    FW_CTXT_ACTION_ADD);
+
+       if (ret)
+               return ret;
+
+       ctxt->ref++;
+
+       return 0;
 }
 
 /*
@@ -285,6 +294,11 @@ int iwl_mvm_phy_ctxt_add(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
 void iwl_mvm_phy_ctxt_ref(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt)
 {
        lockdep_assert_held(&mvm->mutex);
+
+       /* If we were taking the first ref, we should have
+        * called iwl_mvm_phy_ctxt_add.
+        */
+       WARN_ON(!ctxt->ref);
        ctxt->ref++;
 }