2022-04-15 09:42:55

by Michael Straube

[permalink] [raw]
Subject: [PATCH v2 0/8] staging: r8188eu: fix and clean up some firmware code

This series fixes wrong size of struct rt_firmware_hdr in the first
patch and does some cleanups in rtl8188e_firmware_download() in the
other patches.

Tested on x86_64 with Inter-Tech DMG-02.

v2:
Added a patch to check size of struct rt_firmware_hdr at compile time.

Michael Straube (8):
staging: r8188eu: fix struct rt_firmware_hdr
staging: r8188eu: clean up comments in struct rt_firmware_hdr
staging: r8188eu: rename fields of struct rt_firmware_hdr
staging: r8188eu: use sizeof instead of hardcoded firmware header size
staging: r8188eu: remove variables from rtl8188e_firmware_download()
staging: r8188eu: always log firmware info
staging: r8188eu: check firmware header existence before access
staging: r8188eu: check rt_firmware_hdr size at compile time

drivers/staging/r8188eu/core/rtw_fw.c | 77 ++++++++++-----------------
1 file changed, 28 insertions(+), 49 deletions(-)

--
2.35.1


2022-04-16 00:37:38

by Larry Finger

[permalink] [raw]
Subject: Re: [PATCH v2 0/8] staging: r8188eu: fix and clean up some firmware code

On 4/14/22 05:43, Michael Straube wrote:
> This series fixes wrong size of struct rt_firmware_hdr in the first
> patch and does some cleanups in rtl8188e_firmware_download() in the
> other patches.
>
> Tested on x86_64 with Inter-Tech DMG-02.
>
> v2:
> Added a patch to check size of struct rt_firmware_hdr at compile time.

Please wait a while before submitting new versions until those of us in time
zones further west get a chance. My objections to the logging change still apply.

NACK

Larry

2022-04-16 00:38:54

by Michael Straube

[permalink] [raw]
Subject: [PATCH v2 1/8] staging: r8188eu: fix struct rt_firmware_hdr

The structure rt_firmware_hdr is wrong, there are two issues.

The first issue is that the size of struct rt_firmware_hdr is 33 bytes
but the header in the firmware file is 32 bytes long.

The hexdump of rtl8188eufw.bin shows that the field Rsvd1 of struct
rt_firmware_hdr should be u8 instead of __le16.

OFFSET rtl8188eufw.bin
-----------------------------------------------------------
0x00000000 E1 88 10 00 0B 00 01 00 01 21 11 27 30 36 00 00
0x00000010 2D 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00000020 02 45 4E 00 00 00 00 00 00 00 00 00 00 00 00 00

0x00000000 E1 88 10 00 0B 00 01 00 01 21 11 27 30 36 00 00
^ ^ ^ ^ ^ ^
Subversion Rsvd1 Month Date Hour Minute

This was figured out by looking at struct rtlwifi_firmware_header in
drivers/net/wireless/rtlwifi/wifi.h and the firmware file that the
rtlwifi/rtl8188ee driver uses.

The second issue is that the u16 and u32 fields sould be __le16 and
__le32.

Change the field Rsvd1 to u8 and the u16, u32 fileds to __le16, __le32.

Both issues had no effect because the header size is actually hardcoded
to 32 where it is used in the code. Also the fields after Subversion
are not used and the bytes of the u16 and u32 fields are all zero.

