2022-04-15 13:22:07

by Michael Straube

[permalink] [raw]
Subject: [PATCH v3 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.

v3:
- Splitted the first patch into two separate patches.
- Added back logging the firmware version only once.
- Included the compile time check for size of rt_firmware from
patch 8/8 of v2 in the patch that replaces the hardcoded size.

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: convert u32 fields of rt_firmware_hdr to __le32
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: use pr_info_once() to log the firmware version
staging: r8188eu: check firmware header existence before access

drivers/staging/r8188eu/core/rtw_fw.c | 79 ++++++++++-----------------
1 file changed, 29 insertions(+), 50 deletions(-)

--
2.35.1


2022-04-16 00:15:56

by Michael Straube

[permalink] [raw]
Subject: [PATCH v3 7/8] staging: r8188eu: use pr_info_once() to log the firmware version

Use pr_info_once() instead of a static variable and an if statement
to log the firmware version only once.

Signed-off-by: Michael Straube <[email protected]>
---
v3:
- added back logging the firmware version only once, using
pr_info_once() instead of a static variable and if statement

v2:
- no changes

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 c102aba099f5..7ee72236c7f4 100644
--- a/drivers/staging/r8188eu/core/rtw_fw.c
+++ b/drivers/staging/r8188eu/core/rtw_fw.c
@@ -241,7 +241,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);
@@ -255,10 +254,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_once("%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 00:36:54

by Michael Straube

[permalink] [raw]
Subject: [PATCH v3 4/8] staging: r8188eu: rename fields of struct rt_firmware_hdr

Rename the fields of struct rt_firmware_hdr to avoid camel case.

Signed-off-by: Michael Straube <[email protected]>
---
v3:
- no changes

v2:
- no changes

drivers/staging/r8188eu/core/rtw_fw.c | 48 +++++++++++++--------------
1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_fw.c b/drivers/staging/r8188eu/core/rtw_fw.c
index 323e0c634c4e..3da52a1ba23c 100644
--- a/drivers/staging/r8188eu/core/rtw_fw.c
+++ b/drivers/staging/r8188eu/core/rtw_fw.c
@@ -9,29 +9,29 @@
#define MAX_PAGE_SIZE 4096

#define IS_FW_HEADER_EXIST(_fwhdr) \
- ((le16_to_cpu(_fwhdr->Signature) & 0xFFF0) == 0x92C0 || \
- (le16_to_cpu(_fwhdr->Signature) & 0xFFF0) == 0x88C0 || \
- (le16_to_cpu(_fwhdr->Signature) & 0xFFF0) == 0x2300 || \
- (le16_to_cpu(_fwhdr->Signature) & 0xFFF0) == 0x88E0)
+ ((le16_to_cpu(_fwhdr->signature) & 0xFFF0) == 0x92C0 || \
+ (le16_to_cpu(_fwhdr->signature) & 0xFFF0) == 0x88C0 || \
+ (le16_to_cpu(_fwhdr->signature) & 0xFFF0) == 0x2300 || \
+ (le16_to_cpu(_fwhdr->signature) & 0xFFF0) == 0x88E0)

struct rt_firmware_hdr {
- __le16 Signature;
- u8 Category;
- u8 Function;
- __le16 Version;
- u8 Subversion;
- u8 Rsvd1;
- u8 Month;
- u8 Date;
- u8 Hour;
- u8 Minute;
- __le16 RamCodeSize;
- u8 Foundry;
- u8 Rsvd2;
- __le32 SvnIdx;
- __le32 Rsvd3;
- __le32 Rsvd4;
- __le32 Rsvd5;
+ __le16 signature;
+ u8 category;
+ u8 function;
+ __le16 version;
+ u8 subversion;
+ u8 rsvd1;
+ u8 month;
+ u8 date;
+ u8 hour;
+ u8 minute;
+ __le16 ramcodesize;
+ u8 foundry;
+ u8 rsvd2;
+ __le32 svnidx;
+ __le32 rsvd3;
+ __le32 rsvd4;
+ __le32 rsvd5;
};

static void fw_download_enable(struct adapter *padapter, bool enable)
@@ -254,9 +254,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;

- fw_version = le16_to_cpu(fwhdr->Version);
- fw_subversion = fwhdr->Subversion;
- fw_signature = le16_to_cpu(fwhdr->Signature);
+ fw_version = le16_to_cpu(fwhdr->version);
+ fw_subversion = fwhdr->subversion;
+ fw_signature = le16_to_cpu(fwhdr->signature);

if (!log_version++)
pr_info("%sFirmware Version %d, SubVersion %d, Signature 0x%x\n",
--
2.35.1

2022-04-16 00:42:21

by Michael Straube

[permalink] [raw]
Subject: [PATCH v3 3/8] staging: r8188eu: clean up comments in struct rt_firmware_hdr

The comments in struct rt_firmware_hdr are not needed.
Remove them.

Signed-off-by: Michael Straube <[email protected]>
---
v3:
- no changes

v2:
- no changes

drivers/staging/r8188eu/core/rtw_fw.c | 37 ++++++++-------------------
1 file changed, 11 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_fw.c b/drivers/staging/r8188eu/core/rtw_fw.c
index 7cd08268f3b9..323e0c634c4e 100644
--- a/drivers/staging/r8188eu/core/rtw_fw.c
+++ b/drivers/staging/r8188eu/core/rtw_fw.c
@@ -14,37 +14,22 @@
(le16_to_cpu(_fwhdr->Signature) & 0xFFF0) == 0x2300 || \
(le16_to_cpu(_fwhdr->Signature) & 0xFFF0) == 0x88E0)

-/* This structure must be careful with byte-ordering */
-
struct rt_firmware_hdr {
- /* 8-byte alinment required */
- /* LONG WORD 0 ---- */
- __le16 Signature; /* 92C0: test chip; 92C,
- * 88C0: test chip; 88C1: MP A-cut;
- * 92C1: MP A-cut */
- u8 Category; /* AP/NIC and USB/PCI */
- u8 Function; /* Reserved for different FW function
- * indcation, for further use when
- * driver needs to download different
- * FW for different conditions */
- __le16 Version; /* FW Version */
- u8 Subversion; /* FW Subversion, default 0x00 */
+ __le16 Signature;
+ u8 Category;
+ u8 Function;
+ __le16 Version;
+ u8 Subversion;
u8 Rsvd1;
-
- /* LONG WORD 1 ---- */
- u8 Month; /* Release time Month field */
- u8 Date; /* Release time Date field */
- u8 Hour; /* Release time Hour field */
- u8 Minute; /* Release time Minute field */
- __le16 RamCodeSize; /* The size of RAM code */
+ u8 Month;
+ u8 Date;
+ u8 Hour;
+ u8 Minute;
+ __le16 RamCodeSize;
u8 Foundry;
u8 Rsvd2;
-
- /* LONG WORD 2 ---- */
- __le32 SvnIdx; /* The SVN entry index */
+ __le32 SvnIdx;
__le32 Rsvd3;
-
- /* LONG WORD 3 ---- */
__le32 Rsvd4;
__le32 Rsvd5;
};
--
2.35.1

2022-04-16 00:45:31

by Larry Finger

[permalink] [raw]
Subject: Re: [PATCH v3 3/8] staging: r8188eu: clean up comments in struct rt_firmware_hdr

On 4/15/22 07:10, Michael Straube wrote:
> The comments in struct rt_firmware_hdr are not needed.
> Remove them.
>
> Signed-off-by: Michael Straube <[email protected]>
> ---
> v3:
> - no changes
>
> v2:
> - no changes
>
> drivers/staging/r8188eu/core/rtw_fw.c | 37 ++++++++-------------------
> 1 file changed, 11 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/staging/r8188eu/core/rtw_fw.c b/drivers/staging/r8188eu/core/rtw_fw.c
> index 7cd08268f3b9..323e0c634c4e 100644
> --- a/drivers/staging/r8188eu/core/rtw_fw.c
> +++ b/drivers/staging/r8188eu/core/rtw_fw.c
> @@ -14,37 +14,22 @@
> (le16_to_cpu(_fwhdr->Signature) & 0xFFF0) == 0x2300 || \
> (le16_to_cpu(_fwhdr->Signature) & 0xFFF0) == 0x88E0)
>
> -/* This structure must be careful with byte-ordering */
> -
> struct rt_firmware_hdr {
> - /* 8-byte alinment required */
> - /* LONG WORD 0 ---- */
> - __le16 Signature; /* 92C0: test chip; 92C,
> - * 88C0: test chip; 88C1: MP A-cut;
> - * 92C1: MP A-cut */
> - u8 Category; /* AP/NIC and USB/PCI */
> - u8 Function; /* Reserved for different FW function
> - * indcation, for further use when
> - * driver needs to download different
> - * FW for different conditions */
> - __le16 Version; /* FW Version */
> - u8 Subversion; /* FW Subversion, default 0x00 */
> + __le16 Signature;
> + u8 Category;
> + u8 Function;
> + __le16 Version;
> + u8 Subversion;
> u8 Rsvd1;
> -
> - /* LONG WORD 1 ---- */
> - u8 Month; /* Release time Month field */
> - u8 Date; /* Release time Date field */
> - u8 Hour; /* Release time Hour field */
> - u8 Minute; /* Release time Minute field */
> - __le16 RamCodeSize; /* The size of RAM code */
> + u8 Month;
> + u8 Date;
> + u8 Hour;
> + u8 Minute;
> + __le16 RamCodeSize;
> u8 Foundry;
> u8 Rsvd2;
> -
> - /* LONG WORD 2 ---- */
> - __le32 SvnIdx; /* The SVN entry index */
> + __le32 SvnIdx;
> __le32 Rsvd3;
> -
> - /* LONG WORD 3 ---- */
> __le32 Rsvd4;
> __le32 Rsvd5;
> };

