net: phy: aquantia: clamp temperature value in aqr_hwmon_set
Subsystems (3)
PATCH 1/1 net: phy: aquantia: clamp temperature value in aqr_hwmon_set
React like otherdrivers do when an out-of-range value is passed from hwmon core.
---
I implemented this patch based on observing how other drivers are reacting, and after experiencing the hwmon core passing -INT MAX. Based on a cursory look at the hwmon code, I don't believe this to be a bug. If this is instead the case, I hope I will be corrected and this patch rejected.
--- drivers/net/phy/aquantia_hwmon.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/phy/aquantia_hwmon.c +1 -2
@@ -70,8 +70,7 @@ static int aqr_hwmon_set(struct phy_device *phydev, int reg, long value) {int temp; -if (value >=128000 || value <-128000 ) -return -ERANGE ; +clamp_val (value,-128000 ,128000 ); temp = value *256 /1000 ;
Signature · 1 line
2.39.2
Guenter Roeck
maintainerQuoted 3 lines · Enrico Mioso
React like otherdrivers do when an out-of-range value is passed from hwmon core.
This is not an appropriate patch description.
Quoted 6 lines
Signed-off-by Enrico Mioso <[email protected]>CC Andrew Lunn <[email protected]>CC Russell King <[email protected]>---
I implemented this patch based on observing how other drivers are reacting, and after experiencing the hwmon core passing -INT MAX. Based on a
I don't understand "after experiencing the hwmon core passing -INT MAX".
Quoted 2 lines
cursory look at the hwmon code, I don't believe this to be a bug. If this is instead the case, I hope I will be corrected and this patch rejected.
The bug, if anything, in the current code is that it should return -EINVAL. -ERANGE is "Math result not representable" which doesn't make sense here.
Other than that, it is up to the driver author to decide if they want to return an error in this situation or if they want to clamp the range. We recommend to clamp because users won't normally know the valid range, but, again, it is up to the driver author to decide if they want to burden users with figuring out the valid range.
Guenter
Quoted 21 lines
--- drivers/net/phy/aquantia_hwmon.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/net/phy/aquantia_hwmon.c +1
-2@@ -70,8 +70,7 @@ static int aqr_hwmon_set(struct phy_device *phydev, int reg, long value) {int temp; -if (value >=128000 || value <-128000 ) -return -ERANGE ; +clamp_val (value,-128000 ,128000 ); temp = value *256 /1000 ;Signature · 1 line
2.39.2
Andrew Lunn
maintainerdrivers/net/phy/aquantia_hwmon.c static int aqr_hwmon_set(struct phy_device *phydev, int reg, long value) · line 73
Quoted 11 lines
drivers/net/phy/aquantia_hwmon.c +1
-2@@ -70,8 +70,7 @@ static int aqr_hwmon_set(struct phy_device *phydev, int reg, long value) {int temp; -if (value >=128000 || value <-128000 ) -return -ERANGE ; +clamp_val (value,-128000 ,128000 );
It could be argued that value < -128000 should return -EUNOBTAINABLE. I've had trouble getting DRAMS to work at -40C, even those listed as industrial. Setting an alarm for -128C is pointless.
+128C is also a bit questionable. The aQuantia PHYs do run hot, you often see a heat sink, and they are supposed to support up to 108C. So an alarm for 128C probably also does not work.
Anyway, as Guenter suggested, please change -ERANGE to -EINVAL.
Andrew
Guenter Roeck
maintainerQuoted 8 lines · Andrew Lunn
Quoted 8 lines
drivers/net/phy/aquantia_hwmon.c +0
-0@@ -70,8 +70,7 @@ static int aqr_hwmon_set(struct phy_device *phydev, int reg, long value) {int temp;
Quoted 6 lines
drivers/net/phy/aquantia_hwmon.c static int aqr_hwmon_set(struct phy_device *phydev, int reg, long value) · line 73
Quoted 3 lines
drivers/net/phy/aquantia_hwmon.c +1
-2-if (value >=128000 || value <-128000 ) -return -ERANGE ; +clamp_val (value,-128000 ,128000 );It could be argued that value < -128000 should return
-EUNOBTAINABLE. I've had trouble getting DRAMS to work at -40C, even
Hmm, I don't see that one anywhere.
Quoted 6 lines
those listed as industrial. Setting an alarm for -128C is pointless.
+128C is also a bit questionable. The aQuantia PHYs do run hot, you often see a heat sink, and they are supposed to support up to 108C. So an alarm for 128C probably also does not work.
It has been an endless argument if limits should be clamped to the limits supported by the chip registers or to the limits supported by the chip according to its datasheet. I personally see that as the responsibility of the person actually configuring the limits, not the driver. After all, there could be chip variants supporting different limits, and who knows what chip variants are going to be available in the future. Anyway, as I said, this has been an endless argument, and it is another detail that I usually let driver developers decide because they often feel passionate about it.
Guenter
Quoted 3 lines
Anyway, as Guenter suggested, please change
-ERANGEto-EINVAL.Andrew
Quoted 43 lines · Guenter Roeck
Date: Sat, 18 Feb 2023 15:42:34
From: Guenter Roeck <[email protected]>
To: Andrew Lunn <[email protected]>
Cc: Enrico Mioso <[email protected]>, [email protected],
Russell King <[email protected]>
Subject: Re: [PATCH] net: phy: aquantia: clamp temperature value in
aqr_hwmon_setQuoted 8 lines · Andrew Lunn
Quoted 8 lines
drivers/net/phy/aquantia_hwmon.c +0
-0@@ -70,8 +70,7 @@ static int aqr_hwmon_set(struct phy_device *phydev, int reg, long value) {int temp;Quoted 6 lines
drivers/net/phy/aquantia_hwmon.c static int aqr_hwmon_set(struct phy_device *phydev, int reg, long value) · line 73
Quoted 3 lines
drivers/net/phy/aquantia_hwmon.c +1
-2-if (value >=128000 || value <-128000 ) -return -ERANGE ; +clamp_val (value,-128000 ,128000 );It could be argued that value < -128000 should return
-EUNOBTAINABLE. I've had trouble getting DRAMS to work at -40C, evenHmm, I don't see that one anywhere.
Quoted 6 lines
those listed as industrial. Setting an alarm for -128C is pointless.
+128C is also a bit questionable. The aQuantia PHYs do run hot, you often see a heat sink, and they are supposed to support up to 108C. So an alarm for 128C probably also does not work.
It has been an endless argument if limits should be clamped to the limits supported by the chip registers or to the limits supported by the chip according to its datasheet. I personally see that as the responsibility of the person actually configuring the limits, not the driver. After all, there could be chip variants supporting different limits, and who knows what chip variants are going to be available in the future. Anyway, as I said, this has been an endless argument, and it is another detail that I usually let driver developers decide because they often feel passionate about it.
Quoted 6 lines
Guenter
Quoted 3 lines
Anyway, as Guenter suggested, please change
-ERANGEto-EINVAL.Andrew
Thanks a lot for your review and feedback.
I will send a new patch then, simply changing -ERANGE to -EINVAL.
Onanother side - if I want to set those limits to -10 °C and +90 °C, may you suggest me a DTS snippet? Thanks, Enrico
Enrico
Guenter Roeck
maintainerQuoted 4 lines · Enrico Mioso
Onanother side - if I want to set those limits to -10 °C and +90 °C, may you suggest me a DTS snippet? Thanks, Enrico
That would hae to be supported by the driver.
Guenter