Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1031322lqt; Tue, 19 Mar 2024 10:39:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1C5TV5N4HbYrFh+ALUY40T3l1/Ggjib8nakmNsPMYi05nra4wSAGqkHaCXD6tXLd73Q7/FPsnjFHdQeSRFnJt/uatW5kjBFrPzKEFZA== X-Google-Smtp-Source: AGHT+IEb9fPvCwUOPuCMcymFNNVTJCF8WqdS2cMFVYKhFVvn8fxN2gteOVa3eXqKQqT7JOgHtGse X-Received: by 2002:a0c:db03:0:b0:690:e990:c183 with SMTP id d3-20020a0cdb03000000b00690e990c183mr16105667qvk.10.1710869980099; Tue, 19 Mar 2024 10:39:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710869980; cv=pass; d=google.com; s=arc-20160816; b=obewNWlEOkgxwt6uz2MCXChcz0nUI4JPz3TQgEG9OmpxlQVH0zdmJaO6ltSlYNCClR GJXjP3Rbadb3VJRBE99m8RHTZeRJHdmsJKO6E3SQC8Thqiq3INlDKJW6QxvI+qBELaEB khp5eQJuJyuE2T6O68e6EBXIbSeMrVnc/QxdBNVA7vrKzIxj/brBpEdDF51tHntV0oIR kbK//GX7yzynX3hjl5WluKZfjZVIDPcUKBFFNOwfEQFAfT/Hks1RnEvxa5tSRvGbMYiE gT3FRYkYEOJemJfQrJ11VNMqcYM1eZmp4hk7XJKfwZW5ivmB/hfkZR+sGr3qUJ3ng2Cz DTZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=30OVccu37msNI2bSsKUApJ3bxW4FidEbBz78sq4z1tk=; fh=pegCnw1n517BRFKuFQ2sxAAC52QjGBSrPmiRQc9uhx8=; b=IdAbZhfziIk2kXlde9bgho2CIpuzStwmqXLVdRhsrQBaLlQXaOhS5zsipgpEqJSlQ8 0MWUPTDr5X3uDvatC426zVrORHn/wRx17RKViZZoN4QZ97loj/p+X+nYZECwm3nhpol5 oUPFUgZzsRHjjOZBgIk0dL8i93QNnqI1o7WfFFGzXlNc70W8s3KqPv4Hx3FlEqQI5YgI jV74+E74navOuWPB0EOpDzzskRj5kP9O0mi6e1fsbTL/lXBJ1BCaPBniWR/PTXJXI0cZ 0tbOsIcZaTY46jpFJvUflymSC+/RfrHjHGS3kA/Q7/p1pmgAEX3g7VbDfdF3ZFY5xU+a QvbQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eCeX921G; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-wireless+bounces-4923-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-wireless+bounces-4923-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h12-20020a0562140dac00b0068ef4078b0csi11611805qvh.557.2024.03.19.10.39.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 10:39:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless+bounces-4923-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eCeX921G; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-wireless+bounces-4923-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-wireless+bounces-4923-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C52191C21001 for ; Tue, 19 Mar 2024 17:39:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA8EA23772; Tue, 19 Mar 2024 17:39:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eCeX921G" X-Original-To: linux-wireless@vger.kernel.org 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 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 Content-Transfer-Encoding: 8bit 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; -- 2.44.0