From patchwork Thu May 27 11:35:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 449280 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB213C4708A for ; Thu, 27 May 2021 11:35:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCF3D613D4 for ; Thu, 27 May 2021 11:35:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233817AbhE0LhN (ORCPT ); Thu, 27 May 2021 07:37:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:45978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233040AbhE0LhM (ORCPT ); Thu, 27 May 2021 07:37:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D8579613D1; Thu, 27 May 2021 11:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622115339; bh=gjhnBhOTi7Awsd2npnMhdrKrxykt+cNqv4JP9FPfc9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mQbasv6AFfeCbJYlp74JDnwxVfC3YQHA3l1Miteve49U6r+pOZ4Jp2FV2tQzbyEQV O4kUSTSusg69jjbLkcXxF+ZQnX2/2t4dCs7riPQcACL/hOiXiLqdegw38Uv0cPnlzl txkFhUHY4fIKXMf3fgC68rkWgpX3tDmojD1W3GGqPdpaG8ophkXGgzSiuVxt6Ga8f0 stCgffTxTVMjLR3p7gY2CpH/ejgBLUafD+gW89ak7bS296eqNSTSVlSBdfLjtX0pYq mPdo1kY8meQi/Ayz5zsfyKmi5KOnkHkIlfrxuV4mx0AFqVWPQ0789MI+Y1s8A8tPp8 Iv4D3ccvyN5Gg== From: Lorenzo Bianconi To: nbd@nbd.name Cc: lorenzo.bianconi@redhat.com, linux-wireless@vger.kernel.org, shayne.chen@mediatek.com, ryder.lee@mediatek.com Subject: [PATCH 1/3] mt76: testmode: fix memory leak in mt76_testmode_alloc_skb Date: Thu, 27 May 2021 13:35:28 +0200 Message-Id: <71df955d0c971505a872cd37eb365d002046b915.1622115194.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Free all pending frames in case of failure in mt76_testmode_alloc_skb routine Fixes: 2601dda8faa76 ("mt76: testmode: add support to send larger packet") Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/testmode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/testmode.c b/drivers/net/wireless/mediatek/mt76/testmode.c index 001d0ba5f73e..f40387a866ee 100644 --- a/drivers/net/wireless/mediatek/mt76/testmode.c +++ b/drivers/net/wireless/mediatek/mt76/testmode.c @@ -158,8 +158,11 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len) frag_len = MT_TXP_MAX_LEN; frag = alloc_skb(frag_len, GFP_KERNEL); - if (!frag) + if (!frag) { + mt76_testmode_free_skb(phy); + dev_kfree_skb(head); return -ENOMEM; + } __skb_put_zero(frag, frag_len); head->len += frag->len; From patchwork Thu May 27 11:35:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 449857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50F39C4708C for ; Thu, 27 May 2021 11:35:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29F90613D1 for ; Thu, 27 May 2021 11:35:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233866AbhE0LhP (ORCPT ); Thu, 27 May 2021 07:37:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:45996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233044AbhE0LhO (ORCPT ); Thu, 27 May 2021 07:37:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DD92D6113B; Thu, 27 May 2021 11:35:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622115341; bh=p73O82Z1ZhU3VDcrG/bDC+qzdAACTdgokU8OAn8p5Mg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qsv4UNpwnB4EAg+6gDct7EVgm+squiC/sGr3/Lt5NYFqGAS+KR/iajZ9b8tMrvxIe Omhxm9WNp45frBxpy5ae6hkfj7e9lsb87ddge86Vr5bV3U3dtS5xgjlxDqk5B0EKDw ++c2Beg+gHeEjQEa9M3H+6e8ZC1BdGs5XQ7wq8rnSk+DEirD+/T6rYC47b/BDjCpK/ wSnFhuVoRDj7MBnJ0JCmoSZkLjhMZapXM8qqnjJrRkEiRP+VeZZ3aa8XV4zfLw5cPN L5gt82zWa7Mwmv0nGjcO1wy8yR6FWURv311QZvH7W5gak8Amq8bXUL32zvAxIeM1S2 RSLJrCoQ4uzfg== From: Lorenzo Bianconi To: nbd@nbd.name Cc: lorenzo.bianconi@redhat.com, linux-wireless@vger.kernel.org, shayne.chen@mediatek.com, ryder.lee@mediatek.com Subject: [PATCH 2/3] mt76: testmode: remove unnecessary function calls in mt76_testmode_free_skb Date: Thu, 27 May 2021 13:35:29 +0200 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Get rid of unnecessary function calls in mt76_testmode_free_skb routine since they are already managed by dev_kfree_skb Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/testmode.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/testmode.c b/drivers/net/wireless/mediatek/mt76/testmode.c index f40387a866ee..c516469278a4 100644 --- a/drivers/net/wireless/mediatek/mt76/testmode.c +++ b/drivers/net/wireless/mediatek/mt76/testmode.c @@ -88,17 +88,8 @@ static void mt76_testmode_free_skb(struct mt76_phy *phy) { struct mt76_testmode_data *td = &phy->test; - struct sk_buff *skb = td->tx_skb; - - if (!skb) - return; - - if (skb_has_frag_list(skb)) { - kfree_skb_list(skb_shinfo(skb)->frag_list); - skb_shinfo(skb)->frag_list = NULL; - } - dev_kfree_skb(skb); + dev_kfree_skb(td->tx_skb); td->tx_skb = NULL; } From patchwork Thu May 27 11:35:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 449279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37B10C47089 for ; Thu, 27 May 2021 11:35:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D8AD613D4 for ; Thu, 27 May 2021 11:35:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233040AbhE0LhR (ORCPT ); Thu, 27 May 2021 07:37:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:46008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233825AbhE0LhQ (ORCPT ); Thu, 27 May 2021 07:37:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B1AEB613D3; Thu, 27 May 2021 11:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622115343; bh=TJknkpMyZT/wY84jq9Xil6QwGq+ffNfouQm2ahZK/m8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AJ7HAD46Ii3KYzgrM3dvPRKqJ4D2MoUSXe+kCW82Z3XRxuXmuBiEFCj5knBMXo3N9 0Rw0cpPJqUpolhT+LrxbWtA9XoL3CyFLKEo7ft7y5HFEgct/dLxmu5fxGPVGtP3ENn zm9KEyAiP97acDkGCaOkAHmW8l2+reUeJ+8qdJKE98Q7wAwqylb/0W7x/F6zZu42p0 aFQBX3PplXZZRezyx2HQMem34fhbx5Qj5LSDlvgx7c0mDOjL2+mTEslO40Gd1D20fL z8P6vrRpzv/uLzwTvXhP98mZMkvCPBrqPPx3bVUISmiRmmZElNeUOHKl3zIZIxixi+ 55vAVAR0wfvXg== From: Lorenzo Bianconi To: nbd@nbd.name Cc: lorenzo.bianconi@redhat.com, linux-wireless@vger.kernel.org, shayne.chen@mediatek.com, ryder.lee@mediatek.com Subject: [PATCH 3/3] mt76: testmode: remove undefined behaviour in mt76_testmode_alloc_skb Date: Thu, 27 May 2021 13:35:30 +0200 Message-Id: <1892c389b06aabc59ff9e01d53fc14cf0097c17d.1622115194.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Get rif of an undefined behaviour in mt76_testmode_alloc_skb routine allocating skb frames Fixes: 2601dda8faa76 ("mt76: testmode: add support to send larger packet") Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/testmode.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/testmode.c b/drivers/net/wireless/mediatek/mt76/testmode.c index c516469278a4..c6a85a0cfc89 100644 --- a/drivers/net/wireless/mediatek/mt76/testmode.c +++ b/drivers/net/wireless/mediatek/mt76/testmode.c @@ -159,12 +159,8 @@ int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len) head->len += frag->len; head->data_len += frag->len; - if (*frag_tail) { - (*frag_tail)->next = frag; - frag_tail = &frag; - } else { - *frag_tail = frag; - } + *frag_tail = frag; + frag_tail = &(*frag_tail)->next; } mt76_testmode_free_skb(phy);