Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1121589pxf; Fri, 26 Mar 2021 01:17:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3AL6Ma08lDt5fQaRTJFBKzcdUZpGQf98P6umcXSblinJ2ywr6fSGJsm5cLawAfmSWypmg X-Received: by 2002:a17:906:cd05:: with SMTP id oz5mr14169439ejb.345.1616746630945; Fri, 26 Mar 2021 01:17:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616746630; cv=none; d=google.com; s=arc-20160816; b=GYEfkMfg1hqIKa+O4bgKuvJTZe0KnSU4o1OpXW4VWOn+5kLXpbuzkqQduBKCZ4JTRI K6q29pqYV8+XGeAXQpZ+EaaBT2sdQGFOUeEH6mJjj+kEJct7TiNE/AnYwjCwDlyn8Yxd BSUPiC4Y3Xk5yGtqKQgSr7t5vc6ECKVZt0m8ajxWAafiS7xzNp/3DQ7XgjAuiaXFm9u7 0bfn5HJ2+q7LDEy6fwZlgAOoF0887/iIkqAKMQ+0jUHfozXkDGJFUE1jDgBFwwMIQ69/ 68yEPmc7MjNkMuCkrhMDRkOlnc5k4s5FfpdG+a8Fj5Yf4whf2qB5kTPwBNed8n3n9YGy ioqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=NqbENeAB6AweRLS9ploBusk+xAfU+B2sy8VHr1a50Qo=; b=K196PDazC5SldsBcIg8kzx85YPwuxmaUPysVWMSBDZikMqOvM0S5adrGc0w5QTnHEB 9n32nfvxAMy/P5+AD5bF/mpDDINa0eeuBT5adc6oEfBG3HflUindRKEs5CMLto8Iv7V5 e3QCND93V5bYwwGgxEIzaiQmaCtrD0v/nfkJKZK6exxOlLPYtNaZt2VCNP/1eBt8HcLu cERx9K0ySyRJyZUwpNU5Ami0+aKkmpmFZ2ZlTkiukdLwjthTFT1JLC7FquPLC9zgKy7C zkrrKHXTdGOVpgyEfxJKbT/VZ9+YjT3cDShJ75Lwx8xTLQGQ2bgk3oNs0IiuF8vZOIvP hvHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=kxw7whtK; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h25si6089440ejd.683.2021.03.26.01.16.47; Fri, 26 Mar 2021 01:17:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=kxw7whtK; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230006AbhCZIQI (ORCPT + 99 others); Fri, 26 Mar 2021 04:16:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbhCZIQD (ORCPT ); Fri, 26 Mar 2021 04:16:03 -0400 Received: from nbd.name (nbd.name [IPv6:2a01:4f8:221:3d45::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B167C0613AA for ; Fri, 26 Mar 2021 01:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject :To:From:Sender:Reply-To:Cc:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=NqbENeAB6AweRLS9ploBusk+xAfU+B2sy8VHr1a50Qo=; b=kxw7whtKkEhr3dyiDyZ+VmvPfD LovMJ7/kLueir7OD2GGroqg5EbcW5PDywSIURsfI2GkAGM1X9/ETl9u3QnMGCpEz+IeIDUJirX2WQ 9q2I1dZDTWCGiozf8OpFW9dPPrQZGQaCUgEPTvUl3y1U9t2Hx+BcXhP/W/r6145yXL1g=; Received: from p4ff13c8d.dip0.t-ipconnect.de ([79.241.60.141] helo=localhost.localdomain) by ds12 with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1lPhdR-0007bD-8w for linux-wireless@vger.kernel.org; Fri, 26 Mar 2021 09:16:01 +0100 From: Felix Fietkau To: linux-wireless@vger.kernel.org Subject: [PATCH 1/2] mt76: mt7915: fix key set/delete issue Date: Fri, 26 Mar 2021 09:15:51 +0100 Message-Id: <20210326081552.21736-1-nbd@nbd.name> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Deleting a key with the previous key index deletes the current key Rework the code to better keep track of multiple keys and check for the key index before deleting the current key Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7915/main.c | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c index cde8c1ce3ae0..b32a435688bc 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c @@ -346,7 +346,9 @@ static int mt7915_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, struct mt7915_sta *msta = sta ? (struct mt7915_sta *)sta->drv_priv : &mvif->sta; struct mt76_wcid *wcid = &msta->wcid; + u8 *wcid_keyidx = &wcid->hw_key_idx; int idx = key->keyidx; + int err = 0; /* The hardware does not support per-STA RX GTK, fallback * to software mode for these. @@ -361,6 +363,7 @@ static int mt7915_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, /* fall back to sw encryption for unsupported ciphers */ switch (key->cipher) { case WLAN_CIPHER_SUITE_AES_CMAC: + wcid_keyidx = &wcid->hw_key_idx2; key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE; break; case WLAN_CIPHER_SUITE_TKIP: @@ -376,16 +379,24 @@ static int mt7915_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, return -EOPNOTSUPP; } - if (cmd == SET_KEY) { - key->hw_key_idx = wcid->idx; - wcid->hw_key_idx = idx; - } else if (idx == wcid->hw_key_idx) { - wcid->hw_key_idx = -1; - } + mutex_lock(&dev->mt76.mutex); + + if (cmd == SET_KEY) + *wcid_keyidx = idx; + else if (idx == *wcid_keyidx) + *wcid_keyidx = -1; + else + goto out; + mt76_wcid_key_setup(&dev->mt76, wcid, cmd == SET_KEY ? key : NULL); - return mt7915_mcu_add_key(dev, vif, msta, key, cmd); + err = mt7915_mcu_add_key(dev, vif, msta, key, cmd); + +out: + mutex_unlock(&dev->mt76.mutex); + + return err; } static int mt7915_config(struct ieee80211_hw *hw, u32 changed) -- 2.30.1