libertas: fix some memleaks in lbs_allocate_cmd_buffer
PATCH 1/1 libertas: fix some memleaks in lbs_allocate_cmd_buffer
In the for statement of lbs_allocate_cmd_buffer, if the allocation of cmdarray[i].cmdbuf fails, both cmdarray and cmdarray[i].cmdbuf needs to be freed. Otherwise, there will be memleaks in lbs_allocate_cmd_buffer.
Fixes 876c9d3aeb98 ("[PATCH] Marvell Libertas 8388 802.11b/g USB driver")
Signed-off-by Zhipeng Lu <[email protected]>
--- drivers/net/wireless/marvell/libertas/cmd.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/net/wireless/marvell/libertas/cmd.c +11 -2
@@ -1132,7 +1132,7 @@ int lbs_allocate_cmd_buffer(struct lbs_private *priv)if (!cmdarray[i].cmdbuf) {lbs_deb_host ("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n" ); ret =-1 ; - goto done; + goto free_cmd_array; } }
@@ -1140,8 +1140,17 @@ int lbs_allocate_cmd_buffer(struct lbs_private *priv)init_waitqueue_head (&cmdarray[i].cmdwait_q);lbs_cleanup_and_insert_cmd (priv, &cmdarray[i]); } - ret =0 ; +return 0 ; +free_cmd_array: +for (i =0 ; i <LBS_NUM_CMD_BUFFERS ; i++) { +if (cmdarray[i].cmdbuf) { +kfree (cmdarray[i].cmdbuf); + cmdarray[i].cmdbuf =NULL ; + } + } +kfree (priv->cmd_array); + priv->cmd_array =NULL ; done:return ret; }
Signature · 1 line
2.34.1
Re: wifi: libertas: fix some memleaks in lbs_allocate_cmd_buffer()
Quoted 6 lines · Zhipeng Lu
In the for statement of
lbs_allocate_cmd_buffer(), if the allocation of cmdarray[i].cmdbuf fails, both cmdarray and cmdarray[i].cmdbuf needs to be freed. Otherwise, there will be memleaks inlbs_allocate_cmd_buffer().Fixes 876c9d3aeb98 ("[PATCH] Marvell Libertas 8388 802.11b/g USB driver")Signed-off-by Zhipeng Lu <[email protected]>
Patch applied to wireless-next.git, thanks.
5f0e4aede01c wifi: libertas: fix some memleaks in lbs_allocate_cmd_buffer()
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches