Skip to content

Commit 5d5cd85

Browse files
MikeLooijmansKalle Valo
authored and
Kalle Valo
committed
rsi: Fix failure to load firmware after memory leak fix and fix the leak
Fixes commit eae79b4 ("rsi: fix memory leak in rsi_load_ta_instructions()") which stopped the driver from functioning. Firmware data has been allocated using vmalloc(), resulting in memory that cannot be used for DMA. Hence the firmware was first copied to a buffer allocated with kmalloc() in the original code. This patch reverts the commit and only calls "kfree()" to release the buffer after sending the data. This fixes the memory leak without breaking the driver. Add a comment to the kmemdup() calls to explain why this is done, and abort if memory allocation fails. Tested on a Topic Miami-Florida board which contains the rsi SDIO chip. Also added the same kfree() call to the USB glue driver. This was not tested on actual hardware though, as I only have the SDIO version. Fixes: eae79b4 ("rsi: fix memory leak in rsi_load_ta_instructions()") Signed-off-by: Mike Looijmans <[email protected]> Cc: [email protected] Signed-off-by: Kalle Valo <[email protected]>
1 parent f7c0af8 commit 5d5cd85

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

drivers/net/wireless/rsi/rsi_91x_sdio_ops.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ static int rsi_load_ta_instructions(struct rsi_common *common)
172172
(struct rsi_91x_sdiodev *)adapter->rsi_dev;
173173
u32 len;
174174
u32 num_blocks;
175+
const u8 *fw;
175176
const struct firmware *fw_entry = NULL;
176177
u32 block_size = dev->tx_blk_size;
177178
int status = 0;
@@ -200,6 +201,10 @@ static int rsi_load_ta_instructions(struct rsi_common *common)
200201
return status;
201202
}
202203

204+
/* Copy firmware into DMA-accessible memory */
205+
fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
206+
if (!fw)
207+
return -ENOMEM;
203208
len = fw_entry->size;
204209

205210
if (len % 4)
@@ -210,7 +215,8 @@ static int rsi_load_ta_instructions(struct rsi_common *common)
210215
rsi_dbg(INIT_ZONE, "%s: Instruction size:%d\n", __func__, len);
211216
rsi_dbg(INIT_ZONE, "%s: num blocks: %d\n", __func__, num_blocks);
212217

213-
status = rsi_copy_to_card(common, fw_entry->data, len, num_blocks);
218+
status = rsi_copy_to_card(common, fw, len, num_blocks);
219+
kfree(fw);
214220
release_firmware(fw_entry);
215221
return status;
216222
}

drivers/net/wireless/rsi/rsi_91x_usb_ops.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ static int rsi_load_ta_instructions(struct rsi_common *common)
146146
return status;
147147
}
148148

149+
/* Copy firmware into DMA-accessible memory */
149150
fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
151+
if (!fw)
152+
return -ENOMEM;
150153
len = fw_entry->size;
151154

152155
if (len % 4)
@@ -158,6 +161,7 @@ static int rsi_load_ta_instructions(struct rsi_common *common)
158161
rsi_dbg(INIT_ZONE, "%s: num blocks: %d\n", __func__, num_blocks);
159162

160163
status = rsi_copy_to_card(common, fw, len, num_blocks);
164+
kfree(fw);
161165
release_firmware(fw_entry);
162166
return status;
163167
}

0 commit comments

Comments
 (0)