Skip to contentSkip to conversation

r8169: remove not needed check in rtl_fw_write_firmware

PATCH Applied Heiner Kallweit 3 participants 5 messages Nov 23, 2023 – Nov 24, 2023

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

PATCH 1/1 r8169: remove not needed check in rtl_fw_write_firmware

This check can never be true for a firmware file with a correct format. Existing checks in rtl_fw_data_ok() are sufficient, no problems with invalid firmware files are known.

---
 drivers/net/ethernet/realtek/r8169_firmware.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/ethernet/realtek/r8169_firmware.c +0 -3
index cbc6b846d..ed6e721b1 100644
@@ -151,9 +151,6 @@ void rtl_fw_write_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
 		u32 regno = (action & 0x0fff0000) >> 16;
 		enum rtl_fw_opcode opcode = action >> 28;
 
-		if (!action)
-			break;
-
 		switch (opcode) {
 		case PHY_READ:
 			predata = fw_read(tp, regno);
Signature · 1 line
2.43.0
reviewer
#1 lore raw
Quoted 14 lines · Heiner Kallweit

This check can never be true for a firmware file with a correct format. Existing checks in rtl_fw_data_ok() are sufficient, no problems with invalid firmware files are known.

---
 drivers/net/ethernet/realtek/r8169_firmware.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/ethernet/realtek/r8169_firmware.c +0 -0
index cbc6b846d..ed6e721b1 100644

drivers/net/ethernet/realtek/r8169_firmware.c void rtl_fw_write_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) · line 156

Quoted 6 lines
drivers/net/ethernet/realtek/r8169_firmware.c +0 -3
@@ -151,9 +151,6 @@ void rtl_fw_write_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
 		u32 regno = (action & 0x0fff0000) >> 16;
 		enum rtl_fw_opcode opcode = action >> 28;
 
-		if (!action)
-			break;
-

Hi Heiner,

I could well be wrong, but this does seem to guard against the following case:

1. data = 0
2. regno = 0
3. opcode = 0 (PHY_READ)

Which does not seem to be checked in rtl_fw_data_ok().

It's unclear to me if there is any value in this guard.

Quoted 6 lines
drivers/net/ethernet/realtek/r8169_firmware.c +0 -0
 		switch (opcode) {
 		case PHY_READ:
 			predata = fw_read(tp, regno);
Signature · 1 line
2.43.0
author maintainer
#2 lore raw
Quoted 26 lines · Simon Horman
Quoted 14 lines · Heiner Kallweit

This check can never be true for a firmware file with a correct format. Existing checks in rtl_fw_data_ok() are sufficient, no problems with invalid firmware files are known.

---
 drivers/net/ethernet/realtek/r8169_firmware.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/ethernet/realtek/r8169_firmware.c +0 -0
index cbc6b846d..ed6e721b1 100644

drivers/net/ethernet/realtek/r8169_firmware.c void rtl_fw_write_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) · line 156

Quoted 6 lines
drivers/net/ethernet/realtek/r8169_firmware.c +0 -3
@@ -151,9 +151,6 @@ void rtl_fw_write_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
 		u32 regno = (action & 0x0fff0000) >> 16;
 		enum rtl_fw_opcode opcode = action >> 28;
 
-		if (!action)
-			break;
-

Hi Heiner,

I could well be wrong, but this does seem to guard against the following case:

Quoted 8 lines

1. data = 0
2. regno = 0
3. opcode = 0 (PHY_READ)

Which does not seem to be checked in rtl_fw_data_ok().

It's unclear to me if there is any value in this guard.

Value 0 is used with a special meaning in two places:
1. Newer firmwares with some meta data before the actual firmware have first dword 0 to be able to differentiate old and new fw format.
2. Typically (not always) fw files in new format have a trailing dword 0.

A potential problem (as you mention) is that value 0 isn't really a sentinel value because reading PHY register 0 is a valid command. It's just never used in their firmwares.

There's no need to guard from reading PHY reg 0. It does no harm. I *think* they once added this check to detect end of file. But that's not needed because the actual firmware length is part of the meta data. Therefore reading data from the firmware will stop before reaching the training zero(s).

Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/realtek/r8169_firmware.c +0 -0
 		switch (opcode) {
 		case PHY_READ:
 			predata = fw_read(tp, regno);
Signature · 1 line
2.43.0
reviewer
#3 lore raw
Quoted 44 lines · Heiner Kallweit
Quoted 26 lines · Simon Horman
Quoted 14 lines · Heiner Kallweit

This check can never be true for a firmware file with a correct format. Existing checks in rtl_fw_data_ok() are sufficient, no problems with invalid firmware files are known.

---
 drivers/net/ethernet/realtek/r8169_firmware.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/ethernet/realtek/r8169_firmware.c +0 -0
index cbc6b846d..ed6e721b1 100644

drivers/net/ethernet/realtek/r8169_firmware.c void rtl_fw_write_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) · line 156

Quoted 6 lines
drivers/net/ethernet/realtek/r8169_firmware.c +0 -3
@@ -151,9 +151,6 @@ void rtl_fw_write_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
 		u32 regno = (action & 0x0fff0000) >> 16;
 		enum rtl_fw_opcode opcode = action >> 28;
 
-		if (!action)
-			break;
-

Hi Heiner,

I could well be wrong, but this does seem to guard against the following case:

Quoted 8 lines

1. data = 0
2. regno = 0
3. opcode = 0 (PHY_READ)

Which does not seem to be checked in rtl_fw_data_ok().

It's unclear to me if there is any value in this guard.

Value 0 is used with a special meaning in two places:
1. Newer firmwares with some meta data before the actual firmware have first dword 0 to be able to differentiate old and new fw format.
2. Typically (not always) fw files in new format have a trailing dword 0.

A potential problem (as you mention) is that value 0 isn't really a sentinel value because reading PHY register 0 is a valid command. It's just never used in their firmwares.

Quoted 5 lines

There's no need to guard from reading PHY reg 0. It does no harm. I *think* they once added this check to detect end of file. But that's not needed because the actual firmware length is part of the meta data. Therefore reading data from the firmware will stop before reaching the training zero(s).

Thanks for the clarification.
I am happy with this patch (which is now in net-next).

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/realtek/r8169_firmware.c +0 -0
 		switch (opcode) {
 		case PHY_READ:
 			predata = fw_read(tp, regno);
Signature · 1 line
2.43.0
#4 lore raw
In reply to Heiner Kallweit
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 8 lines · On Thu, 23 Nov 2023 10:53:26 +0100 you wrote:

This check can never be true for a firmware file with a correct format. Existing checks in rtl_fw_data_ok() are sufficient, no problems with invalid firmware files are known.

---
 drivers/net/ethernet/realtek/r8169_firmware.c | 3 ---
 1 file changed, 3 deletions(-)

Here is the summary with links:
- [net-next] r8169: remove not needed check in rtl_fw_write_firmware

    https://git.kernel.org/netdev/net-next/c/3a767b482cac

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html