/drivers/net/wireless/ath/ath9k remove unnecessary ?: operator
Subsystems (3)
PATCH 1/1 /drivers/net/wireless/ath/ath9k remove unnecessary ?: operator
((thermometer < 0) ? 0 : (thermometer == X)) and (thermometer == X) are equal for X >= 0.
--- drivers/net/wireless/ath/ath9k/ar9003_eeprom.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/ath/ath9k/ar9003_eeprom.c +3 -3
@@ -4097,16 +4097,16 @@ static void ar9003_hw_thermometer_apply(struct ath_hw *ah)REG_RMW_FIELD (ah,AR_PHY_65NM_CH2_RXTX4 ,AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR , therm_on); - therm_on = (thermometer <0 ) ?0 : (thermometer ==0 ); + therm_on = thermometer ==0 ;REG_RMW_FIELD (ah,AR_PHY_65NM_CH0_RXTX4 ,AR_PHY_65NM_CH0_RXTX4_THERM_ON , therm_on);if (pCap->chip_chainmask &BIT (1 )) { - therm_on = (thermometer <0 ) ?0 : (thermometer ==1 ); + therm_on = thermometer ==1 ;REG_RMW_FIELD (ah,AR_PHY_65NM_CH1_RXTX4 ,AR_PHY_65NM_CH0_RXTX4_THERM_ON , therm_on); }if (pCap->chip_chainmask &BIT (2 )) { - therm_on = (thermometer <0 ) ?0 : (thermometer ==2 ); + therm_on = thermometer ==2 ;REG_RMW_FIELD (ah,AR_PHY_65NM_CH2_RXTX4 ,AR_PHY_65NM_CH0_RXTX4_THERM_ON , therm_on); }
Signature · 1 line
2.4.10
Quoted 1 line · Ivan Safonov
((thermometer < 0) ? 0 : (thermometer == X)) and (thermometer == X) are equal for X >= 0.
X is not guaranteed to be >= 0 here
drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
Quoted 6 lines
Signed-off-by Ivan Safonov <[email protected]>---
?drivers/net/wireless/ath/ath9k/ar9003_eeprom.c | 6 +++--- ?1 file changed, 3 insertions(+), 3 deletions(-)drivers/net/wireless/ath/ath9k/ar9003_eeprom.c +0
-0
[]
drivers/net/wireless/ath/ath9k/ar9003_eeprom.c static void ar9003_hw_thermometer_apply(struct ath_hw *ah) · line 4100
Quoted 6 lines
drivers/net/wireless/ath/ath9k/ar9003_eeprom.c +0
-0@@ -4097,16 +4097,16 @@ static void ar9003_hw_thermometer_apply(struct ath_hw *ah) ? REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4, ? ??????AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, therm_on);?
drivers/net/wireless/ath/ath9k/ar9003_eeprom.c +1
-1- therm_on = (thermometer <0 ) ?0 : (thermometer ==0 ); + therm_on = thermometer ==0 ;
This code is not equivalent.
Check what happens when thermometer is -1.
Quoted 14 lines
? REG_RMW_FIELD(ah,
AR_PHY_65NM_CH0_RXTX4,
? ??????AR_PHY_65NM_CH0_RXTX4_THERM_ON,therm_on);
? if (pCap->chip_chainmask& BIT(1)) {drivers/net/wireless/ath/ath9k/ar9003_eeprom.c +1
-1- therm_on = (thermometer <0 ) ?0 : (thermometer ==1 ); + therm_on = thermometer ==1 ;? REG_RMW_FIELD(ah,
AR_PHY_65NM_CH1_RXTX4,
? ??????AR_PHY_65NM_CH0_RXTX4_THERM_ON,therm_on);
? }
? if (pCap->chip_chainmask& BIT(2)) {drivers/net/wireless/ath/ath9k/ar9003_eeprom.c +1
-1- therm_on = (thermometer <0 ) ?0 : (thermometer ==2 ); + therm_on = thermometer ==2 ;? REG_RMW_FIELD(ah,
AR_PHY_65NM_CH2_RXTX4,
? ??????AR_PHY_65NM_CH0_RXTX4_THERM_ON,therm_on);
? }
Quoted 3 lines · Joe Perches
Quoted 1 line · Ivan Safonov
((thermometer < 0) ? 0 : (thermometer == X)) and (thermometer == X) are equal for X >= 0.
X is not guaranteed to be >= 0 here
X is fixed constant. In this case X is {0, 1, 2}.
Quoted 9 lines
drivers/net/wireless/ath/ath9k/ar9003_eeprom.c static void ar9003_hw_thermometer_apply(struct ath_hw *ah) · line 4100
Quoted 6 lines
drivers/net/wireless/ath/ath9k/ar9003_eeprom.c +1
-1@@ -4097,16 +4097,16 @@ static void ar9003_hw_thermometer_apply(struct ath_hw *ah)REG_RMW_FIELD (ah,AR_PHY_65NM_CH2_RXTX4 ,AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR , therm_on); - therm_on = (thermometer <0 ) ?0 : (thermometer ==0 ); + therm_on = thermometer ==0 ;This code is not equivalent.
Check what happens when thermometer is -1.
therm_on = (thermometer < 0) ? 0 : (thermometer == 0) => therm_on = (true) ? 0 : (thermometer == 0) =>
therm_on is 0
therm_on = thermometer == 0 =>
therm_on = false
false is equal to 0
Value of the thermometer variable isanerror code, or athermometercode. The thermometercode is never equal to the error code (thermometercode >= 0, error code <0).
Quoted 7 lines · Ivan Safonov
Quoted 4 lines · Joe Perches
Quoted 2 lines · Ivan Safonov
((thermometer < 0) ? 0 : (thermometer == X)) and (thermometer ==
X) are equal for X >= 0.X is not guaranteed to be >= 0 here
X is fixed constant. In this case X is {0, 1, 2}.
Looks like it can be -1 to me (range: -1, 0, 1, 2)
static int ar9003_hw_get_thermometer(struct ath_hw *ah)
{
struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
struct ar9300_base_eep_hdr *pBase = &eep->baseEepHeader;
int thermometer =??(pBase->miscConfiguration >> 1) & 0x3;
return --thermometer;
}Quoted 9 lines · Joe Perches
Quoted 6 lines · Ivan Safonov
Quoted 4 lines · Joe Perches
Quoted 2 lines · Ivan Safonov
((thermometer < 0) ? 0 : (thermometer == X)) and (thermometer ==
X) are equal for X >= 0.X is not guaranteed to be >= 0 here
X is fixed constant. In this case X is {0, 1, 2}.
Looks like it can be -1 to me (range: -1, 0, 1, 2)
Quoted 8 lines
static int
ar9003_hw_get_thermometer(struct ath_hw *ah){ struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep; struct ar9300_base_eep_hdr *pBase = &eep->baseEepHeader; int thermometer = (pBase->miscConfiguration >> 1) & 0x3; return --thermometer; }
X is not thermometer. The thermometer is {-1, 0, 1, 2}. X is {0, 1, 2}. All possible X valueswritten in the comments:
ar9003_hw_get_thermometer used only in ar9003_hw_thermometer_apply:
static void ar9003_hw_thermometer_apply(struct ath_hw *ah)
{
struct ath9k_hw_capabilities *pCap = &ah->caps;
int thermometer = ar9003_hw_get_thermometer(ah);
u8 therm_on = (thermometer < 0) ? 0 : 1;
REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_RXTX4,
AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, therm_on);
if (pCap->chip_chainmask & BIT(1))
REG_RMW_FIELD(ah, AR_PHY_65NM_CH1_RXTX4,
AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, therm_on);
if (pCap->chip_chainmask & BIT(2))
REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,
AR_PHY_65NM_CH0_RXTX4_THERM_ON_OVR, therm_on);
therm_on = (thermometer < 0) ? 0 : (thermometer == 0); /* X = 0 */
REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_RXTX4,
AR_PHY_65NM_CH0_RXTX4_THERM_ON, therm_on);
if (pCap->chip_chainmask & BIT(1)) {
therm_on = (thermometer < 0) ? 0 : (thermometer == 1);
/* X = 1 */
REG_RMW_FIELD(ah, AR_PHY_65NM_CH1_RXTX4,
AR_PHY_65NM_CH0_RXTX4_THERM_ON, therm_on);
}
if (pCap->chip_chainmask & BIT(2)) {
therm_on = (thermometer < 0) ? 0 : (thermometer == 2);
/* X = 2 */
REG_RMW_FIELD(ah, AR_PHY_65NM_CH2_RXTX4,
AR_PHY_65NM_CH0_RXTX4_THERM_ON, therm_on);
}
}There is no X = -1.