[PATCH 1/3] staging: rtl8188eu: remove _rtl88e_fill_dummy

From: Ivan Safonov
Date: Thu Feb 11 2016 - 13:25:04 EST


The _rtl88e_fill_dummy function replaced by memset in rtl88eu_download_fw.

More appropriate names are used for pfwdata and fwsize variables
(download_data and download_size respectively).

Also u32 replaced by size_t for download_size variable.

Signed-off-by: Ivan Safonov <insafonov@xxxxxxxxx>
---
drivers/staging/rtl8188eu/hal/fw.c | 45 +++++++++++++++++---------------------
1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/rtl8188eu/hal/fw.c b/drivers/staging/rtl8188eu/hal/fw.c
index 4d72537..25cecae 100644
--- a/drivers/staging/rtl8188eu/hal/fw.c
+++ b/drivers/staging/rtl8188eu/hal/fw.c
@@ -75,16 +75,6 @@ static void _rtl88e_fw_block_write(struct adapter *adapt,
usb_write8(adapt, write_address, byte_buffer[i]);
}

-static void _rtl88e_fill_dummy(u8 *pfwbuf, u32 *pfwlen)
-{
- u32 i;
-
- for (i = *pfwlen; i < roundup(*pfwlen, 4); i++)
- pfwbuf[i] = 0;
-
- *pfwlen = i;
-}
-
static void _rtl88e_fw_page_write(struct adapter *adapt,
u32 page, const u8 *buffer, u32 size)
{
@@ -103,8 +93,6 @@ static void _rtl88e_write_fw(struct adapter *adapt, u8 *buffer, u32 size)
u32 page_no, remain;
u32 page, offset;

- _rtl88e_fill_dummy(buf_ptr, &size);
-
page_no = size / FW_8192C_PAGE_SIZE;
remain = size % FW_8192C_PAGE_SIZE;

@@ -176,8 +164,9 @@ int rtl88eu_download_fw(struct adapter *adapt)
const struct firmware *fw;
const char fw_name[] = "rtlwifi/rtl8188eufw.bin";
struct rtl92c_firmware_header *pfwheader = NULL;
- u8 *pfwdata;
- u32 fwsize;
+ u8 *download_data;
+ size_t download_size;
+ unsigned int trailing_zeros_length;

if (request_firmware(&fw, fw_name, device)) {
dev_err(device, "Firmware %s not available\n", fw_name);
@@ -186,34 +175,40 @@ int rtl88eu_download_fw(struct adapter *adapt)

if (fw->size > FW_8188E_SIZE) {
dev_err(device, "Firmware size exceed 0x%X. Check it.\n",
- FW_8188E_SIZE);
+ FW_8188E_SIZE);
return -1;
}

- pfwdata = kzalloc(FW_8188E_SIZE, GFP_KERNEL);
- if (!pfwdata)
+ trailing_zeros_length = (4 - fw->size % 4) % 4;
+
+ rtlhal->fwsize = fw->size;
+ rtlhal->pfirmware = kmalloc(fw->size + trailing_zeros_length,
+ GFP_KERNEL);
+ if (!rtlhal->pfirmware)
return -ENOMEM;

- rtlhal->pfirmware = pfwdata;
memcpy(rtlhal->pfirmware, fw->data, fw->size);
- rtlhal->fwsize = fw->size;
- release_firmware(fw);
+ memset(rtlhal->pfirmware + fw->size, 0, trailing_zeros_length);

- fwsize = rtlhal->fwsize;
- pfwheader = (struct rtl92c_firmware_header *)pfwdata;
+ pfwheader = (struct rtl92c_firmware_header *)rtlhal->pfirmware;

if (IS_FW_HEADER_EXIST(pfwheader)) {
- pfwdata = pfwdata + 32;
- fwsize = fwsize - 32;
+ download_data = rtlhal->pfirmware + 32;
+ download_size = fw->size + trailing_zeros_length - 32;
+ } else {
+ download_data = rtlhal->pfirmware;
+ download_size = fw->size + trailing_zeros_length;
}

+ release_firmware(fw);
+
if (usb_read8(adapt, REG_MCUFWDL) & RAM_DL_SEL) {
usb_write8(adapt, REG_MCUFWDL, 0);
rtl88e_firmware_selfreset(adapt);
}
_rtl88e_enable_fw_download(adapt, true);
usb_write8(adapt, REG_MCUFWDL, usb_read8(adapt, REG_MCUFWDL) | FWDL_ChkSum_rpt);
- _rtl88e_write_fw(adapt, pfwdata, fwsize);
+ _rtl88e_write_fw(adapt, download_data, download_size);
_rtl88e_enable_fw_download(adapt, false);

return _rtl88e_fw_free_to_go(adapt);
--
2.4.10