The comments "LONG WORD" are useless, but the comments describing the fields are
still useful. I do not like this patch.

Will your next step be stripping ALL comments from the driver? The source would
be a lot smaller that way! :)

Larry

2022-04-16 01:15:54

by Michael Straube

[permalink] [raw]
Subject: [PATCH v3 2/8] staging: r8188eu: convert u32 fields of rt_firmware_hdr to __le32

Convert the u32 fields of struct rt_firmware_hdr to __le32 for
consistency.

Signed-off-by: Michael Straube <[email protected]>
---
v3:
- this patch was part of patch 1/8 in v2

drivers/staging/r8188eu/core/rtw_fw.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_fw.c b/drivers/staging/r8188eu/core/rtw_fw.c
index eb4ab11f6b28..7cd08268f3b9 100644
--- a/drivers/staging/r8188eu/core/rtw_fw.c
+++ b/drivers/staging/r8188eu/core/rtw_fw.c
@@ -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:18:12

by Michael Straube

[permalink] [raw]
Subject: [PATCH v3 8/8] staging: r8188eu: check firmware header existence before access

We should access the fields of fwhdr only if the check for firmware
header existence is true. Move the affected code into the if block
that checks firmware header existence.

Signed-off-by: Michael Straube <[email protected]>
---
v3:
- no real changes,
just the pr_info() -> pr_info_once() from patch 7/8 is different

