diff options
author | Anshul Jain <anshulj@nvidia.com> | 2013-10-17 12:53:42 -0700 |
---|---|---|
committer | Mandar Padmawar <mpadmawar@nvidia.com> | 2013-10-17 23:38:10 -0700 |
commit | 1b75fee284a42f1d48b570aaed51261cff0fbcd3 (patch) | |
tree | 6f369570ee5d802aaa2fa6d5a963801b1f6d2cd8 /drivers | |
parent | 5eec7cd755f9c8dbdc826d63f10b30cad237eb5d (diff) |
misc: nct1008: Temperature bound check
This change does bound checking of temperature reads from NCT
device, this is done to return error when NCT is not ready and
TF tries to read temperture.
Bug 1388303
Change-Id: I642ecb46feb39469c0b3b33ea513604c7ff4a893
Signed-off-by: Anshul Jain <anshulj@nvidia.com>
Reviewed-on: http://git-master/r/300670
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
GVS: Gerrit_Virtual_Submit
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/misc/nct1008.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/drivers/misc/nct1008.c b/drivers/misc/nct1008.c index 8bebf2f7c4d0..42ed0f6103ae 100644 --- a/drivers/misc/nct1008.c +++ b/drivers/misc/nct1008.c @@ -81,6 +81,9 @@ #define POWER_ON_DELAY 20 /*ms*/ +#define NCT1008_TJ_MAX 150000 /*mC*/ +#define NCT1008_TJ_MIN -55000 /*mC*/ + struct nct1008_data { struct workqueue_struct *workqueue; struct work_struct work; @@ -532,28 +535,37 @@ static int nct1008_ext_get_temp(struct thermal_zone_device *thz, u8 value; mutex_lock(&data->suspend_mutex); + /* Read External Temp */ value = nct1008_read_reg(client, EXT_TEMP_RD_LO); if (value < 0) goto read_error; - temp_ext_lo = (value >> 6); + temp_ext_lo = (value >> 6); value = nct1008_read_reg(client, EXT_TEMP_RD_HI); + if (value < 0) goto read_error; - temp_ext_hi = value_to_temperature(pdata->ext_range, value); + temp_ext_hi = value_to_temperature(pdata->ext_range, value); temp_ext_milli = CELSIUS_TO_MILLICELSIUS(temp_ext_hi) + - temp_ext_lo * 250; + temp_ext_lo * 250; + *temp = temp_ext_milli; - data->etemp = temp_ext_milli; + + if (temp_ext_milli > NCT1008_TJ_MAX || + temp_ext_milli < NCT1008_TJ_MIN) { + dev_err(&data->client->dev, + "wrong temp read: %ld", temp_ext_milli); + goto read_error; + } else + data->etemp = temp_ext_milli; mutex_unlock(&data->suspend_mutex); return 0; read_error: mutex_unlock(&data->suspend_mutex); - *temp = 0; return -1; } |