Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4111340rwb; Mon, 31 Jul 2023 01:12:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlEfFiquDLpaCHsTqxtCgEbWF2ovkfJasn3RsCJ4bGbkKgvZopS6sKTM5jmcx2+aDHdqXAL8 X-Received: by 2002:a17:903:1246:b0:1bb:a367:a70 with SMTP id u6-20020a170903124600b001bba3670a70mr9018182plh.17.1690791158875; Mon, 31 Jul 2023 01:12:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690791158; cv=none; d=google.com; s=arc-20160816; b=uY2pPvGDx/LYHWBhRYp86XAatjKoNjIcr+RJ9JHFOFQf9vL7jXsxLI1qTHNKPuMbL0 yAs4m/JWKwCzJzDK16yBt0M9iR/YhB3opyKpb2mxAGKygg/nshY1LdRitALuRu/2rQvu dr5mHmTRPISHNTtXp2YBpb/I5QhUpzrM7cGZPBSTmqA0QT5sn+wRZQNl8dIOzB/bs29p rgJYRYz/ghs59XDS4iH5xzy6QdpA5G/80Grvi22mhtxBL1qfmY/9nXkYyzbGhGEbz6C6 ha5pLA9RIxYgUY/9x8EUcZi3Vbg9J6KOHcKVkv2+7EAbCbzzLvXfRE6C0jDxtUE2Ksuu CPSg== 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:cc:to:from:dkim-signature; bh=niPW9mOlnq+6D62V91CeQPMC9wMt/+kbxTndO37szXg=; fh=3TPm3sajwtWrN1bG/QWGjiUYm6kHkLuPR+YSyDrY0z4=; b=XtGDg8ndVYvwSCnS4Ir48irfXBB+ugxRGGTfEgz2YoCQztbkKEj+47ZcDFgDt2ml5R VjDj/MR97Rcr4bMraEL8x+q8gV6rq3GLF+gFQSRa8rg4l6kjZbouUVlIA6dIS5O5i08w E4OZDz0BEWwijf1+23nJumeAB7fNPRsPC8Spocx7eed9i5NFE/1gdamsf8gIvMbXNZXg 1sMeL/pkVPNh+jcTQrRLzYBbNNn2n6LycFt4ZFsps3BoOiWpToHBLe20V6WYreWe2hGj BAjNFusdkV1hutfudlTfjiYDCDZrCt6qBAKYaxpQaFcMvORX47Q8H0Xx5hQ4tejAJ8gC LsZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=Jk8jCefp; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q7-20020a170902a3c700b001bb162e944dsi3829295plb.51.2023.07.31.01.12.26; Mon, 31 Jul 2023 01:12:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=Jk8jCefp; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229897AbjGaHoT (ORCPT + 59 others); Mon, 31 Jul 2023 03:44:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229766AbjGaHoS (ORCPT ); Mon, 31 Jul 2023 03:44:18 -0400 Received: from forward102c.mail.yandex.net (forward102c.mail.yandex.net [178.154.239.213]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CF9A133 for ; Mon, 31 Jul 2023 00:44:17 -0700 (PDT) Received: from mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:2891:0:640:3c15:0]) by forward102c.mail.yandex.net (Yandex) with ESMTP id 0172160045; Mon, 31 Jul 2023 10:44:15 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id EiKcMeeWuqM0-zZYuyZAm; Mon, 31 Jul 2023 10:44:14 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1690789454; bh=niPW9mOlnq+6D62V91CeQPMC9wMt/+kbxTndO37szXg=; h=Message-ID:Date:Cc:Subject:To:From; b=Jk8jCefpji63l1E/p29JwC+pubkVOF6ROAVgU0AjGj0xjCipWj7y1xYpCBCH2EeTy 8goKWx+Isnr+YD7ORJs2mQJjndjjyvj1Rrj0M6mkH2RBMm4OQLM77sz7flCHy7xC1c osVyA7/ots4ybxReqOTfiHMtXpIsQSdZovXkcuEk= Authentication-Results: mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Brian Norris Cc: Kalle Valo , linux-wireless@vger.kernel.org, Dmitry Antipov Subject: [PATCH] wifi: mwifiex: fix error recovery in PCIE buffer descriptor management Date: Mon, 31 Jul 2023 10:43:07 +0300 Message-ID: <20230731074334.56463-1-dmantipov@yandex.ru> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Add missing 'kfree_skb()' in 'mwifiex_init_rxq_ring()' and never do 'kfree(card->rxbd_ring_vbase)' because this area is DMAed and should be released with 'dma_free_coherent()'. The latter is performed in 'mwifiex_pcie_delete_rxbd_ring()', which is now called to recover from possible errors in 'mwifiex_pcie_create_rxbd_ring()'. Likewise for 'mwifiex_pcie_init_evt_ring()', 'kfree(card->evtbd_ring_vbase)' 'mwifiex_pcie_delete_evtbd_ring()' and 'mwifiex_pcie_create_rxbd_ring()'. Fixes: 0732484b47b5 ("mwifiex: separate ring initialization and ring creation routines") Signed-off-by: Dmitry Antipov --- drivers/net/wireless/marvell/mwifiex/pcie.c | 25 ++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c index 9a698a16a8f3..6697132ecc97 100644 --- a/drivers/net/wireless/marvell/mwifiex/pcie.c +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c @@ -189,6 +189,8 @@ static int mwifiex_pcie_probe_of(struct device *dev) } static void mwifiex_pcie_work(struct work_struct *work); +static int mwifiex_pcie_delete_rxbd_ring(struct mwifiex_adapter *adapter); +static int mwifiex_pcie_delete_evtbd_ring(struct mwifiex_adapter *adapter); static int mwifiex_map_pci_memory(struct mwifiex_adapter *adapter, struct sk_buff *skb, @@ -792,14 +794,15 @@ static int mwifiex_init_rxq_ring(struct mwifiex_adapter *adapter) if (!skb) { mwifiex_dbg(adapter, ERROR, "Unable to allocate skb for RX ring.\n"); - kfree(card->rxbd_ring_vbase); return -ENOMEM; } if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_RX_DATA_BUF_SIZE, - DMA_FROM_DEVICE)) - return -1; + DMA_FROM_DEVICE)) { + kfree_skb(skb); + return -ENOMEM; + } buf_pa = MWIFIEX_SKB_DMA_ADDR(skb); @@ -849,7 +852,6 @@ static int mwifiex_pcie_init_evt_ring(struct mwifiex_adapter *adapter) if (!skb) { mwifiex_dbg(adapter, ERROR, "Unable to allocate skb for EVENT buf.\n"); - kfree(card->evtbd_ring_vbase); return -ENOMEM; } skb_put(skb, MAX_EVENT_SIZE); @@ -857,8 +859,7 @@ static int mwifiex_pcie_init_evt_ring(struct mwifiex_adapter *adapter) if (mwifiex_map_pci_memory(adapter, skb, MAX_EVENT_SIZE, DMA_FROM_DEVICE)) { kfree_skb(skb); - kfree(card->evtbd_ring_vbase); - return -1; + return -ENOMEM; } buf_pa = MWIFIEX_SKB_DMA_ADDR(skb); @@ -1058,6 +1059,7 @@ static int mwifiex_pcie_delete_txbd_ring(struct mwifiex_adapter *adapter) */ static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter) { + int ret; struct pcie_service_card *card = adapter->card; const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; @@ -1096,7 +1098,10 @@ static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter) (u32)((u64)card->rxbd_ring_pbase >> 32), card->rxbd_ring_size); - return mwifiex_init_rxq_ring(adapter); + ret = mwifiex_init_rxq_ring(adapter); + if (ret) + mwifiex_pcie_delete_rxbd_ring(adapter); + return ret; } /* @@ -1127,6 +1132,7 @@ static int mwifiex_pcie_delete_rxbd_ring(struct mwifiex_adapter *adapter) */ static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter) { + int ret; struct pcie_service_card *card = adapter->card; const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; @@ -1161,7 +1167,10 @@ static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter) (u32)((u64)card->evtbd_ring_pbase >> 32), card->evtbd_ring_size); - return mwifiex_pcie_init_evt_ring(adapter); + ret = mwifiex_pcie_init_evt_ring(adapter); + if (ret) + mwifiex_pcie_delete_evtbd_ring(adapter); + return ret; } /* -- 2.41.0