From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 952304F68CD; Tue, 13 Oct 2026 12:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791895668; cv=none; b=hZAsJBt4Ycn+pmHJZKLJ3rXOXWt2dMwNEyN7M0RLnAggXh/Wmx/C74nt2rxiCMOyxaDpODAI49y+MLEY1cDdLU588T343Xushm9dwJokVEA6hmyCOq9dyqgmObd83j53i3jQSL7SYpwR7jg3HaJHyXlJA6jlhB554Y8bHxpF1Q0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791895668; c=relaxed/simple; bh=kLeAhf2Qe+EiFCm11c+7Y70+9mPp5t4glPvEUDA86eo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AuJlfBTPD8amlSBK7uDGvy3ZkZnVOkodR8GqpnzYQeqEF8RYJ21xeioTbAmrkjoDOj1OQkkDwC71360Ak4M4WGD9IsCsUeHGTXJf1iXjGcYu+QtZaxA2aSYw6bc0UzvZqYa/GGIPNI3JKUlLiaUwP9nB6sngeRfYs1Cwu96qJi8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hXw8yVHA; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="hXw8yVHA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A50931F000FF; Tue, 13 Oct 2026 12:47:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1791895667; bh=I/XEFj6y5TYnKpUSD2A27Ae1u7ZLuYv/R73thmUFnyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hXw8yVHADMZZYoCaQglRroov35LcPvNQ5c/n5ermFSo2Brjf49UOYkHDcnzajskU7 ymASQzcJX/YSxMNX2bT/cecBCOTqA+Pp4PDnnIzytR2S6ohj/noShh70ZMP6+yPohn 5UG+XOEygGieJ+IbRcinOorddBS2W9aOYwhAad0s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Baochen Qiang , Vasanthakumar Thiagarajan , Jeff Johnson , Artem Dinaburg , Sasha Levin Subject: [PATCH 6.12 351/497] wifi: ath12k: fix reusing m3 memory Date: Tue, 13 Oct 2026 13:38:38 +0200 Message-ID: <20261013112916.238798176@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261013112907.864180619@linuxfoundation.org> References: <20261013112907.864180619@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Baochen Qiang [ Upstream commit 00575bb44b2c2aa53d0a768de2b80c9c1af0174d ] During firmware recovery or suspend/resume, m3 memory could be reused if the size of the new m3 binary is equal to or less than that of the existing memory. There will be issues for the latter case, since m3_mem->size will be updated with a smaller value and this value is eventually used in the free path, where the original total size should be used instead. To fix it, add a new member in m3_mem_region structure to track the original memory size and use it in free path. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c5-00302-QCAHMTSWPL_V1.0_V2.0_SILICONZ-1.115823.3 [ Backport to 6.12.y: drop the copyright-line hunks, which do not apply to 6.12.y. The code changes are the same as upstream. ] Fixes: 05090ae82f44 ("wifi: ath12k: check M3 buffer size as well whey trying to reuse it") Signed-off-by: Baochen Qiang Reviewed-by: Vasanthakumar Thiagarajan Link: https://patch.msgid.link/20251029-ath12k-fix-m3-reuse-v1-1-69225bacfc5d@oss.qualcomm.com Signed-off-by: Jeff Johnson Assisted-by: LLM Signed-off-by: Artem Dinaburg Signed-off-by: Sasha Levin --- drivers/net/wireless/ath/ath12k/qmi.c | 9 ++++++--- drivers/net/wireless/ath/ath12k/qmi.h | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c index b93ce9f87f612..5b02d1d76a36e 100644 --- a/drivers/net/wireless/ath/ath12k/qmi.c +++ b/drivers/net/wireless/ath/ath12k/qmi.c @@ -2724,9 +2724,10 @@ static void ath12k_qmi_m3_free(struct ath12k_base *ab) if (!m3_mem->vaddr) return; - dma_free_coherent(ab->dev, m3_mem->size, + dma_free_coherent(ab->dev, m3_mem->total_size, m3_mem->vaddr, m3_mem->paddr); m3_mem->vaddr = NULL; + m3_mem->total_size = 0; m3_mem->size = 0; } @@ -2762,7 +2763,7 @@ static int ath12k_qmi_m3_load(struct ath12k_base *ab) /* In recovery/resume cases, M3 buffer is not freed, try to reuse that */ if (m3_mem->vaddr) { - if (m3_mem->size >= m3_len) + if (m3_mem->total_size >= m3_len) goto skip_m3_alloc; /* Old buffer is too small, free and reallocate */ @@ -2774,11 +2775,13 @@ static int ath12k_qmi_m3_load(struct ath12k_base *ab) GFP_KERNEL); if (!m3_mem->vaddr) { ath12k_err(ab, "failed to allocate memory for M3 with size %zu\n", - fw->size); + m3_len); ret = -ENOMEM; goto out; } + m3_mem->total_size = m3_len; + skip_m3_alloc: memcpy(m3_mem->vaddr, m3_data, m3_len); m3_mem->size = m3_len; diff --git a/drivers/net/wireless/ath/ath12k/qmi.h b/drivers/net/wireless/ath/ath12k/qmi.h index 0dfcbd8cb59b6..e9eb186441cce 100644 --- a/drivers/net/wireless/ath/ath12k/qmi.h +++ b/drivers/net/wireless/ath/ath12k/qmi.h @@ -118,6 +118,9 @@ struct target_info { }; struct m3_mem_region { + /* total memory allocated */ + u32 total_size; + /* actual memory being used */ u32 size; dma_addr_t paddr; void *vaddr; -- 2.53.0