Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

broadcom: tg3: fix use of SPEED_UNKNOWN ethtool constant

tg3 driver uses u16 to store SPEED_UKNOWN ethtool constant,
which is defined as -1, resulting in value truncation and
thus incorrect test results against SPEED_UNKNOWN.

For example, the following test will print "False":

u16 speed = SPEED_UNKNOWN;

if (speed == SPEED_UNKNOWN)
printf("True");
else
printf("False");

Change storage of speed to use u32 to avoid this issue.

Signed-off-by: Michael Zhivich <mzhivich@akamai.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Michael Zhivich and committed by
David S. Miller
caf2c520 afe64245

+6 -6
+4 -4
drivers/net/ethernet/broadcom/tg3.c
··· 4283 4283 pci_set_power_state(tp->pdev, PCI_D3hot); 4284 4284 } 4285 4285 4286 - static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) 4286 + static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u32 *speed, u8 *duplex) 4287 4287 { 4288 4288 switch (val & MII_TG3_AUX_STAT_SPDMASK) { 4289 4289 case MII_TG3_AUX_STAT_10HALF: ··· 4787 4787 bool current_link_up; 4788 4788 u32 bmsr, val; 4789 4789 u32 lcl_adv, rmt_adv; 4790 - u16 current_speed; 4790 + u32 current_speed; 4791 4791 u8 current_duplex; 4792 4792 int i, err; 4793 4793 ··· 5719 5719 static int tg3_setup_fiber_phy(struct tg3 *tp, bool force_reset) 5720 5720 { 5721 5721 u32 orig_pause_cfg; 5722 - u16 orig_active_speed; 5722 + u32 orig_active_speed; 5723 5723 u8 orig_active_duplex; 5724 5724 u32 mac_status; 5725 5725 bool current_link_up; ··· 5823 5823 { 5824 5824 int err = 0; 5825 5825 u32 bmsr, bmcr; 5826 - u16 current_speed = SPEED_UNKNOWN; 5826 + u32 current_speed = SPEED_UNKNOWN; 5827 5827 u8 current_duplex = DUPLEX_UNKNOWN; 5828 5828 bool current_link_up = false; 5829 5829 u32 local_adv, remote_adv, sgsr;
+2 -2
drivers/net/ethernet/broadcom/tg3.h
··· 2873 2873 struct tg3_link_config { 2874 2874 /* Describes what we're trying to get. */ 2875 2875 u32 advertising; 2876 - u16 speed; 2876 + u32 speed; 2877 2877 u8 duplex; 2878 2878 u8 autoneg; 2879 2879 u8 flowctrl; ··· 2882 2882 u8 active_flowctrl; 2883 2883 2884 2884 u8 active_duplex; 2885 - u16 active_speed; 2885 + u32 active_speed; 2886 2886 u32 rmt_adv; 2887 2887 }; 2888 2888