hwmon: (k10temp) Only apply temperature offset if result is positive

"Linux Kernel Mailing List" <[email protected]> Fri, 16 Feb 2018 17:08:31 +0000 (UTC)
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/aef17ca1271948ee57cc39b2493d31110cc42625
Commit:     aef17ca1271948ee57cc39b2493d31110cc42625
Parent:     7928b2cbe55b2a410a0f5c1f154610059c57b1b2
Refname:    refs/heads/master
Author:     Guenter Roeck <[email protected]>
AuthorDate: Wed Feb 7 17:49:39 2018 -0800
Committer:  Guenter Roeck <[email protected]>
CommitDate: Mon Feb 12 14:23:29 2018 -0800

    hwmon: (k10temp) Only apply temperature offset if result is positive
    
    A user reports a really bad temperature on Ryzen 1950X.
    
    k10temp-pci-00cb
    Adapter: PCI adapter
    temp1: +4294948.3°C (high = +70.0°C)
    
    This will happen if the temperature reported by the chip is lower than
    the offset temperature. This has been seen in the field if "Sense MI Skew"
    and/or "Sense MI Offset" BIOS parameters were set to unexpected values.
    Let's report a temperature of 0 degrees C in that case.
    
    Fixes: 1b50b776355f ("hwmon: (k10temp) Add support for temperature offsets")
    Signed-off-by: Guenter Roeck <[email protected]>
---
 drivers/hwmon/k10temp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c
index 06b4e1c78bd8..4c6594a4661d 100644
--- a/drivers/hwmon/k10temp.c
+++ b/drivers/hwmon/k10temp.c
@@ -129,7 +129,10 @@ static ssize_t temp1_input_show(struct device *dev,
 
 	data->read_tempreg(data->pdev, &regval);
 	temp = (regval >> 21) * 125;
-	temp -= data->temp_offset;
+	if (temp > data->temp_offset)
+		temp -= data->temp_offset;
+	else
+		temp = 0;
 
 	return sprintf(buf, "%u\n", temp);
 }
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html