lkml.org 
[lkml]   [2022]   [Aug]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 11/16] hwmon: (mr75203) add protection for negative voltage value
Date
This change makes sure the returned voltage vlaue is 0 or positive.

Signed-off-by: Eliav Farber <farbere@amazon.com>
---
drivers/hwmon/mr75203.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c
index 417b135c1b3f..8d8883301ff5 100644
--- a/drivers/hwmon/mr75203.c
+++ b/drivers/hwmon/mr75203.c
@@ -216,6 +216,13 @@ static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val)
return ret;

n &= SAMPLE_DATA_MSK;
+
+ /* Voltage can't be negative */
+ if (PVT_N_CONST * n < PVT_R_CONST) {
+ *val = 0;
+ return 0;
+ }
+
/* Convert the N bitstream count into voltage */
*val = pvt->vd[channel].pre_scaler;
*val *= (PVT_N_CONST * n - PVT_R_CONST);
--
2.37.1
\
 
 \ /
  Last update: 2022-08-16 11:42    [W:0.126 / U:0.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site