Skip to contentSkip to conversation

igb: fix bit_shift to be in [1..8] range

PATCH Applied Tony Nguyen 2 participants 2 messages May 16, 2023 – May 17, 2023

Subsystems (3)
lore
Share & tools
lore

Tony Nguyen

author maintainer
#0 lore raw

PATCH 1/1 igb: fix bit_shift to be in [1..8] range

From: Aleksandr Loktionov <[email protected]>

In igb_hash_mc_addr() the expression:

        "mc_addr[4] >> 8 - bit_shift", right shifting "mc_addr[4]"

shift by more than 7 bits always yields zero, so hash becomes not so different. Add initialization with bit_shift = 1 and add a loop condition to ensure bit_shift will be always in [1..8] range.

Fixes 9d5c824399de ("igb: PCI-Express 82575 Gigabit Ethernet driver")
---
 drivers/net/ethernet/intel/igb/e1000_mac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igb/e1000_mac.c +2 -2
index 205d577bdbba..caf91c6f52b4 100644
@@ -426,7 +426,7 @@ void igb_mta_set(struct e1000_hw *hw, u32 hash_value)
 static u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
 {
 	u32 hash_value, hash_mask;
-	u8 bit_shift = 0;
+	u8 bit_shift = 1;
 
 	/* Register count multiplied by bits per register */
 	hash_mask = (hw->mac.mta_reg_count * 32) - 1;
@@ -434,7 +434,7 @@ static u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
 	/* For a mc_filter_type of 0, bit_shift is the number of left-shifts
 	 * where 0xFF would still fall within the hash mask.
 	 */
-	while (hash_mask >> bit_shift != 0xFF)
+	while (hash_mask >> bit_shift != 0xFF && bit_shift < 4)
 		bit_shift++;
 
 	/* The portion of the address that is used for the hash table
Signature · 1 line
2.38.1
#1 lore raw
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:

Hello:

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

Quoted 9 lines · On Tue, 16 May 2023 10:41:46 -0700 you wrote:

From: Aleksandr Loktionov <[email protected]>

In igb_hash_mc_addr() the expression:

        "mc_addr[4] >> 8 - bit_shift", right shifting "mc_addr[4]"

shift by more than 7 bits always yields zero, so hash becomes not so different. Add initialization with bit_shift = 1 and add a loop condition to ensure bit_shift will be always in [1..8] range.

[...]

Here is the summary with links:
- [net] igb: fix bit_shift to be in [1..8] range

    https://git.kernel.org/netdev/net/c/60d758659f1f

You are awesome, thank you!

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