* [PATCH] /drivers/net/wireless/ath/ath9k remove unnecessary ?: operator @ 2015-12-28 13:48 Ivan Safonov [not found] ` <20151228134852.GA10572-99FyVxquhxHwodmfrJTGkIdd74u8MsAO@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Ivan Safonov @ 2015-12-28 13:48 UTC (permalink / raw) To: QCA ath9k Development Cc: Kalle Valo, linux-wireless, ath9k-devel, netdev, linux-kernel ((thermometer < 0) ? 0 : (thermometer == X)) and (thermometer == X) are equal for X >= 0. Signed-off-by: Ivan Safonov <insafonov@gmail.com> --- drivers/net/wireless/ath/ath9k/ar9003_eeprom.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c index 8b4561e..35e57f7 100644 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c @@ -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); } -- 2.4.10 ^ permalink raw reply related [flat|nested] 5+ messages in thread
[parent not found: <20151228134852.GA10572-99FyVxquhxHwodmfrJTGkIdd74u8MsAO@public.gmane.org>]
* Re: [PATCH] /drivers/net/wireless/ath/ath9k remove unnecessary ?: operator [not found] ` <20151228134852.GA10572-99FyVxquhxHwodmfrJTGkIdd74u8MsAO@public.gmane.org> @ 2015-12-28 17:56 ` Joe Perches 2015-12-28 18:38 ` Ivan Safonov 0 siblings, 1 reply; 5+ messages in thread From: Joe Perches @ 2015-12-28 17:56 UTC (permalink / raw) To: Ivan Safonov, QCA ath9k Development Cc: Kalle Valo, linux-wireless-u79uwXL29TY76Z2rM5mHXA, ath9k-devel-xDcbHBWguxHbcTqmT+pZeQ, netdev-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA On Mon, 2015-12-28 at 20:48 +0700, Ivan Safonov wrote: > ((thermometer < 0) ? 0 : (thermometer == X)) and (thermometer == X) are equal for X >= 0. X is not guaranteed to be >= 0 here > Signed-off-by: Ivan Safonov <insafonov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > --- > drivers/net/wireless/ath/ath9k/ar9003_eeprom.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c [] > @@ -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. > 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); > } -- To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] /drivers/net/wireless/ath/ath9k remove unnecessary ?: operator 2015-12-28 17:56 ` Joe Perches @ 2015-12-28 18:38 ` Ivan Safonov 2015-12-29 0:31 ` Joe Perches 0 siblings, 1 reply; 5+ messages in thread From: Ivan Safonov @ 2015-12-28 18:38 UTC (permalink / raw) To: Joe Perches, QCA ath9k Development Cc: Kalle Valo, linux-wireless, ath9k-devel, netdev, linux-kernel On 12/29/2015 12:56 AM, Joe Perches wrote: > On Mon, 2015-12-28 at 20:48 +0700, Ivan Safonov wrote: >> ((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}. >> @@ -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). ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] /drivers/net/wireless/ath/ath9k remove unnecessary ?: operator 2015-12-28 18:38 ` Ivan Safonov @ 2015-12-29 0:31 ` Joe Perches 2015-12-29 4:11 ` Ivan Safonov 0 siblings, 1 reply; 5+ messages in thread From: Joe Perches @ 2015-12-29 0:31 UTC (permalink / raw) To: Ivan Safonov, QCA ath9k Development Cc: Kalle Valo, linux-wireless, ath9k-devel, netdev, linux-kernel On Tue, 2015-12-29 at 01:38 +0700, Ivan Safonov wrote: > On 12/29/2015 12:56 AM, Joe Perches wrote: > > On Mon, 2015-12-28 at 20:48 +0700, Ivan Safonov wrote: > > > ((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; } ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] /drivers/net/wireless/ath/ath9k remove unnecessary ?: operator 2015-12-29 0:31 ` Joe Perches @ 2015-12-29 4:11 ` Ivan Safonov 0 siblings, 0 replies; 5+ messages in thread From: Ivan Safonov @ 2015-12-29 4:11 UTC (permalink / raw) To: Joe Perches, QCA ath9k Development Cc: Kalle Valo, linux-wireless, ath9k-devel, netdev, linux-kernel On 12/29/2015 07:31 AM, Joe Perches wrote: > On Tue, 2015-12-29 at 01:38 +0700, Ivan Safonov wrote: >> On 12/29/2015 12:56 AM, Joe Perches wrote: >>> On Mon, 2015-12-28 at 20:48 +0700, Ivan Safonov wrote: >>>> ((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; > } 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. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-12-29 4:11 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-12-28 13:48 [PATCH] /drivers/net/wireless/ath/ath9k remove unnecessary ?: operator Ivan Safonov [not found] ` <20151228134852.GA10572-99FyVxquhxHwodmfrJTGkIdd74u8MsAO@public.gmane.org> 2015-12-28 17:56 ` Joe Perches 2015-12-28 18:38 ` Ivan Safonov 2015-12-29 0:31 ` Joe Perches 2015-12-29 4:11 ` Ivan Safonov
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).