v2:
- no changes

drivers/staging/r8188eu/core/rtw_fw.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_fw.c b/drivers/staging/r8188eu/core/rtw_fw.c
index 7ee72236c7f4..8b5c67780a7b 100644
--- a/drivers/staging/r8188eu/core/rtw_fw.c
+++ b/drivers/staging/r8188eu/core/rtw_fw.c
@@ -251,14 +251,13 @@ int rtl8188e_firmware_download(struct adapter *padapter)
fw_data = dvobj->firmware.data;
fw_size = dvobj->firmware.size;

- /* To Check Fw header. Added by tynli. 2009.12.04. */
fwhdr = (struct rt_firmware_hdr *)dvobj->firmware.data;

- pr_info_once("%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)) {
+ pr_info_once("%sFirmware Version %d, SubVersion %d, Signature 0x%x\n",
+ DRIVER_PREFIX, le16_to_cpu(fwhdr->version), fwhdr->subversion,
+ le16_to_cpu(fwhdr->signature));
+
fw_data = fw_data + sizeof(struct rt_firmware_hdr);
fw_size = fw_size - sizeof(struct rt_firmware_hdr);
}
--
2.35.1

2022-04-16 02:00:58

by Michael Straube

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

Use sizeof() instead of hardcoding the firmware header size and add
a compile time check to ensure struct rt_firmware_hdr has the correct
size.

Signed-off-by: Michael Straube <[email protected]>
---
v3:
- added the compile time size check from patch 8/8 of v2

v2:
- no changes

drivers/staging/r8188eu/core/rtw_fw.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_fw.c b/drivers/staging/r8188eu/core/rtw_fw.c
index 3da52a1ba23c..0279af37719a 100644
--- a/drivers/staging/r8188eu/core/rtw_fw.c
+++ b/drivers/staging/r8188eu/core/rtw_fw.c
@@ -34,6 +34,8 @@ struct rt_firmware_hdr {
__le32 rsvd5;
};