Fixes: 7884fc0a1473 ("staging: r8188eu: introduce new include dir for RTL8188eu driver")
Signed-off-by: Michael Straube <[email protected]>
---
drivers/staging/r8188eu/core/rtw_fw.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_fw.c b/drivers/staging/r8188eu/core/rtw_fw.c
index 8620f3c92b52..7cd08268f3b9 100644
--- a/drivers/staging/r8188eu/core/rtw_fw.c
+++ b/drivers/staging/r8188eu/core/rtw_fw.c
@@ -29,7 +29,7 @@ struct rt_firmware_hdr {
* FW for different conditions */
__le16 Version; /* FW Version */
u8 Subversion; /* FW Subversion, default 0x00 */
- u16 Rsvd1;
+ u8 Rsvd1;

/* LONG WORD 1 ---- */
u8 Month; /* Release time Month field */
@@ -42,11 +42,11 @@ struct rt_firmware_hdr {

/* LONG WORD 2 ---- */
__le32 SvnIdx; /* The SVN entry index */
- u32 Rsvd3;
+ __le32 Rsvd3;

/* LONG WORD 3 ---- */
- u32 Rsvd4;
- u32 Rsvd5;
+ __le32 Rsvd4;
+ __le32 Rsvd5;
};

static void fw_download_enable(struct adapter *padapter, bool enable)
--
2.35.1

2022-04-16 01:04:14

by Michael Straube

[permalink] [raw]
Subject: [PATCH v2 6/8] staging: r8188eu: always log firmware info

The local static variable log_version prevents logging the firmware
information more than once, e.g. when the device is unplugged and
plugged again. That is not necessary and complicates the code. Remove
it.

Signed-off-by: Michael Straube <[email protected]>
---
drivers/staging/r8188eu/core/rtw_fw.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_fw.c b/drivers/staging/r8188eu/core/rtw_fw.c
index cbc4980bd938..64963507a346 100644
--- a/drivers/staging/r8188eu/core/rtw_fw.c
+++ b/drivers/staging/r8188eu/core/rtw_fw.c
@@ -239,7 +239,6 @@ int rtl8188e_firmware_download(struct adapter *padapter)
struct rt_firmware_hdr *fwhdr = NULL;
u8 *fw_data;
u32 fw_size;
- static int log_version;

if (!dvobj->firmware.data)
ret = load_firmware(&dvobj->firmware, device);
@@ -253,10 +252,9 @@ int rtl8188e_firmware_download(struct adapter *padapter)
/* To Check Fw header. Added by tynli. 2009.12.04. */
fwhdr = (struct rt_firmware_hdr *)dvobj->firmware.data;

- if (!log_version++)
- pr_info("%sFirmware Version %d, SubVersion %d, Signature 0x%x\n",
- DRIVER_PREFIX, le16_to_cpu(fwhdr->version), fwhdr->subversion,
- le16_to_cpu(fwhdr->signature));
+ pr_info("%sFirmware Version %d, SubVersion %d, Signature 0x%x\n",
+ DRIVER_PREFIX, le16_to_cpu(fwhdr->version), fwhdr->subversion,
+ le16_to_cpu(fwhdr->signature));

if (IS_FW_HEADER_EXIST(fwhdr)) {
fw_data = fw_data + sizeof(struct rt_firmware_hdr);
--
2.35.1

2022-04-16 02:12:36

by Michael Straube

[permalink] [raw]
Subject: [PATCH v2 4/8] staging: r8188eu: use sizeof instead of hardcoded firmware header size

Use sizeof() instead of hardcoding the firmware header size.

Signed-off-by: Michael Straube <[email protected]>
---
drivers/staging/r8188eu/core/rtw_fw.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_fw.c b/drivers/staging/r8188eu/core/rtw_fw.c
index 3da52a1ba23c..94526064f29b 100644
--- a/drivers/staging/r8188eu/core/rtw_fw.c
+++ b/drivers/staging/r8188eu/core/rtw_fw.c
@@ -263,9 +263,8 @@ int rtl8188e_firmware_download(struct adapter *padapter)
DRIVER_PREFIX, fw_version, fw_subversion, fw_signature);

if (IS_FW_HEADER_EXIST(fwhdr)) {
- /* Shift 32 bytes for FW header */
- fw_data = fw_data + 32;
- fw_size = fw_size - 32;
+ fw_data = fw_data + sizeof(struct rt_firmware_hdr);
+ fw_size = fw_size - sizeof(struct rt_firmware_hdr);
}

/* Suggested by Filen. If 8051 is running in RAM code, driver should inform Fw to reset by itself, */
--
2.35.1