From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Xiaoke Wang <xkernel.wang@foxmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sasha Levin <sashal@kernel.org>,
kuba@kernel.org, hdegoede@redhat.com, macromorgan@hotmail.com,
chi.minghao@zte.com.cn, linux-staging@lists.linux.dev
Subject: [PATCH AUTOSEL 5.15 35/47] staging: rtl8723bs: fix potential memory leak in rtw_init_drv_sw()
Date: Wed, 12 Oct 2022 20:21:10 -0400 [thread overview]
Message-ID: <20221013002124.1894077-35-sashal@kernel.org> (raw)
In-Reply-To: <20221013002124.1894077-1-sashal@kernel.org>
From: Xiaoke Wang <xkernel.wang@foxmail.com>
[ Upstream commit 5a5aa9cce621e2c0e25a1e5d72d6be1749167cc0 ]
In rtw_init_drv_sw(), there are various init functions are called to
populate the padapter structure and some checks for their return value.
However, except for the first one error path, the other five error paths
do not properly release the previous allocated resources, which leads to
various memory leaks.
This patch fixes them and keeps the success and error separate.
Note that these changes keep the form of `rtw_init_drv_sw()` in
"drivers/staging/r8188eu/os_dep/os_intfs.c". As there is no proper device
to test with, no runtime testing was performed.
Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
Link: https://lore.kernel.org/r/tencent_C3B899D2FC3F1BC827F3552E0B0734056006@qq.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/staging/rtl8723bs/os_dep/os_intfs.c | 60 +++++++++++----------
1 file changed, 31 insertions(+), 29 deletions(-)
diff --git a/drivers/staging/rtl8723bs/os_dep/os_intfs.c b/drivers/staging/rtl8723bs/os_dep/os_intfs.c
index f78bf174de8e..23f4f706f935 100644
--- a/drivers/staging/rtl8723bs/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8723bs/os_dep/os_intfs.c
@@ -664,51 +664,36 @@ void rtw_reset_drv_sw(struct adapter *padapter)
u8 rtw_init_drv_sw(struct adapter *padapter)
{
- u8 ret8 = _SUCCESS;
-
rtw_init_default_value(padapter);
rtw_init_hal_com_default_value(padapter);
- if (rtw_init_cmd_priv(&padapter->cmdpriv)) {
- ret8 = _FAIL;
- goto exit;
- }
+ if (rtw_init_cmd_priv(&padapter->cmdpriv))
+ return _FAIL;
padapter->cmdpriv.padapter = padapter;
- if (rtw_init_evt_priv(&padapter->evtpriv)) {
- ret8 = _FAIL;
- goto exit;
- }
+ if (rtw_init_evt_priv(&padapter->evtpriv))
+ goto free_cmd_priv;
-
- if (rtw_init_mlme_priv(padapter) == _FAIL) {
- ret8 = _FAIL;
- goto exit;
- }
+ if (rtw_init_mlme_priv(padapter) == _FAIL)
+ goto free_evt_priv;
init_mlme_ext_priv(padapter);
- if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL) {
- ret8 = _FAIL;
- goto exit;
- }
+ if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL)
+ goto free_mlme_ext;
- if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL) {
- ret8 = _FAIL;
- goto exit;
- }
+ if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL)
+ goto free_xmit_priv;
/* add for CONFIG_IEEE80211W, none 11w also can use */
spin_lock_init(&padapter->security_key_mutex);
/* We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */
/* memset((unsigned char *)&padapter->securitypriv, 0, sizeof (struct security_priv)); */
- if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL) {
- ret8 = _FAIL;
- goto exit;
- }
+ if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL)
+ goto free_recv_priv;
padapter->stapriv.padapter = padapter;
padapter->setband = GHZ24_50;
@@ -719,9 +704,26 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
rtw_hal_dm_init(padapter);
-exit:
+ return _SUCCESS;
+
+free_recv_priv:
+ _rtw_free_recv_priv(&padapter->recvpriv);
+
+free_xmit_priv:
+ _rtw_free_xmit_priv(&padapter->xmitpriv);
+
+free_mlme_ext:
+ free_mlme_ext_priv(&padapter->mlmeextpriv);
- return ret8;
+ rtw_free_mlme_priv(&padapter->mlmepriv);
+
+free_evt_priv:
+ rtw_free_evt_priv(&padapter->evtpriv);
+
+free_cmd_priv:
+ rtw_free_cmd_priv(&padapter->cmdpriv);
+
+ return _FAIL;
}
void rtw_cancel_all_timer(struct adapter *padapter)
--
2.35.1
next prev parent reply other threads:[~2022-10-13 1:26 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-13 0:20 [PATCH AUTOSEL 5.15 01/47] clk: zynqmp: Fix stack-out-of-bounds in strncpy` Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 02/47] media: cx88: Fix a null-ptr-deref bug in buffer_prepare() Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 03/47] media: platform: fix some double free in meson-ge2d and mtk-jpeg and s5p-mfc Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 04/47] clk: zynqmp: pll: rectify rate rounding in zynqmp_pll_round_rate Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 05/47] usb: host: xhci-plat: suspend and resume clocks Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 06/47] usb: host: xhci-plat: suspend/resume clks for brcm Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 07/47] dmaengine: ti: k3-udma: Reset UDMA_CHAN_RT byte counters to prevent overflow Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 08/47] scsi: 3w-9xxx: Avoid disabling device if failing to enable it Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 09/47] nbd: Fix hung when signal interrupts nbd_start_device_ioctl() Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 10/47] iommu/arm-smmu-v3: Make default domain type of HiSilicon PTT device to identity Sasha Levin
2022-10-13 7:07 ` John Garry
2022-10-16 13:30 ` Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 11/47] staging: rtl8712: Fix return type for implementation of ndo_start_xmit Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 12/47] staging: rtl8192e: " Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 13/47] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 14/47] staging: vt6655: fix potential memory leak Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 15/47] blk-throttle: prevent overflow while calculating wait time Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 16/47] gpiolib: of: do not ignore requested index when applying quirks Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 17/47] gpiolib: of: make Freescale SPI quirk similar to all others Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 18/47] gpiolib: rework quirk handling in of_find_gpio() Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 19/47] ata: libahci_platform: Sanity check the DT child nodes number Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 20/47] bcache: fix set_at_max_writeback_rate() for multiple attached devices Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 21/47] soundwire: cadence: Don't overwrite msg->buf during write commands Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 22/47] soundwire: intel: fix error handling on dai registration issues Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 23/47] hid: topre: Add driver fixing report descriptor Sasha Levin
2022-10-13 0:20 ` [PATCH AUTOSEL 5.15 24/47] habanalabs: remove some f/w descriptor validations Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 25/47] HID: roccat: Fix use-after-free in roccat_read() Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 26/47] HSI: ssi_protocol: fix potential resource leak in ssip_pn_open() Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 27/47] eventfd: guard wake_up in eventfd fs calls as well Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 28/47] md/raid5: Wait for MD_SB_CHANGE_PENDING in raid5d Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 29/47] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 30/47] usb: musb: Fix musb_gadget.c rxstate overflow bug Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 31/47] arm64: dts: imx8mp: Add snps,gfladj-refclk-lpm-sel quirk to USB nodes Sasha Levin
2022-10-13 5:57 ` [PATCH AUTOSEL 5.15 31/47] arm64: dts: imx8mp: Add snps, gfladj-refclk-lpm-sel " Alexander Stein
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 32/47] usb: dwc3: core: Enable GUCTL1 bit 10 for fixing termination error after resume bug Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 33/47] Revert "usb: storage: Add quirk for Samsung Fit flash" Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 34/47] tty: n_gsm: replace use of gsm_read_ea() with gsm_read_ea_val() Sasha Levin
2022-10-13 6:21 ` Jiri Slaby
2022-10-16 13:27 ` Sasha Levin
2022-10-13 0:21 ` Sasha Levin [this message]
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 36/47] staging: rtl8723bs: fix a potential memory leak in rtw_init_cmd_priv() Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 37/47] staging: rtl8192u: Fix return type of ieee80211_xmit Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 38/47] staging: octeon: Fix return type of cvm_oct_xmit and cvm_oct_xmit_pow Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 39/47] scsi: tracing: Fix compile error in trace_array calls when TRACING is disabled Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 40/47] ext2: Use kvmalloc() for group descriptor array Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 41/47] nvme: copy firmware_rev on each init Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 42/47] nvmet-tcp: add bounds check on Transfer Tag Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 43/47] usb: idmouse: fix an uninit-value in idmouse_open Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 44/47] fsi: master-ast-cf: Fix missing of_node_put in fsi_master_acf_probe Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 45/47] sbitmap: fix lockup while swapping Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 46/47] clk: bcm2835: Make peripheral PLLC critical Sasha Levin
2022-10-13 0:21 ` [PATCH AUTOSEL 5.15 47/47] clk: bcm2835: Round UART input clock up Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221013002124.1894077-35-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=chi.minghao@zte.com.cn \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=macromorgan@hotmail.com \
--cc=stable@vger.kernel.org \
--cc=xkernel.wang@foxmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox