Skip to content

Commit 00575bb

Browse files
Baochen Qiangjeff-t-johnson
authored andcommitted
wifi: ath12k: fix reusing m3 memory
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 Fixes: 05090ae ("wifi: ath12k: check M3 buffer size as well whey trying to reuse it") Signed-off-by: Baochen Qiang <baochen.qiang@oss.qualcomm.com> Reviewed-by: Vasanthakumar Thiagarajan <vasanthakumar.thiagarajan@oss.qualcomm.com> Link: https://patch.msgid.link/20251029-ath12k-fix-m3-reuse-v1-1-69225bacfc5d@oss.qualcomm.com Signed-off-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
1 parent be5febd commit 00575bb

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

drivers/net/wireless/ath/ath12k/qmi.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: BSD-3-Clause-Clear
22
/*
33
* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4-
* Copyright (c) 2021-2025 Qualcomm Innovation Center, Inc. All rights reserved.
4+
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
55
*/
66

77
#include <linux/elf.h>
@@ -3114,9 +3114,10 @@ static void ath12k_qmi_m3_free(struct ath12k_base *ab)
31143114
if (!m3_mem->vaddr)
31153115
return;
31163116

3117-
dma_free_coherent(ab->dev, m3_mem->size,
3117+
dma_free_coherent(ab->dev, m3_mem->total_size,
31183118
m3_mem->vaddr, m3_mem->paddr);
31193119
m3_mem->vaddr = NULL;
3120+
m3_mem->total_size = 0;
31203121
m3_mem->size = 0;
31213122
}
31223123

@@ -3152,7 +3153,7 @@ static int ath12k_qmi_m3_load(struct ath12k_base *ab)
31523153

31533154
/* In recovery/resume cases, M3 buffer is not freed, try to reuse that */
31543155
if (m3_mem->vaddr) {
3155-
if (m3_mem->size >= m3_len)
3156+
if (m3_mem->total_size >= m3_len)
31563157
goto skip_m3_alloc;
31573158

31583159
/* Old buffer is too small, free and reallocate */
@@ -3164,11 +3165,13 @@ static int ath12k_qmi_m3_load(struct ath12k_base *ab)
31643165
GFP_KERNEL);
31653166
if (!m3_mem->vaddr) {
31663167
ath12k_err(ab, "failed to allocate memory for M3 with size %zu\n",
3167-
fw->size);
3168+
m3_len);
31683169
ret = -ENOMEM;
31693170
goto out;
31703171
}
31713172

3173+
m3_mem->total_size = m3_len;
3174+
31723175
skip_m3_alloc:
31733176
memcpy(m3_mem->vaddr, m3_data, m3_len);
31743177
m3_mem->size = m3_len;

drivers/net/wireless/ath/ath12k/qmi.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* SPDX-License-Identifier: BSD-3-Clause-Clear */
22
/*
33
* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4-
* Copyright (c) 2021-2025 Qualcomm Innovation Center, Inc. All rights reserved.
4+
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
55
*/
66

77
#ifndef ATH12K_QMI_H
@@ -120,6 +120,9 @@ struct target_info {
120120
};
121121

122122
struct m3_mem_region {
123+
/* total memory allocated */
124+
u32 total_size;
125+
/* actual memory being used */
123126
u32 size;
124127
dma_addr_t paddr;
125128
void *vaddr;

0 commit comments

Comments
 (0)