From patchwork Tue Jan 17 13:53:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13104709 X-Patchwork-Delegate: nbd@nbd.name Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98544C677F1 for ; Tue, 17 Jan 2023 13:54:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbjAQNyE (ORCPT ); Tue, 17 Jan 2023 08:54:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231370AbjAQNxj (ORCPT ); Tue, 17 Jan 2023 08:53:39 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E617D125B1 for ; Tue, 17 Jan 2023 05:53:38 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A1CBDB8163A for ; Tue, 17 Jan 2023 13:53:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03D6EC433D2; Tue, 17 Jan 2023 13:53:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673963616; bh=nk+Re60RYHcCBiN7iaGHXgD9hFEjuZ/uY5jRwFwkFHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eqipFMRzcY9D3plcGsg6521Adlwl9oaNgujWuUvyaCHV4NYUU+8LjzSe7oNAKFKOs GAodNN+VLbDTUsW6ngPvPLG+rmczoDBPXFLbrlLZAYz8oVHH3B0/RrZYY384htuUYs ibmhW7ZOPoO9pVxS1fWBF/Ss71q43UtgkU1KitKdW2UtC3Y+SVRI+suZIJPrfWaRW/ xSukEU7h1inis3Z5lpq98xR02zeRg3QNKPTmDyU09b5CfIquznoXGzwyNl/cABKQYX 0id9Ll3h/pzWMrPchDsfIRWXRzO56p1nchWuM3K0tsLGVezrnNbGFyrZr5ta66aRax o4tym+HDjrXUw== From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com Subject: [PATCH v2 1/4] wifi: mt76: mt7915: fix memory leak in mt7915_mmio_wed_init_rx_buf Date: Tue, 17 Jan 2023 14:53:14 +0100 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Free mt76_txwi_cache pointer in mt7915_mmio_wed_init_rx_buf routine in case of failure. Fixes: 4f831d18d12d ("wifi: mt76: mt7915: enable WED RX support") Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt7915/mmio.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c index b96348002815..20efbf47110b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c @@ -637,9 +637,14 @@ static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size) int token; void *ptr; + if (!t) + goto unmap; + page = __dev_alloc_pages(GFP_KERNEL, get_order(length)); - if (!page) + if (!page) { + mt76_put_rxwi(&dev->mt76, t); goto unmap; + } ptr = page_address(page); phy_addr = dma_map_single(dev->mt76.dma_dev, ptr, @@ -647,6 +652,7 @@ static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size) DMA_TO_DEVICE); if (unlikely(dma_mapping_error(dev->mt76.dev, phy_addr))) { __free_pages(page, get_order(length)); + mt76_put_rxwi(&dev->mt76, t); goto unmap; } @@ -656,6 +662,7 @@ static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size) dma_unmap_single(dev->mt76.dma_dev, phy_addr, wed->wlan.rx_size, DMA_TO_DEVICE); __free_pages(page, get_order(length)); + mt76_put_rxwi(&dev->mt76, t); goto unmap; }