linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code
@ 2022-04-14  8:38 Michael Straube
  2022-04-14  8:38 ` [PATCH 1/7] staging: r8188eu: fix struct rt_firmware_hdr Michael Straube
                   ` (7 more replies)
  0 siblings, 8 replies; 14+ messages in thread
From: Michael Straube @ 2022-04-14  8:38 UTC (permalink / raw)
  To: gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel, 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.

Michael Straube (7):
  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

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

-- 
2.35.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/7] staging: r8188eu: fix struct rt_firmware_hdr
  2022-04-14  8:38 [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code Michael Straube
@ 2022-04-14  8:38 ` Michael Straube
  2022-04-14 15:32   ` Larry Finger
  2022-04-14  8:38 ` [PATCH 2/7] staging: r8188eu: clean up comments in " Michael Straube
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 14+ messages in thread
From: Michael Straube @ 2022-04-14  8:38 UTC (permalink / raw)
  To: gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel, Michael Straube

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 <straube.linux@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/7] staging: r8188eu: clean up comments in struct rt_firmware_hdr
  2022-04-14  8:38 [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code Michael Straube
  2022-04-14  8:38 ` [PATCH 1/7] staging: r8188eu: fix struct rt_firmware_hdr Michael Straube
@ 2022-04-14  8:38 ` Michael Straube
  2022-04-14  8:38 ` [PATCH 3/7] staging: r8188eu: rename fields of " Michael Straube
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Michael Straube @ 2022-04-14  8:38 UTC (permalink / raw)
  To: gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel, Michael Straube

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

Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 3/7] staging: r8188eu: rename fields of struct rt_firmware_hdr
  2022-04-14  8:38 [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code Michael Straube
  2022-04-14  8:38 ` [PATCH 1/7] staging: r8188eu: fix struct rt_firmware_hdr Michael Straube
  2022-04-14  8:38 ` [PATCH 2/7] staging: r8188eu: clean up comments in " Michael Straube
@ 2022-04-14  8:38 ` Michael Straube
  2022-04-14  8:38 ` [PATCH 4/7] staging: r8188eu: use sizeof instead of hardcoded firmware header size Michael Straube
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Michael Straube @ 2022-04-14  8:38 UTC (permalink / raw)
  To: gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel, Michael Straube

Rename the fields of struct rt_firmware_hdr to avoid camel case.

Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 4/7] staging: r8188eu: use sizeof instead of hardcoded firmware header size
  2022-04-14  8:38 [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code Michael Straube
                   ` (2 preceding siblings ...)
  2022-04-14  8:38 ` [PATCH 3/7] staging: r8188eu: rename fields of " Michael Straube
@ 2022-04-14  8:38 ` Michael Straube
  2022-04-14 19:36   ` Pavel Skripkin
  2022-04-14  8:38 ` [PATCH 5/7] staging: r8188eu: remove variables from rtl8188e_firmware_download() Michael Straube
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 14+ messages in thread
From: Michael Straube @ 2022-04-14  8:38 UTC (permalink / raw)
  To: gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel, Michael Straube

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

Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 5/7] staging: r8188eu: remove variables from rtl8188e_firmware_download()
  2022-04-14  8:38 [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code Michael Straube
                   ` (3 preceding siblings ...)
  2022-04-14  8:38 ` [PATCH 4/7] staging: r8188eu: use sizeof instead of hardcoded firmware header size Michael Straube
@ 2022-04-14  8:38 ` Michael Straube
  2022-04-14  8:38 ` [PATCH 6/7] staging: r8188eu: always log firmware info Michael Straube
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Michael Straube @ 2022-04-14  8:38 UTC (permalink / raw)
  To: gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel, 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.

Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
 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 94526064f29b..cbc4980bd938 100644
--- a/drivers/staging/r8188eu/core/rtw_fw.c
+++ b/drivers/staging/r8188eu/core/rtw_fw.c
@@ -237,7 +237,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;
@@ -254,13 +253,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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 6/7] staging: r8188eu: always log firmware info
  2022-04-14  8:38 [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code Michael Straube
                   ` (4 preceding siblings ...)
  2022-04-14  8:38 ` [PATCH 5/7] staging: r8188eu: remove variables from rtl8188e_firmware_download() Michael Straube
@ 2022-04-14  8:38 ` Michael Straube
  2022-04-14 15:36   ` Larry Finger
  2022-04-14  8:38 ` [PATCH 7/7] staging: r8188eu: check firmware header existence before access Michael Straube
  2022-04-14 15:43 ` [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code Larry Finger
  7 siblings, 1 reply; 14+ messages in thread
From: Michael Straube @ 2022-04-14  8:38 UTC (permalink / raw)
  To: gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel, Michael Straube

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 <straube.linux@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 7/7] staging: r8188eu: check firmware header existence before access
  2022-04-14  8:38 [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code Michael Straube
                   ` (5 preceding siblings ...)
  2022-04-14  8:38 ` [PATCH 6/7] staging: r8188eu: always log firmware info Michael Straube
@ 2022-04-14  8:38 ` Michael Straube
  2022-04-14 15:40   ` Larry Finger
  2022-04-14 15:43 ` [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code Larry Finger
  7 siblings, 1 reply; 14+ messages in thread
From: Michael Straube @ 2022-04-14  8:38 UTC (permalink / raw)
  To: gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel, 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.

Signed-off-by: Michael Straube <straube.linux@gmail.com>
---
Do we need the IS_FW_HEADER_EXIST(fwhdr) check at all?
The header _does_ exist in rtl8188eufw.bin and it's very
unlikely that it ever changes _and_ the header will be
removed.

 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 64963507a346..c58bce1a1856 100644
--- a/drivers/staging/r8188eu/core/rtw_fw.c
+++ b/drivers/staging/r8188eu/core/rtw_fw.c
@@ -249,14 +249,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("%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("%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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/7] staging: r8188eu: fix struct rt_firmware_hdr
  2022-04-14  8:38 ` [PATCH 1/7] staging: r8188eu: fix struct rt_firmware_hdr Michael Straube
@ 2022-04-14 15:32   ` Larry Finger
  0 siblings, 0 replies; 14+ messages in thread
From: Larry Finger @ 2022-04-14 15:32 UTC (permalink / raw)
  To: Michael Straube, gregkh; +Cc: phil, linux-staging, linux-kernel

On 4/14/22 03:38, Michael Straube wrote:
> 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.

There is a typo here.

Note that the various RsvdN fields are just reserving space and will never be 
referenced, thus it does not matter if they are u32 or __le32. It is OK to 
change them, but it is not wrong to leave them the way they are.

Larry


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 6/7] staging: r8188eu: always log firmware info
  2022-04-14  8:38 ` [PATCH 6/7] staging: r8188eu: always log firmware info Michael Straube
@ 2022-04-14 15:36   ` Larry Finger
  2022-04-14 19:39     ` Pavel Skripkin
  0 siblings, 1 reply; 14+ messages in thread
From: Larry Finger @ 2022-04-14 15:36 UTC (permalink / raw)
  To: Michael Straube, gregkh; +Cc: phil, linux-staging, linux-kernel

On 4/14/22 03:38, Michael Straube wrote:
> 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.

I think the slight complication of the code, one static variable and one if 
statement, is worth not spamming the logs. My recollection is that there are 
other cases besides unplugging and replugging that lead to the firmware being 
reloaded.

Larry


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 7/7] staging: r8188eu: check firmware header existence before access
  2022-04-14  8:38 ` [PATCH 7/7] staging: r8188eu: check firmware header existence before access Michael Straube
@ 2022-04-14 15:40   ` Larry Finger
  0 siblings, 0 replies; 14+ messages in thread
From: Larry Finger @ 2022-04-14 15:40 UTC (permalink / raw)
  To: Michael Straube, gregkh; +Cc: phil, linux-staging, linux-kernel

On 4/14/22 03:38, Michael Straube wrote:
> 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 <straube.linux@gmail.com>
> ---
> Do we need the IS_FW_HEADER_EXIST(fwhdr) check at all?
> The header _does_ exist in rtl8188eufw.bin and it's very
> unlikely that it ever changes _and_ the header will be
> removed.
> 
>   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 64963507a346..c58bce1a1856 100644
> --- a/drivers/staging/r8188eu/core/rtw_fw.c
> +++ b/drivers/staging/r8188eu/core/rtw_fw.c
> @@ -249,14 +249,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("%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("%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);
>   	}

You can probably remove the IS_FW_HEADER_EXIST macro, but please restore the 
guard against logging the version more than once.

Larry


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code
  2022-04-14  8:38 [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code Michael Straube
                   ` (6 preceding siblings ...)
  2022-04-14  8:38 ` [PATCH 7/7] staging: r8188eu: check firmware header existence before access Michael Straube
@ 2022-04-14 15:43 ` Larry Finger
  7 siblings, 0 replies; 14+ messages in thread
From: Larry Finger @ 2022-04-14 15:43 UTC (permalink / raw)
  To: Michael Straube, gregkh; +Cc: phil, linux-staging, linux-kernel

On 4/14/22 03:38, 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.
> 
> Michael Straube (7):
>    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

Acked-by: Larry Finger <Larry.Finger@lwfinger.net> for 2/7 through 5/7. Patch 
1/7 has a typo in the commit message, and I have objection to the logging 
changes in 6/7 and 7/7.

Larry


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 4/7] staging: r8188eu: use sizeof instead of hardcoded firmware header size
  2022-04-14  8:38 ` [PATCH 4/7] staging: r8188eu: use sizeof instead of hardcoded firmware header size Michael Straube
@ 2022-04-14 19:36   ` Pavel Skripkin
  0 siblings, 0 replies; 14+ messages in thread
