From patchwork Tue Mar 19 17:39:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13596942 X-Patchwork-Delegate: nbd@nbd.name Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C52B42375B for ; Tue, 19 Mar 2024 17:39:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710869975; cv=none; b=XEsyJW22eOVgToVJNcjgXecSJhKReYULuoWKEja0z3JD+0hSfmknrXBoV/h6QNGQGXussr9VWK2lPwIlDdmdoiTUV0PLZbonjWxpYkwBv+WgVRSnhjMjPeOCTjNHXWFi3q5gfIK48OhTeUktk7VDt2PQvu3LtpCoaRhhIIHev7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710869975; c=relaxed/simple; bh=HTsBylmQ/Fyja+f2LE6kyL3EX6N34Mpa+nEkmWGsRig=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=mK40RGDS4UiDd1JCX2zhm+xp8l90Cg7GJiw2y23Ia+adIOKMUdAEIbAFXv8Z9NoNnWyZAh/iSKJe9Km/RzwVJIsUUp20GKi9tuul+5L6UHfij7pp3iGUAu1jqGkXJ3ZdkIzn00kkAvifgFCunVfvHdAt0DssarlfWVu54iYjelQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eCeX921G; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eCeX921G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF198C433C7; Tue, 19 Mar 2024 17:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710869975; bh=HTsBylmQ/Fyja+f2LE6kyL3EX6N34Mpa+nEkmWGsRig=; h=From:To:Cc:Subject:Date:From; b=eCeX921G0+cdAhV1txEd3bsBRNSv2/5MZST2/Hqs1ydhW6QT9wqFjJ0uJIVTZplwT RtcXdTpVvppdMG7lscLdNczmwJSaSthKWAgah+UGqv4dhMFAXYEKp3R7uDx+E6RntG te7EEIjxSWk6SsUu125D+1pKYfMVz4n1yIPkOrDeag6fxFENeeaAulKMDIyKGAgZsv NB9N+i4XM6zWzTI6khIEVaOVSlNPGE4IE7NNX4LIKC8opMgibToMjEcmGxcszo25wD ZSt/9uygZi/r6kVJ2fmyZ6TAoW1KsmRC8SZfCu2EqCZsSog6LdhFOBtI72vdIlGXCW 2Ypjyg5Y/s0Nw== From: Lorenzo Bianconi To: nbd@nbd.name Cc: lorenzo.bianconi@redhat.com, linux-wireless@vger.kernel.org, sean.wang@mediatek.com, deren.wu@mediatek.com Subject: [RFT] mt76: sdio: move mcu queue size check inside critical section Date: Tue, 19 Mar 2024 18:39:24 +0100 Message-ID: X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Even if it is not a real issue at the moment since concurrent access to mcu message queue is protected by mcu mutex, make the code more robust and move mcu queue free space check inside queue spinlock critical section. Signed-off-by: Lorenzo Bianconi --- compile tested only. @Deren: can you please run some tests? --- drivers/net/wireless/mediatek/mt76/sdio.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/sdio.c b/drivers/net/wireless/mediatek/mt76/sdio.c index 3e88798df017..6198906946f5 100644 --- a/drivers/net/wireless/mediatek/mt76/sdio.c +++ b/drivers/net/wireless/mediatek/mt76/sdio.c @@ -548,10 +548,7 @@ static int mt76s_tx_queue_skb_raw(struct mt76_dev *dev, struct mt76_queue *q, struct sk_buff *skb, u32 tx_info) { - int ret = -ENOSPC, len = skb->len, pad; - - if (q->queued == q->ndesc) - goto error; + int ret, len = skb->len, pad; pad = round_up(skb->len, 4) - skb->len; ret = mt76_skb_adjust_pad(skb, pad); @@ -560,6 +557,12 @@ mt76s_tx_queue_skb_raw(struct mt76_dev *dev, struct mt76_queue *q, spin_lock_bh(&q->lock); + if (q->queued == q->ndesc) { + ret = -ENOSPC; + spin_unlock_bh(&q->lock); + goto error; + } + q->entry[q->head].buf_sz = len; q->entry[q->head].skb = skb;