+static_assert(sizeof(struct rt_firmware_hdr) == 32);
+
static void fw_download_enable(struct adapter *padapter, bool enable)
{
u8 tmp;
@@ -263,9 +265,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

2022-04-16 02:12:31

by Michael Straube

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

The size of struct rt_firmware_hdr is 36 bytes.

$ pahole -C rt_firmware_hdr drivers/staging/r8188eu/r8188eu.o
struct rt_firmware_hdr {
__le16 Signature; /* 0 2 */
u8 Category; /* 2 1 */
u8 Function; /* 3 1 */
__le16 Version; /* 4 2 */
u8 Subversion; /* 6 1 */

/* XXX 1 byte hole, try to pack */

u16 Rsvd1; /* 8 2 */
u8 Month; /* 10 1 */
u8 Date; /* 11 1 */
u8 Hour; /* 12 1 */
u8 Minute; /* 13 1 */
__le16 RamCodeSize; /* 14 2 */
u8 Foundry; /* 16 1 */
u8 Rsvd2; /* 17 1 */

/* XXX 2 bytes hole, try to pack */

__le32 SvnIdx; /* 20 4 */
u32 Rsvd3; /* 24 4 */
u32 Rsvd4; /* 28 4 */
u32 Rsvd5; /* 32 4 */

/* size: 36, cachelines: 1, members: 17 */
/* sum members: 33, holes: 2, sum holes: 3 */
/* last cacheline: 36 bytes */
};

But the header in the firmware file is only 32 bytes long.

The hexdump of rtl8188eufw.bin shows that the field Rsvd1 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

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

With the change of field Rsvd1 from __le16 to u8 the structure has the
correct size 32.

$ pahole -C rt_firmware_hdr drivers/staging/r8188eu/r8188eu.o
struct rt_firmware_hdr {
__le16 Signature; /* 0 2 */
u8 Category; /* 2 1 */
u8 Function; /* 3 1 */
__le16 Version; /* 4 2 */
u8 Subversion; /* 6 1 */
u8 Rsvd1; /* 7 1 */
u8 Month; /* 8 1 */
u8 Date; /* 9 1 */
u8 Hour; /* 10 1 */
u8 Minute; /* 11 1 */
__le16 RamCodeSize; /* 12 2 */
u8 Foundry; /* 14 1 */
u8 Rsvd2; /* 15 1 */
__le32 SvnIdx; /* 16 4 */
u32 Rsvd3; /* 20 4 */
u32 Rsvd4; /* 24 4 */
u32 Rsvd5; /* 28 4 */

/* size: 32, cachelines: 1, members: 17 */
/* last cacheline: 32 bytes */

The wrong size had no effect because the header size is hardcoded to
32 where it is used in the code and the fields after Subversion are
not used.

Fixes: 7884fc0a1473 ("staging: r8188eu: introduce new include dir for RTL8188eu driver")
Signed-off-by: Michael Straube <[email protected]>
---
v3:
- updated the commit message
- moved the u32 to __le32 conversions to a separate patch

v2:
- no changes

drivers/staging/r8188eu/core/rtw_fw.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/r8188eu/core/rtw_fw.c b/drivers/staging/r8188eu/core/rtw_fw.c
index 8620f3c92b52..eb4ab11f6b28 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 */
--
2.35.1

2022-04-16 02:38:57

by Michael Straube

[permalink] [raw]
Subject: [PATCH v3 6/8] staging: r8188eu: remove variables from rtl8188e_firmware_download()

The local variables fw_version, fw_subversion, fw_signature in
rtl8188e_firmware_download() are only used in one place. Use the
assigned values directly and remove the variables to make the code
shorter and cleaner.

Signed-off-by: Michael Straube <[email protected]>
---
v3:
- no changes

v2:
- no changes

drivers/staging/r8188eu/core/rtw_fw.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_fw.c b/drivers/staging/r8188eu/core/rtw_fw.c
index 0279af37719a..c102aba099f5 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 dvobj_priv *dvobj = adapter_to_dvobj(padapter);
struct device *device = dvobj_to_dev(dvobj);
struct rt_firmware_hdr *fwhdr = NULL;
- u16 fw_version, fw_subversion, fw_signature;
u8 *fw_data;
u32 fw_size;
static int log_version;
@@ -256,13 +255,10 @@ 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;

- fw_version = le16_to_cpu(fwhdr->version);
- fw_subversion = fwhdr->subversion;
- fw_signature = le16_to_cpu(fwhdr->signature);
-
if (!log_version++)
pr_info("%sFirmware Version %d, SubVersion %d, Signature 0x%x\n",
- DRIVER_PREFIX, fw_version, fw_subversion, fw_signature);
+ 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:45:09

by Larry Finger

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

On 4/15/22 07:10, 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.
>
> v3:
> - Splitted the first patch into two separate patches.
> - Added back logging the firmware version only once.
> - Included the compile time check for size of rt_firmware from
> patch 8/8 of v2 in the patch that replaces the hardcoded size.
>
> 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: convert u32 fields of rt_firmware_hdr to __le32
> 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: use pr_info_once() to log the firmware version
> staging: r8188eu: check firmware header existence before access
>
> drivers/staging/r8188eu/core/rtw_fw.c | 79 ++++++++++-----------------
> 1 file changed, 29 insertions(+), 50 deletions(-)

Most of this is fine, other than the removal of in-line comments in patch 3/8.

Larry

2022-04-16 02:49:19

by Michael Straube

[permalink] [raw]
Subject: Re: [PATCH v3 3/8] staging: r8188eu: clean up comments in struct rt_firmware_hdr

On 4/15/22 17:44, Larry Finger wrote:
> On 4/15/22 07:10, Michael Straube wrote:
>> The comments in struct rt_firmware_hdr are not needed.
>> Remove them.
>>
>> Signed-off-by: Michael Straube <[email protected]>
>> ---
>> v3:
>> - no changes
>>
>> v2:
>> - no changes
>>
>>   drivers/staging/r8188eu/core/rtw_fw.c | 37 ++++++++-------------------
>>   1 file changed, 11 insertions(+), 26 deletions(-)
>>
>> diff --git a/drivers/staging/r8188eu/core/rtw_fw.c
>> b/drivers/staging/r8188eu/core/rtw_fw.c
>> index 7cd08268f3b9..323e0c634c4e 100644
>> --- a/drivers/staging/r8188eu/core/rtw_fw.c
>> +++ b/drivers/staging/r8188eu/core/rtw_fw.c
>> @@ -14,37 +14,22 @@
>>       (le16_to_cpu(_fwhdr->Signature) & 0xFFF0) == 0x2300 ||    \
>>       (le16_to_cpu(_fwhdr->Signature) & 0xFFF0) == 0x88E0)
>> -/*  This structure must be careful with byte-ordering */
>> -
>>   struct rt_firmware_hdr {
>> -    /*  8-byte alinment required */
>> -    /*  LONG WORD 0 ---- */
>> -    __le16        Signature;    /* 92C0: test chip; 92C,
>> -                     * 88C0: test chip; 88C1: MP A-cut;
>> -                     * 92C1: MP A-cut */
>> -    u8        Category;    /*  AP/NIC and USB/PCI */
>> -    u8        Function;    /*  Reserved for different FW function
>> -                     *  indcation, for further use when
>> -                     *  driver needs to download different
>> -                     *  FW for different conditions */
>> -    __le16        Version;    /*  FW Version */
>> -    u8        Subversion;    /*  FW Subversion, default 0x00 */
>> +    __le16        Signature;
>> +    u8        Category;
>> +    u8        Function;
>> +    __le16        Version;
>> +    u8        Subversion;
>>       u8        Rsvd1;
>> -
>> -    /*  LONG WORD 1 ---- */
>> -    u8        Month;    /*  Release time Month field */
>> -    u8        Date;    /*  Release time Date field */
>> -    u8        Hour;    /*  Release time Hour field */
>> -    u8        Minute;    /*  Release time Minute field */
>> -    __le16        RamCodeSize;    /*  The size of RAM code */
>> +    u8        Month;
>> +    u8        Date;
>> +    u8        Hour;
>> +    u8        Minute;
>> +    __le16        RamCodeSize;
>>       u8        Foundry;
>>       u8        Rsvd2;
>> -
>> -    /*  LONG WORD 2 ---- */
>> -    __le32        SvnIdx;    /*  The SVN entry index */
>> +    __le32        SvnIdx;
>>       __le32        Rsvd3;
>> -
>> -    /*  LONG WORD 3 ---- */
>>       __le32        Rsvd4;
>>       __le32        Rsvd5;
>>   };
>
> The comments "LONG WORD" are useless, but the comments describing the
> fields are still useful. I do not like this patch.
>

Hi Larry,

You are right the in-line comments are useful. I'll send v4 keeping
them.

You only mentioned the in-line comments, just to get it right this
time:

What about the "8-byte alignment required" comment? You said in another
thread that the __le16 references need alignment 4. Should I make the
struct __aligned(8) or at least __aligned(4)?

And about "/* This structure must be careful with byte-ordering */" ?
I think it's obvious because of the __le16 and __le32 fields and can be
removed. Do you agree on that?

regards,
Michael