From: Pavel Skripkin @ 2022-04-14 19:36 UTC (permalink / raw)
  To: Michael Straube, gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel

Hi Michael,

On 4/14/22 11:38, Michael Straube wrote:
> Use sizeof() instead of hardcoding the firmware header size.
> 
> Signed-off-by: Michael Straube <straube.linux@gmail.com>
> ---
>   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);


What about BUILD_BUG_ON(sizeof(struct rt_firmware_hdr) != 32)? To be 
sure we won't face same bug in future





With regards,
Pavel Skripkin

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 6/7] staging: r8188eu: always log firmware info
  2022-04-14 15:36   ` Larry Finger
@ 2022-04-14 19:39     ` Pavel Skripkin
  0 siblings, 0 replies; 14+ messages in thread
From: Pavel Skripkin @ 2022-04-14 19:39 UTC (permalink / raw)
  To: Larry Finger, Michael Straube, gregkh; +Cc: phil, linux-staging, linux-kernel

Hi Larry,

On 4/14/22 18:36, Larry Finger wrote:
> On 4/14/22 03:38, Michael Straube wrote:
>> 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.
> 
> I think the slight complication of the code, one static variable and one if
> statement, is worth not spamming the logs. My recollection is that there are
> other cases besides unplugging and replugging that lead to the firmware being
> reloaded.
> 


