Smatch reported memory leak bug in rtl8723b_FirmwareDownload function.
The problem is pFirmware memory is not released in release_fw1.
Instead of redirecting to release_fw1 we can turn it into exit
and free the memory.
Signed-off-by: F.A. SULAIMAN <[email protected]>
---
drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
index de8caa6cd418..b59c2aa3a9d8 100644
--- a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
+++ b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
@@ -436,7 +436,7 @@ s32 rtl8723b_FirmwareDownload(struct adapter *padapter, bool bUsedWoWLANFw)
if (pFirmware->fw_length > FW_8723B_SIZE) {
rtStatus = _FAIL;
DBG_871X_LEVEL(_drv_emerg_, "Firmware size:%u exceed %u\n", pFirmware->fw_length, FW_8723B_SIZE);
- goto release_fw1;
+ goto exit;
}
pFirmwareBuf = pFirmware->fw_buffer_sz;
@@ -512,7 +512,6 @@ s32 rtl8723b_FirmwareDownload(struct adapter *padapter, bool bUsedWoWLANFw)
exit:
kfree(pFirmware->fw_buffer_sz);
kfree(pFirmware);
-release_fw1:
kfree(pBTFirmware);
DBG_871X(" <=== rtl8723b_FirmwareDownload()\n");
return rtStatus;
--
2.17.1
On Tue, Aug 31, 2021 at 01:03:55AM +0530, F.A.Sulaiman wrote:
> Smatch reported memory leak bug in rtl8723b_FirmwareDownload function.
> The problem is pFirmware memory is not released in release_fw1.
> Instead of redirecting to release_fw1 we can turn it into exit
> and free the memory.
>
> Signed-off-by: F.A. SULAIMAN <[email protected]>
> ---
> drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
> index de8caa6cd418..b59c2aa3a9d8 100644
> --- a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
> +++ b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
> @@ -436,7 +436,7 @@ s32 rtl8723b_FirmwareDownload(struct adapter *padapter, bool bUsedWoWLANFw)
> if (pFirmware->fw_length > FW_8723B_SIZE) {
> rtStatus = _FAIL;
> DBG_871X_LEVEL(_drv_emerg_, "Firmware size:%u exceed %u\n", pFirmware->fw_length, FW_8723B_SIZE);
> - goto release_fw1;
> + goto exit;
> }
The current tree doesn't have DBG_871X_LEVEL() so you must be working
against something old. You need to work against linux-next or staging
next.
Your patch fixes a bug, but it would be better to just re-write the
error handling for this function. There is another bug that a bunch
of error paths don't call release_firmware(fw). Use the "Free the Last
Thing" method.
pFirmware = kzalloc(sizeof(struct rt_firmware), GFP_KERNEL);
if (!pFirmware)
return _FAIL;
The last thing we allocated is "pFirmware" so free that if we have an
error.
pBTFirmware = kzalloc(sizeof(struct rt_firmware), GFP_KERNEL);
if (!pBTFirmware) {
rtStatus = _FAIL;
goto free_firmware;
}
Now the last thing is pBTFirmware.
rtStatus = request_firmware(&fw, fwfilepath, device);
if (rtStatus) {
rtStatus = _FAIL;
goto free_bt_firmware;
}
Now the last thing is "fw". But this is a bit tricky because we're
going to release it as soon as possible and not wait until the end of
the function. There isn't a reason for this... We can change that or
keep it as-is. If we keep it as is, then the we'll just call
release_firmware(fw); before the goto free_bt_firmware; The current
code leaks fw on a bunch of error paths.
pFirmware->fw_buffer_sz = kmemdup(fw->data, fw->size, GFP_KERNEL);
if (!pFirmware->fw_buffer_sz) {
rtStatus = _FAIL;
release_firmware(fw);
goto free_bt_firmware;
}
Or:
pFirmware->fw_buffer_sz = kmemdup(fw->data, fw->size, GFP_KERNEL);
if (!pFirmware->fw_buffer_sz) {
rtStatus = _FAIL;
goto release_fw;
}
Now the last thing is pFirmware->fw_buffer_sz. Etc.
Then at the end it's just:
free_fw_buffer:
kfree(pFirmware->fw_buffer_sz);
release_fw:
release_firmware(fw);
free_bt_firmware:
kfree(pBTFirmware);
free_firmware:
kfree(pFirmware);
return rtStatus;
}
regards,
dan carpenter
On Tue, Aug 31, 2021 at 2:18 PM Dan Carpenter <[email protected]> wrote:
>
> On Tue, Aug 31, 2021 at 01:03:55AM +0530, F.A.Sulaiman wrote:
> > Smatch reported memory leak bug in rtl8723b_FirmwareDownload function.
> > The problem is pFirmware memory is not released in release_fw1.
> > Instead of redirecting to release_fw1 we can turn it into exit
> > and free the memory.
> >
> > Signed-off-by: F.A. SULAIMAN <[email protected]>
> > ---
> > drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
> > index de8caa6cd418..b59c2aa3a9d8 100644
> > --- a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
> > +++ b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
> > @@ -436,7 +436,7 @@ s32 rtl8723b_FirmwareDownload(struct adapter *padapter, bool bUsedWoWLANFw)
> > if (pFirmware->fw_length > FW_8723B_SIZE) {
> > rtStatus = _FAIL;
> > DBG_871X_LEVEL(_drv_emerg_, "Firmware size:%u exceed %u\n", pFirmware->fw_length, FW_8723B_SIZE);
> > - goto release_fw1;
> > + goto exit;
> > }
>
> The current tree doesn't have DBG_871X_LEVEL() so you must be working
> against something old. You need to work against linux-next or staging
> next.
>
> Your patch fixes a bug, but it would be better to just re-write the
> error handling for this function. There is another bug that a bunch
> of error paths don't call release_firmware(fw). Use the "Free the Last
> Thing" method.
>
> pFirmware = kzalloc(sizeof(struct rt_firmware), GFP_KERNEL);
> if (!pFirmware)
> return _FAIL;
>
> The last thing we allocated is "pFirmware" so free that if we have an
> error.
>
> pBTFirmware = kzalloc(sizeof(struct rt_firmware), GFP_KERNEL);
> if (!pBTFirmware) {
> rtStatus = _FAIL;
> goto free_firmware;
> }
>
> Now the last thing is pBTFirmware.
>
> rtStatus = request_firmware(&fw, fwfilepath, device);
> if (rtStatus) {
> rtStatus = _FAIL;
> goto free_bt_firmware;
> }
>
> Now the last thing is "fw". But this is a bit tricky because we're
> going to release it as soon as possible and not wait until the end of
> the function. There isn't a reason for this... We can change that or
> keep it as-is. If we keep it as is, then the we'll just call
> release_firmware(fw); before the goto free_bt_firmware; The current
> code leaks fw on a bunch of error paths.
>
> pFirmware->fw_buffer_sz = kmemdup(fw->data, fw->size, GFP_KERNEL);
> if (!pFirmware->fw_buffer_sz) {
> rtStatus = _FAIL;
> release_firmware(fw);
> goto free_bt_firmware;
> }
>
> Or:
>
> pFirmware->fw_buffer_sz = kmemdup(fw->data, fw->size, GFP_KERNEL);
> if (!pFirmware->fw_buffer_sz) {
> rtStatus = _FAIL;
> goto release_fw;
> }
>
> Now the last thing is pFirmware->fw_buffer_sz. Etc.
>
> Then at the end it's just:
>
> free_fw_buffer:
> kfree(pFirmware->fw_buffer_sz);
> release_fw:
> release_firmware(fw);
> free_bt_firmware:
> kfree(pBTFirmware);
> free_firmware:
> kfree(pFirmware);
>
> return rtStatus;
> }
>
Thank you! I'll do the changes and send you a v2 patch.
Best Regards,
Asha Sulaiman.
Smatch reported memory leak bug in rtl8723b_FirmwareDownload function.
The problem is pFirmware memory is not released in 'release_fw1'.
Instead of redirecting to 'release_fw1', we can turn it into 'exit'
and free the memory.
Signed-off-by: F.A. SULAIMAN <[email protected]>
---
drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
index f1fc077ed29c..5f09b3ef9459 100644
--- a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
+++ b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
@@ -361,7 +361,7 @@ s32 rtl8723b_FirmwareDownload(struct adapter *padapter, bool bUsedWoWLANFw)
netdev_emerg(padapter->pnetdev,
"Firmware size:%u exceed %u\n",
pFirmware->fw_length, FW_8723B_SIZE);
- goto release_fw1;
+ goto exit;
}
pFirmwareBuf = pFirmware->fw_buffer_sz;
--
2.17.1
On Wed, Jan 05, 2022 at 06:04:47PM +0530, F.A.Sulaiman wrote:
> Smatch reported memory leak bug in rtl8723b_FirmwareDownload function.
> The problem is pFirmware memory is not released in 'release_fw1'.
> Instead of redirecting to 'release_fw1', we can turn it into 'exit'
> and free the memory.
>
> Signed-off-by: F.A. SULAIMAN <[email protected]>
> ---
Please say what changed in between v1 and v2 here, below the --- cut
off line.
> drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
> index f1fc077ed29c..5f09b3ef9459 100644
> --- a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
> +++ b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
> @@ -361,7 +361,7 @@ s32 rtl8723b_FirmwareDownload(struct adapter *padapter, bool bUsedWoWLANFw)
> netdev_emerg(padapter->pnetdev,
> "Firmware size:%u exceed %u\n",
> pFirmware->fw_length, FW_8723B_SIZE);
> - goto release_fw1;
> + goto exit;
I replied to the v1 version of this patch to say that this path needs
to call release_firmware(). That's true, although my proposed solution
introduced a double free. The better way in this case is to call
release_firmware() before the goto. The pattern is "unwind temporary
things and partial iterations before the goto".
The other stuff that I said in my email is still correct. Just re-write
the error handling completely. No point in me reviewing the function
every couple weeks when we could easily just fix it instead.
regards,
dan carpenter
Hi "F.A.Sulaiman",
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on staging/staging-testing]
[also build test WARNING on v5.16-rc8 next-20220106]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/F-A-Sulaiman/rtl8723bs-fix-memory-leak-error/20220105-203752
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 0640d18b15d86ab76275e63f36f5841db5f52e74
config: hexagon-allyesconfig (https://download.01.org/0day-ci/archive/20220107/[email protected]/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project d5b6e30ed3acad794dd0aec400e617daffc6cc3d)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/1a1faafe5fcac0069aad1036ce1757e87ba847d3
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review F-A-Sulaiman/rtl8723bs-fix-memory-leak-error/20220105-203752
git checkout 1a1faafe5fcac0069aad1036ce1757e87ba847d3
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/mmc/host/ drivers/staging/rtl8723bs/ fs/xfs/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
All warnings (new ones prefixed by >>):
>> drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c:421:1: warning: unused label 'release_fw1' [-Wunused-label]
release_fw1:
^~~~~~~~~~~~
drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c:957:5: warning: variable 'hoffset' set but not used [-Wunused-but-set-variable]
u8 hoffset = 0, hworden = 0;
^
drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c:1050:5: warning: variable 'hoffset' set but not used [-Wunused-but-set-variable]
u8 hoffset = 0, hworden = 0;
^
3 warnings generated.
vim +/release_fw1 +421 drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
554c0a3abf216c Hans de Goede 2017-03-29 286
554c0a3abf216c Hans de Goede 2017-03-29 287 /* */
554c0a3abf216c Hans de Goede 2017-03-29 288 /* Description: */
554c0a3abf216c Hans de Goede 2017-03-29 289 /* Download 8192C firmware code. */
554c0a3abf216c Hans de Goede 2017-03-29 290 /* */
554c0a3abf216c Hans de Goede 2017-03-29 291 /* */
554c0a3abf216c Hans de Goede 2017-03-29 292 s32 rtl8723b_FirmwareDownload(struct adapter *padapter, bool bUsedWoWLANFw)
554c0a3abf216c Hans de Goede 2017-03-29 293 {
554c0a3abf216c Hans de Goede 2017-03-29 294 s32 rtStatus = _SUCCESS;
554c0a3abf216c Hans de Goede 2017-03-29 295 u8 write_fw = 0;
554c0a3abf216c Hans de Goede 2017-03-29 296 unsigned long fwdl_start_time;
554c0a3abf216c Hans de Goede 2017-03-29 297 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
554c0a3abf216c Hans de Goede 2017-03-29 298 struct rt_firmware *pFirmware;
554c0a3abf216c Hans de Goede 2017-03-29 299 struct rt_firmware *pBTFirmware;
554c0a3abf216c Hans de Goede 2017-03-29 300 struct rt_firmware_hdr *pFwHdr = NULL;
554c0a3abf216c Hans de Goede 2017-03-29 301 u8 *pFirmwareBuf;
554c0a3abf216c Hans de Goede 2017-03-29 302 u32 FirmwareLen;
554c0a3abf216c Hans de Goede 2017-03-29 303 const struct firmware *fw;
554c0a3abf216c Hans de Goede 2017-03-29 304 struct device *device = dvobj_to_dev(padapter->dvobj);
554c0a3abf216c Hans de Goede 2017-03-29 305 u8 *fwfilepath;
554c0a3abf216c Hans de Goede 2017-03-29 306 struct dvobj_priv *psdpriv = padapter->dvobj;
554c0a3abf216c Hans de Goede 2017-03-29 307 struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
554c0a3abf216c Hans de Goede 2017-03-29 308 u8 tmp_ps;
554c0a3abf216c Hans de Goede 2017-03-29 309
554c0a3abf216c Hans de Goede 2017-03-29 310 pFirmware = kzalloc(sizeof(struct rt_firmware), GFP_KERNEL);
7e2b0aaec63351 Larry Finger 2017-04-08 311 if (!pFirmware)
7e2b0aaec63351 Larry Finger 2017-04-08 312 return _FAIL;
554c0a3abf216c Hans de Goede 2017-03-29 313 pBTFirmware = kzalloc(sizeof(struct rt_firmware), GFP_KERNEL);
7e2b0aaec63351 Larry Finger 2017-04-08 314 if (!pBTFirmware) {
7e2b0aaec63351 Larry Finger 2017-04-08 315 kfree(pFirmware);
7e2b0aaec63351 Larry Finger 2017-04-08 316 return _FAIL;
554c0a3abf216c Hans de Goede 2017-03-29 317 }
554c0a3abf216c Hans de Goede 2017-03-29 318 tmp_ps = rtw_read8(padapter, 0xa3);
554c0a3abf216c Hans de Goede 2017-03-29 319 tmp_ps &= 0xf8;
554c0a3abf216c Hans de Goede 2017-03-29 320 tmp_ps |= 0x02;
554c0a3abf216c Hans de Goede 2017-03-29 321 /* 1. write 0xA3[:2:0] = 3b'010 */
554c0a3abf216c Hans de Goede 2017-03-29 322 rtw_write8(padapter, 0xa3, tmp_ps);
554c0a3abf216c Hans de Goede 2017-03-29 323 /* 2. read power_state = 0xA0[1:0] */
554c0a3abf216c Hans de Goede 2017-03-29 324 tmp_ps = rtw_read8(padapter, 0xa0);
554c0a3abf216c Hans de Goede 2017-03-29 325 tmp_ps &= 0x03;
709c8e49b51c37 Fabio Aiuto 2021-04-07 326 if (tmp_ps != 0x01)
554c0a3abf216c Hans de Goede 2017-03-29 327 pdbgpriv->dbg_downloadfw_pwr_state_cnt++;
554c0a3abf216c Hans de Goede 2017-03-29 328
554c0a3abf216c Hans de Goede 2017-03-29 329 fwfilepath = "rtlwifi/rtl8723bs_nic.bin";
554c0a3abf216c Hans de Goede 2017-03-29 330
b388285205609c Colin Ian King 2017-04-11 331 pr_info("rtl8723bs: acquire FW from file:%s\n", fwfilepath);
554c0a3abf216c Hans de Goede 2017-03-29 332
554c0a3abf216c Hans de Goede 2017-03-29 333 rtStatus = request_firmware(&fw, fwfilepath, device);
554c0a3abf216c Hans de Goede 2017-03-29 334 if (rtStatus) {
554c0a3abf216c Hans de Goede 2017-03-29 335 pr_err("Request firmware failed with error 0x%x\n", rtStatus);
554c0a3abf216c Hans de Goede 2017-03-29 336 rtStatus = _FAIL;
554c0a3abf216c Hans de Goede 2017-03-29 337 goto exit;
554c0a3abf216c Hans de Goede 2017-03-29 338 }
554c0a3abf216c Hans de Goede 2017-03-29 339
554c0a3abf216c Hans de Goede 2017-03-29 340 if (!fw) {
554c0a3abf216c Hans de Goede 2017-03-29 341 pr_err("Firmware %s not available\n", fwfilepath);
554c0a3abf216c Hans de Goede 2017-03-29 342 rtStatus = _FAIL;
554c0a3abf216c Hans de Goede 2017-03-29 343 goto exit;
554c0a3abf216c Hans de Goede 2017-03-29 344 }
554c0a3abf216c Hans de Goede 2017-03-29 345
554c0a3abf216c Hans de Goede 2017-03-29 346 if (fw->size > FW_8723B_SIZE) {
554c0a3abf216c Hans de Goede 2017-03-29 347 rtStatus = _FAIL;
554c0a3abf216c Hans de Goede 2017-03-29 348 goto exit;
554c0a3abf216c Hans de Goede 2017-03-29 349 }
554c0a3abf216c Hans de Goede 2017-03-29 350
93998817a169c0 Quytelda Kahja 2018-05-22 351 pFirmware->fw_buffer_sz = kmemdup(fw->data, fw->size, GFP_KERNEL);
93998817a169c0 Quytelda Kahja 2018-05-22 352 if (!pFirmware->fw_buffer_sz) {
554c0a3abf216c Hans de Goede 2017-03-29 353 rtStatus = _FAIL;
554c0a3abf216c Hans de Goede 2017-03-29 354 goto exit;
554c0a3abf216c Hans de Goede 2017-03-29 355 }
554c0a3abf216c Hans de Goede 2017-03-29 356
93998817a169c0 Quytelda Kahja 2018-05-22 357 pFirmware->fw_length = fw->size;
554c0a3abf216c Hans de Goede 2017-03-29 358 release_firmware(fw);
93998817a169c0 Quytelda Kahja 2018-05-22 359 if (pFirmware->fw_length > FW_8723B_SIZE) {
554c0a3abf216c Hans de Goede 2017-03-29 360 rtStatus = _FAIL;
79df841b435018 Fabio Aiuto 2021-04-15 361 netdev_emerg(padapter->pnetdev,
79df841b435018 Fabio Aiuto 2021-04-15 362 "Firmware size:%u exceed %u\n",
79df841b435018 Fabio Aiuto 2021-04-15 363 pFirmware->fw_length, FW_8723B_SIZE);
1a1faafe5fcac0 F.A.Sulaiman 2022-01-05 364 goto exit;
554c0a3abf216c Hans de Goede 2017-03-29 365 }
554c0a3abf216c Hans de Goede 2017-03-29 366
93998817a169c0 Quytelda Kahja 2018-05-22 367 pFirmwareBuf = pFirmware->fw_buffer_sz;
93998817a169c0 Quytelda Kahja 2018-05-22 368 FirmwareLen = pFirmware->fw_length;
554c0a3abf216c Hans de Goede 2017-03-29 369
554c0a3abf216c Hans de Goede 2017-03-29 370 /* To Check Fw header. Added by tynli. 2009.12.04. */
554c0a3abf216c Hans de Goede 2017-03-29 371 pFwHdr = (struct rt_firmware_hdr *)pFirmwareBuf;
554c0a3abf216c Hans de Goede 2017-03-29 372
699ad73456d6c9 Quytelda Kahja 2018-05-22 373 pHalData->FirmwareVersion = le16_to_cpu(pFwHdr->version);
699ad73456d6c9 Quytelda Kahja 2018-05-22 374 pHalData->FirmwareSubVersion = le16_to_cpu(pFwHdr->subversion);
699ad73456d6c9 Quytelda Kahja 2018-05-22 375 pHalData->FirmwareSignature = le16_to_cpu(pFwHdr->signature);
554c0a3abf216c Hans de Goede 2017-03-29 376
554c0a3abf216c Hans de Goede 2017-03-29 377 if (IS_FW_HEADER_EXIST_8723B(pFwHdr)) {
554c0a3abf216c Hans de Goede 2017-03-29 378 /* Shift 32 bytes for FW header */
554c0a3abf216c Hans de Goede 2017-03-29 379 pFirmwareBuf = pFirmwareBuf + 32;
554c0a3abf216c Hans de Goede 2017-03-29 380 FirmwareLen = FirmwareLen - 32;
554c0a3abf216c Hans de Goede 2017-03-29 381 }
554c0a3abf216c Hans de Goede 2017-03-29 382
554c0a3abf216c Hans de Goede 2017-03-29 383 /* Suggested by Filen. If 8051 is running in RAM code, driver should inform Fw to reset by itself, */
554c0a3abf216c Hans de Goede 2017-03-29 384 /* or it will cause download Fw fail. 2010.02.01. by tynli. */
554c0a3abf216c Hans de Goede 2017-03-29 385 if (rtw_read8(padapter, REG_MCUFWDL) & RAM_DL_SEL) { /* 8051 RAM code */
554c0a3abf216c Hans de Goede 2017-03-29 386 rtw_write8(padapter, REG_MCUFWDL, 0x00);
554c0a3abf216c Hans de Goede 2017-03-29 387 rtl8723b_FirmwareSelfReset(padapter);
554c0a3abf216c Hans de Goede 2017-03-29 388 }
554c0a3abf216c Hans de Goede 2017-03-29 389
554c0a3abf216c Hans de Goede 2017-03-29 390 _FWDownloadEnable(padapter, true);
554c0a3abf216c Hans de Goede 2017-03-29 391 fwdl_start_time = jiffies;
554c0a3abf216c Hans de Goede 2017-03-29 392 while (
554c0a3abf216c Hans de Goede 2017-03-29 393 !padapter->bDriverStopped &&
554c0a3abf216c Hans de Goede 2017-03-29 394 !padapter->bSurpriseRemoved &&
554c0a3abf216c Hans de Goede 2017-03-29 395 (write_fw++ < 3 || jiffies_to_msecs(jiffies - fwdl_start_time) < 500)
554c0a3abf216c Hans de Goede 2017-03-29 396 ) {
554c0a3abf216c Hans de Goede 2017-03-29 397 /* reset FWDL chksum */
554c0a3abf216c Hans de Goede 2017-03-29 398 rtw_write8(padapter, REG_MCUFWDL, rtw_read8(padapter, REG_MCUFWDL)|FWDL_ChkSum_rpt);
554c0a3abf216c Hans de Goede 2017-03-29 399
554c0a3abf216c Hans de Goede 2017-03-29 400 rtStatus = _WriteFW(padapter, pFirmwareBuf, FirmwareLen);
554c0a3abf216c Hans de Goede 2017-03-29 401 if (rtStatus != _SUCCESS)
554c0a3abf216c Hans de Goede 2017-03-29 402 continue;
554c0a3abf216c Hans de Goede 2017-03-29 403
554c0a3abf216c Hans de Goede 2017-03-29 404 rtStatus = polling_fwdl_chksum(padapter, 5, 50);
554c0a3abf216c Hans de Goede 2017-03-29 405 if (rtStatus == _SUCCESS)
554c0a3abf216c Hans de Goede 2017-03-29 406 break;
554c0a3abf216c Hans de Goede 2017-03-29 407 }
554c0a3abf216c Hans de Goede 2017-03-29 408 _FWDownloadEnable(padapter, false);
554c0a3abf216c Hans de Goede 2017-03-29 409 if (_SUCCESS != rtStatus)
554c0a3abf216c Hans de Goede 2017-03-29 410 goto fwdl_stat;
554c0a3abf216c Hans de Goede 2017-03-29 411
554c0a3abf216c Hans de Goede 2017-03-29 412 rtStatus = _FWFreeToGo(padapter, 10, 200);
554c0a3abf216c Hans de Goede 2017-03-29 413 if (_SUCCESS != rtStatus)
554c0a3abf216c Hans de Goede 2017-03-29 414 goto fwdl_stat;
554c0a3abf216c Hans de Goede 2017-03-29 415
554c0a3abf216c Hans de Goede 2017-03-29 416 fwdl_stat:
554c0a3abf216c Hans de Goede 2017-03-29 417
554c0a3abf216c Hans de Goede 2017-03-29 418 exit:
93998817a169c0 Quytelda Kahja 2018-05-22 419 kfree(pFirmware->fw_buffer_sz);
554c0a3abf216c Hans de Goede 2017-03-29 420 kfree(pFirmware);
7e2b0aaec63351 Larry Finger 2017-04-08 @421 release_fw1:
554c0a3abf216c Hans de Goede 2017-03-29 422 kfree(pBTFirmware);
554c0a3abf216c Hans de Goede 2017-03-29 423 return rtStatus;
554c0a3abf216c Hans de Goede 2017-03-29 424 }
554c0a3abf216c Hans de Goede 2017-03-29 425
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]