Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp6403906rwp; Mon, 17 Jul 2023 22:50:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlHPX9IP3HMgSQdrpuefwKhcsB28MGwijZYYb9kcPYbUQ2LQgL4FJGshL2SBsxhfOlGxnpJw X-Received: by 2002:a05:6a20:100c:b0:12d:208c:acaa with SMTP id gs12-20020a056a20100c00b0012d208cacaamr11026351pzc.26.1689659406067; Mon, 17 Jul 2023 22:50:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689659406; cv=none; d=google.com; s=arc-20160816; b=nYM7zPIuqxdWXVolJOZpeEi2+Mho/4YqZgqNqGxBV/ivnMG+jCSGuv8r73HxW6TNLY 1Zn5amVolxtRJiQtIohVJMseKuUQsK6D8SDY9A8FxW0bUaErkuBueB1UJKqzOZ+gnqHZ iYOkfa+cJvqI5at6wf0SmG+f2cWZyyZ3wlgdq0sVnrTUJkZgF3A18r71lwnhckKLmw09 8SFvYuQfj5LNu2VGOIERyHC2LEHHmBApqCw1Zso5IHRzKSTxp/5UlN9hIPHEhCksYYsK 5z54C72TY30u50EtnsSQT2NvZl7RMUrn27uxxq9K4YJBi0ycrhZU3WYsIRpJU6Ggs+ix 5DmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=wI2pBkxpLUpAB3X5rfTIAH0MJvDD2NlcQekkg1nEGUk=; fh=XrB5Xts4kE2+wmNz5OtyIYlsnxWEmVc9vZ5u9cGRtWE=; b=O0rQa2+lDlRfbQs060nwSp2b/r//a6MwyzJxZJf9yUh1gFYLtqxqwgw0pFYkTsKyuH XOBVaua88GSDRLgR7lyvkR23AKJ228VQGqSp/HBWQ+fMVGYsHggYlbPlTVf8IJ5RQSUg BIOln4roEZYluTtIkyghui3q6SLoyrC6gE3utiMV6Fn/Le4puCiIBHUDgo9Pi7i4Apaj XgEZvgYB6GSuy0JzmE6BnH/O1uoMADZOvnu3CEaqdOe19hlFY63xgwO9x2wKiDFHw8zH 5qvLCKbJTgLVd2opUKNE5028MFldsgh8YIBXcFVX+8PooGetIYDbrQ4dlzn3YY8cozH5 Zr3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=e2KcgLyq; 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=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h14-20020a056a00230e00b0067dd87a586esi1071310pfh.377.2023.07.17.22.49.55; Mon, 17 Jul 2023 22:50:06 -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=@quicinc.com header.s=qcppdkim1 header.b=e2KcgLyq; 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=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230159AbjGRFgD (ORCPT + 58 others); Tue, 18 Jul 2023 01:36:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230156AbjGRFgC (ORCPT ); Tue, 18 Jul 2023 01:36:02 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4B05E43 for ; Mon, 17 Jul 2023 22:36:00 -0700 (PDT) Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36I5Y5sQ005063; Tue, 18 Jul 2023 05:35:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=qcppdkim1; bh=wI2pBkxpLUpAB3X5rfTIAH0MJvDD2NlcQekkg1nEGUk=; b=e2KcgLyqFebnOHTXEKc9GWCRGHM4aGemEcYZo3TGYpZLROmKqPmtqzd3F3J+LKJlrg+J 21y1SCUNwRWdw+ekp6dnUI+EQKX/mGKfuq5mDqoK2NL0huvRFFOAdEaZGAVJKdwXCvue 4kd49xGBbENrn2+FT13vQ4a1zU+fukvyQISeLY/8Wa4XiGhRvzaFtbDbpijIghH6kgJ0 2SclE+TbTdo2QLEQ2eC9HZh5mOp/GsZTpwAztC6MRH6hAQqpdEpRn+Zowk2MhnEUPIpe Yk72SQAaAyfBtEz+0S+AMa0m4IfQ8Fdp9J8LNPdMMIcS/364AjlUP53MPEN7Rlm6TnC1 ng== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rw4af21j0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jul 2023 05:35:45 +0000 Received: from nasanex01a.na.qualcomm.com (nasanex01a.na.qualcomm.com [10.52.223.231]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36I5ZiDt020303 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jul 2023 05:35:44 GMT Received: from rajson-linux.qualcomm.com (10.80.80.8) by nasanex01a.na.qualcomm.com (10.52.223.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Mon, 17 Jul 2023 22:35:42 -0700 From: Rajat Soni To: CC: , Rajat Soni Subject: [PATCH] wifi: ath12k: Fix memory leak in rx_desc and tx_desc Date: Tue, 18 Jul 2023 11:05:10 +0530 Message-ID: <20230718053510.30894-1-quic_rajson@quicinc.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01a.na.qualcomm.com (10.52.223.231) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: HMJ4rck0Vtq5ttlW12fJjs_ZM5UHm0ZD X-Proofpoint-ORIG-GUID: HMJ4rck0Vtq5ttlW12fJjs_ZM5UHm0ZD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-17_15,2023-07-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 mlxlogscore=882 mlxscore=0 malwarescore=0 bulkscore=0 phishscore=0 clxscore=1011 suspectscore=0 impostorscore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307180052 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Currently when ath12k_dp_cc_desc_init api is triggered we allocate memory to rx_descs and tx_descs. In ath12k_dp_cc_cleanup, during descriptor cleanup rx_descs and tx_descs memory is not freed. This is cause of memory leak. These allocated memory should be freed in ath12k_dp_cc_cleanup. In ath12k_dp_cc_desc_init, we can save base address of rx_descs and tx_descs. In ath12k_dp_cc_cleanup, we can free rx_descs and tx_descs memory using their base address. Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.0.1-00029-QCAHKSWPL_SILICONZ-1 Signed-off-by: Rajat Soni --- drivers/net/wireless/ath/ath12k/dp.c | 30 +++++++++++++++++++++++++++- drivers/net/wireless/ath/ath12k/dp.h | 2 ++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/dp.c b/drivers/net/wireless/ath/ath12k/dp.c index ae1645d0f42a..db6ac0e0be2c 100644 --- a/drivers/net/wireless/ath/ath12k/dp.c +++ b/drivers/net/wireless/ath/ath12k/dp.c @@ -1129,6 +1129,7 @@ static void ath12k_dp_cc_cleanup(struct ath12k_base *ab) struct ath12k_dp *dp = &ab->dp; struct sk_buff *skb; int i; + u32 pool_id, tx_spt_page; if (!dp->spt_info) return; @@ -1148,6 +1149,14 @@ static void ath12k_dp_cc_cleanup(struct ath12k_base *ab) dev_kfree_skb_any(skb); } + for (i = 0; i < ATH12K_NUM_RX_SPT_PAGES; i++) { + if (!dp->spt_info->rxbaddr[i]) + continue; + + kfree(dp->spt_info->rxbaddr[i]); + dp->spt_info->rxbaddr[i] = NULL; + } + spin_unlock_bh(&dp->rx_desc_lock); /* TX Descriptor cleanup */ @@ -1170,6 +1179,21 @@ static void ath12k_dp_cc_cleanup(struct ath12k_base *ab) spin_unlock_bh(&dp->tx_desc_lock[i]); } + for (pool_id = 0; pool_id < ATH12K_HW_MAX_QUEUES; pool_id++) { + spin_lock_bh(&dp->tx_desc_lock[pool_id]); + + for (i = 0; i < ATH12K_TX_SPT_PAGES_PER_POOL; i++) { + tx_spt_page = i + pool_id * ATH12K_TX_SPT_PAGES_PER_POOL; + if (!dp->spt_info->txbaddr[tx_spt_page]) + continue; + + kfree(dp->spt_info->txbaddr[tx_spt_page]); + dp->spt_info->txbaddr[tx_spt_page] = NULL; + } + + spin_unlock_bh(&dp->tx_desc_lock[pool_id]); + } + /* unmap SPT pages */ for (i = 0; i < dp->num_spt_pages; i++) { if (!dp->spt_info[i].vaddr) @@ -1343,6 +1367,8 @@ static int ath12k_dp_cc_desc_init(struct ath12k_base *ab) return -ENOMEM; } + dp->spt_info->rxbaddr[i] = &rx_descs[0]; + for (j = 0; j < ATH12K_MAX_SPT_ENTRIES; j++) { rx_descs[j].cookie = ath12k_dp_cc_cookie_gen(i, j); rx_descs[j].magic = ATH12K_DP_RX_DESC_MAGIC; @@ -1368,8 +1394,10 @@ static int ath12k_dp_cc_desc_init(struct ath12k_base *ab) return -ENOMEM; } + tx_spt_page = i + pool_id * ATH12K_TX_SPT_PAGES_PER_POOL; + dp->spt_info->txbaddr[tx_spt_page] = &tx_descs[0]; + for (j = 0; j < ATH12K_MAX_SPT_ENTRIES; j++) { - tx_spt_page = i + pool_id * ATH12K_TX_SPT_PAGES_PER_POOL; ppt_idx = ATH12K_NUM_RX_SPT_PAGES + tx_spt_page; tx_descs[j].desc_id = ath12k_dp_cc_cookie_gen(ppt_idx, j); tx_descs[j].pool_id = pool_id; diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index 7c5dafce5a68..9aeda0321cd7 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -289,6 +289,8 @@ struct ath12k_tx_desc_info { struct ath12k_spt_info { dma_addr_t paddr; u64 *vaddr; + struct ath12k_rx_desc_info *rxbaddr[ATH12K_NUM_RX_SPT_PAGES]; + struct ath12k_tx_desc_info *txbaddr[ATH12K_NUM_TX_SPT_PAGES]; }; struct ath12k_reo_queue_ref { -- 2.17.1