What about pr_info_once? Anyway even with old code message printed only 
once per driver load





With regards,
Pavel Skripkin

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-04-14 19:39 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-14  8:38 [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code Michael Straube
2022-04-14  8:38 ` [PATCH 1/7] staging: r8188eu: fix struct rt_firmware_hdr Michael Straube
2022-04-14 15:32   ` Larry Finger
2022-04-14  8:38 ` [PATCH 2/7] staging: r8188eu: clean up comments in " Michael Straube
2022-04-14  8:38 ` [PATCH 3/7] staging: r8188eu: rename fields of " Michael Straube
2022-04-14  8:38 ` [PATCH 4/7] staging: r8188eu: use sizeof instead of hardcoded firmware header size Michael Straube
2022-04-14 19:36   ` Pavel Skripkin
2022-04-14  8:38 ` [PATCH 5/7] staging: r8188eu: remove variables from rtl8188e_firmware_download() Michael Straube
2022-04-14  8:38 ` [PATCH 6/7] staging: r8188eu: always log firmware info Michael Straube
2022-04-14 15:36   ` Larry Finger
2022-04-14 19:39     ` Pavel Skripkin
2022-04-14  8:38 ` [PATCH 7/7] staging: r8188eu: check firmware header existence before access Michael Straube
2022-04-14 15:40   ` Larry Finger
2022-04-14 15:43 ` [PATCH 0/7] staging: r8188eu: fix and clean up some firmware code Larry Finger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).