Skip to contentSkip to conversation

staging: r8188eu: fix and clean up some firmware code

PATCH Superseded Michael Straube 2 participants 13 messages Apr 15, 2022 Staging

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover 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(-)
Signature · 1 line
2.35.1
#1 lore raw

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")

---
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(-)
drivers/staging/r8188eu/core/rtw_fw.c +1 -1
index 8620f3c92b52..eb4ab11f6b28 100644
@@ -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 */
Signature · 1 line
2.35.1
#2 lore raw

PATCH v3 2/8 staging: r8188eu: convert u32 fields of rt_firmware_hdr to __le32

In reply to Michael Straube

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

---
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(-)
drivers/staging/r8188eu/core/rtw_fw.c +3 -3
index eb4ab11f6b28..7cd08268f3b9 100644
@@ -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)
Signature · 1 line
2.35.1
#3 lore raw

PATCH v3 3/8 staging: r8188eu: clean up comments in struct rt_firmware_hdr

In reply to Michael Straube

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

---
v3:
- no changes

v2:
- no changes

 drivers/staging/r8188eu/core/rtw_fw.c | 37 ++++++++-------------------
 1 file changed, 11 insertions(+), 26 deletions(-)
drivers/staging/r8188eu/core/rtw_fw.c +11 -26
index 7cd08268f3b9..323e0c634c4e 100644
@@ -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;
 };
Signature · 1 line
2.35.1
#4 lore raw

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

Quoted 57 lines · Michael Straube

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

---
v3:
- no changes

v2:
- no changes

  drivers/staging/r8188eu/core/rtw_fw.c | 37 ++++++++-------------------
  1 file changed, 11 insertions(+), 26 deletions(-)
drivers/staging/r8188eu/core/rtw_fw.c +10 -21
index 7cd08268f3b9..323e0c634c4e 100644
@@ -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;

drivers/staging/r8188eu/core/rtw_fw.c line 35

Quoted 10 lines
drivers/staging/r8188eu/core/rtw_fw.c +1 -5
-
-	/*  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

#5 lore raw

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

Quoted 61 lines · Larry Finger
Quoted 60 lines · Michael Straube

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

---
v3:
- no changes

v2:
- no changes

  drivers/staging/r8188eu/core/rtw_fw.c | 37 ++++++++-------------------

  1 file changed, 11 insertions(+), 26 deletions(-)
drivers/staging/r8188eu/core/rtw_fw.c +11 -24
index 7cd08268f3b9..323e0c634c4e 100644
@@ -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;
Quoted 9 lines

drivers/staging/r8188eu/core/rtw_fw.c line 35

Quoted 6 lines
drivers/staging/r8188eu/core/rtw_fw.c +0 -2
       __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

#6 lore raw

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

Quoted 77 lines · Michael Straube
Quoted 61 lines · Larry Finger
Quoted 60 lines · Michael Straube

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

---
v3:
- no changes

v2:
- no changes

  drivers/staging/r8188eu/core/rtw_fw.c | 37 ++++++++-------------------

  1 file changed, 11 insertions(+), 26 deletions(-)
drivers/staging/r8188eu/core/rtw_fw.c +11 -24
index 7cd08268f3b9..323e0c634c4e 100644
@@ -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;
Quoted 9 lines

drivers/staging/r8188eu/core/rtw_fw.c line 35

Quoted 6 lines
drivers/staging/r8188eu/core/rtw_fw.c +0 -2
       __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.

Quoted 6 lines

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)?

Routines cpu_to_le16() and le16_to_cpu() require two-byte alignment. Similarly, the 32-bit versions need 4-byte alignment. The layout of the struct will ensure that as long as the entire struct has 4-byte alignment.

This struct is only used in rtl8188e_firmware_download() where it is created on the stack. That means it will be 8-byte aligned for x86_64 and 4-byle aligned on 32-bit systems. I'm sure that Dan or GregKH will correct me if I got this wrong, but that should be sufficient. Making it __aligned(8) could waste 4 bytes on the stack for 32-bit systems. Using __aligned(4) would have no effect on any system.

I say remove the comment.

Quoted 4 lines

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?

Using the __leNN implies little-endian, thus that comment is useless. Yes, I agree.

Larry

#7 lore raw

PATCH v3 4/8 staging: r8188eu: rename fields of struct rt_firmware_hdr

In reply to Michael Straube

Rename the fields of struct rt_firmware_hdr to avoid camel case.

---
v3:
- no changes

v2:
- no changes

 drivers/staging/r8188eu/core/rtw_fw.c | 48 +++++++++++++--------------
 1 file changed, 24 insertions(+), 24 deletions(-)
drivers/staging/r8188eu/core/rtw_fw.c +24 -24
index 323e0c634c4e..3da52a1ba23c 100644
@@ -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",
Signature · 1 line
2.35.1
#8 lore raw

PATCH v3 5/8 staging: r8188eu: use sizeof instead of hardcoded firmware header size

In reply to Michael Straube

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.

---
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(-)
drivers/staging/r8188eu/core/rtw_fw.c +4 -3
index 3da52a1ba23c..0279af37719a 100644
@@ -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, */
Signature · 1 line
2.35.1
#9 lore raw

PATCH v3 6/8 staging: r8188eu: remove variables from rtl8188e_firmware_download()

In reply to Michael Straube

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.

---
v3:
- no changes

v2:
- no changes

 drivers/staging/r8188eu/core/rtw_fw.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/r8188eu/core/rtw_fw.c +2 -6
index 0279af37719a..c102aba099f5 100644
@@ -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);
Signature · 1 line
2.35.1
#10 lore raw

PATCH v3 7/8 staging: r8188eu: use pr_info_once() to log the firmware version

In reply to Michael Straube

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

---
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(-)
drivers/staging/r8188eu/core/rtw_fw.c +3 -5
index c102aba099f5..7ee72236c7f4 100644
@@ -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);
Signature · 1 line
2.35.1
#11 lore raw

PATCH v3 8/8 staging: r8188eu: check firmware header existence before access

In reply to Michael Straube

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.

---
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(-)
drivers/staging/r8188eu/core/rtw_fw.c +4 -5
index 7ee72236c7f4..8b5c67780a7b 100644
@@ -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);
 	}
Signature · 1 line
2.35.1
#12 lore raw
In reply to Michael Straube
Quoted 25 lines · Michael Straube

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

Quoted 2 lines
  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